Re: Share connections over tabs

241 views
Skip to first unread message

Nicolas Chambrier

unread,
Nov 20, 2012, 4:26:40 PM11/20/12
to socket_io
You can't, there are different connections, different sockets.
What you can do is identify the client with a cookie (grab session ID for example) in the handshake, and then make the socket join a room dedicated to this client. If he opens X tabs, there will be X distinct sockets, all in the same room. Then you can synchronize their behavior using this room.


On 20 November 2012 16:09, Danny Bloemendaal <danny.bl...@gmail.com> wrote:
Hi there, 

Has anybody made a decent implementation with socket.io that allows you to share connections over tabs? I've looked at portal.js but I can't get it to work properly. Tips and code are greatly appreciated :)))

Cheers, 
Danny.



--
Nicolas Chambrier, aka naholyr

Blog : http://naholyr.fr
Formateur Clever Institut : http://clever-institut.com/formateur/nicolas-chambrier


Danny Bloemendaal

unread,
Nov 21, 2012, 3:23:16 AM11/21/12
to sock...@googlegroups.com
I don't think this is true. There are various implementations that use some kind of trick with iframes and local storage to do just that. But I haven't seen it with socket.io just yet. Hence my question. 

Take a look at portal for instance: https://github.com/flowersinthesand/portal

Nicolas Chambrier

unread,
Nov 21, 2012, 2:39:55 PM11/21/12
to socket_io
Their code does not respond to your issue. You want to share a websocket connection between two tabs, so that if you "socket.emit('lol')" from server both will receive this event, right?

As far as I understand their code, what they do here is syncing multiple connections (amongst multiple tabs) using local storage event. They do not *share* the connections, they *sync* them, giving the illusion it's shared.
You can achieve the exact same goal by simply emitting to rooms instead of single sockets, and putting all sockets of the same session in the same room.
Reply all
Reply to author
Forward
0 new messages