I am using socket.io in my project. I turned on reconnect feature. I want to if user disconnects from server show an alert (Your internet connection loss. Trying reconnect). And if the user reconnects again I want to show one more alert (Don't worry, you are connected).
How can I do it?
To detect on the client you use
It's the exact same code as above for a node.js server too.
If you want for some reason to detect a user disconnecting and display it to the others, you will need to use the server one to detect it the person leaving and then emit back out a message to the others using something like:
Hope this helps
socket.io
has adisconnect
event, put this inside yourconnect
block:I handled this problem this way. I've made an emit sender on client which is calling heartbeat on server.
I found this code function to call: