socket.io-client
socket.io-client copied to clipboard
sync on unload doesn't work for XHR-Polling or JSONP
I can't get the disconnectSync to actually disconnect the client if they close their browser in chrome (haven't tried elsewhere yet). To reproduce:
- Start a socket server with only XHR polling or only JSONP polling transports and debug log on
- Open connection in chrome (You'll see the handshake and connection in the debug log
- Close the browser tab
- Nothing registers on the server side.
You can ask the client to notify the server about disconnect by turning on the flag sync disconnect on unload:
var socket = io.connect('http://localhost', {
'sync disconnect on unload': true
});
This solution has some shortcomings though, see this pull request for more details.
See also a related StackOverflow question & answer.
Is there a server-side solution for this issue? While the client option works on desktop browsers, I'd still prefer not to rely on the client to inform the server of a disconnect.