Documenting 'reason' parameter of disconnect event handler
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)
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
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
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
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.
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).
I see, I didn't know about that parameter. Thanks. You're right, it should be a rason for that specific case.