I\'m using Socket.io, and I\'d like to know the status of connection to the server from the client-side.
Something like this:
socket.status // return
You can check the socket.connected property:
var socket = io.connect();
console.log('check 1', socket.connected);
socket.on('connect', function() {
console.log('check 2', socket.connected);
});
It's updated dynamically, if the connection is lost it'll be set to false until the client picks up the connection again. So easy to check for with setInterval or something like that.
Another solution would be to catch disconnect events and track the status yourself.