You can use the following built-in functions to find out the connection status and determine the animation status accordingly:
socket.on('disconnect', function(){}); // wait for reconnect, hold animation socket.on('reconnect', function(){}); // connection restored, restart animation socket.on('reconnecting', function( nextRetry ){}); //trying to reconnect, hold animation socket.on('reconnect_failed', function(){ message("Reconnect Failed"); });// end animation
nextRetry indicates the time before it attempts to connect, if this helps to update the user with the status.
In addition, when disconnecting from the server, you do not need to call socket.connect (). Updated status will be available from socket.on ('reconnect'). So just include the call in the animation.
This is only in case of calling socket.disconnect from the client, the connection will not be restored automatically, and therefore socket.connect () will need to be called again.
source share