-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shared Websocket connections over multiple tabs #628
Comments
Can you describe your proposed solution? I'm very interested in making this happen. |
Oh, if I'ld have one, that would already be great. Sadly, it seems to be quite difficult (especially when regarding IE). I hoped / thought this was already solved. As far as my researches / tests went, there are 3 Solutions:
As far as I can tell, simply re-using the already established websocket connections over different Tab's doesnt seem to be possible - so it always has to go over a master connection in the first tab. Sorry, I had the impression that this was already solved somehow by that post 2 years ago, that's why I was asking ;) I wish I'ld already have found a solution, but it really seems quite difficult. |
Bump ! |
Also when a "host" instance has its window closed, other instances must receive a signal to decide which one is going to serve as master. |
For shared web workers, i came across https://github.com/gonzalo123/wsww |
The two ideas combined could be great: use a shared web worker when available, fallback to sharing first window connection if postMessage is available between windows - that's everyone but IE<=9. |
Hey checkout this sweet Cross-tab message bus for browsers ! |
I'm working on socket.io inside a shared webworker while keeping the same API. https://github.com/IguMail/socketio-shared-webworker Feedback would be greatly appreciated. |
For anyone still having this issue. here is how i fixed it.
then on the server side you can create an empty array to a key and an array of values. the username of the user will be used as a key and the corresponding array of socket as the value. in my own case like i said i used a token
then you can perform a simple logic to check if a user already exists in an array, if it does, push the new socket to the array of the user
if it dosent, just create a new key and add the socket as the key.(make sure its an array because a user can always refresh or open a new tab with the same account and you dont want the chat message to deliver in one tab and not deliver in another)
then to emit a message you simply loop through the array and emit the message accordingly. this way each tab gets the message socket.on('chat', (data) => {
you can add a disconnect logic to remove the socket from the users array too to save memory, so only currently open tabs acre active and closed tabs are removed. i hope it solved your problem |
Old browsers won't get shared connections, so what ? |
I'm trying to find a solution to avoid multiple connections over multiple open tabs. Instead, I'ld like to share the connection between them (especially since users tend to have up to 30 tabs open sometimes). Now, I'm apparently not the only one with the Issue, and after searching around for informations for a while, I found this 2 year old entry: https://groups.google.com/forum/#!topic/socket_io/FbHU7HvxK6U
Here, Guillermo Rauch writes:
24/06/2011
I have a solution outlined which will probably land in 0.9.
Now, I'm wondering: is it implemented? Does it work? I couldnt find any informations about it, and I'ld really like to solve the problem over socket.io instead of creating a strange localStorage hack to share a connection.
Thanks in advance, I hope there are some good news - would save me a lot of work ;)
The text was updated successfully, but these errors were encountered: