Some people already have asked this questions in some other places, Im just not sure if it exists here. Anyways, Im using Primus.io
with engine.io
as it's transformer. Im wondering if it's possible to have shared websocket connection on the browser(client). Like if I connected one client and connect another one on the other tab. Ideally they should get same connection that if I send something through the socket both tabs should be able to get the message.
Other's have mentioned about using the localStorage
as a way to share/communicate the same data across different tabs, But I just don't find it neat.
Your help is greatly appreciated.
Best,
Each tab will have a separate connection to the server and has a unique socket id.
If you want to emit a message to every socket for a user id or session id you need to have something to map a user or session to its multiple socket connections.
In Socket.IO, they have a concept of a "room".
On
connection
you can add the socket to a room. This example uses a passport.js authed username for the grouping.Then you can send a message to all sockets for that room.
Socket.IO cleans up the room on
disconnect
for you.https://github.com/cayasso/engine.io-rooms is an implementation of rooms for engine.io that might be useful.
In simple terms