socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Documenting 'reason' parameter of disconnect event handler

Open mohamedhafez opened this issue 12 years ago • 6 comments

I've read that the 'disconnect' handler can take a reason argument, as in socket.on('disconnect', function(reason) {}). Could this be documented in the wiki, along with the possible values for reason? (A specific reason for the user leaving the page and the onbeforeunload handler being called would be super helpful)

mohamedhafez avatar Feb 23 '14 02:02 mohamedhafez

When a user leave the page the reasen will be 'close timeout'. That's how I'm m,anaging that case. I hope this help you.

+1 for reason documentation in the wiki

nicoburghi avatar Feb 23 '14 02:02 nicoburghi

Sorry, when a user leave a page the reason will be 'close timeout' after some minutes (2 minutes by default). You can set this time in the socket.io configuration

nicoburghi avatar Feb 23 '14 02:02 nicoburghi

wait, is that because the connection ends up timing out, or because the onbeforeunload handler in socket.io-client fires a disconnect event and we get immediately disconnected? If there isn't already, it would be really helpful to have that have a different reason than just a normal timeout

mohamedhafez avatar Feb 23 '14 02:02 mohamedhafez

As I understand is because the connection ends up timing out. There is no even fired in the beforeunload handler. I 've tried to fire a custom even in the beforeunload to t immediately disconnected, but did not work. I think you cannot do much things in the beforeunload hanlder.

nicoburghi avatar Feb 23 '14 03:02 nicoburghi

If you set the 'sync disconnect on unload' option on the client to true it will send a synchronous xhr disconnect request in onbeforeunload. (I've been doing a duplicate one just in my own code so I can tell when this happens and it works just fine, it would be nice if I could use the reason to not have to do a 2nd sync xhr request though).

mohamedhafez avatar Feb 23 '14 03:02 mohamedhafez

I see, I didn't know about that parameter. Thanks. You're right, it should be a rason for that specific case.

nicoburghi avatar Feb 24 '14 12:02 nicoburghi