I’m using Node.JS and Socket.IO to create a chat, I use XHR polling with a duration of 10 to host it on Heroku.
When I leave the page with my client, I’d like to calll the disconnect method automatically on the server which removes it from other clients. It’s in fact done but… 2 minutes after the client has really left the page, which is quite awkward.
Is there a way to call the disconnect method as soon as the client doesn’t reply ? Or at least being a little faster to know when the client is not there anymore ?
I’ve tried to close the socket client-side on page exit with jQuery but it doesn’t work. The problem is that using socket.disconnect() is asynchronous and non-blocking and the user leaves before the request is completed…
You can play with
heartbeat timeout,heartbeat intervalandclose timeoutvalues ofsocket.ioconfiguration.Search for
heartbeatandtimeoutin this page: https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO