Get connection status on Socket.io client

后端 未结 5 1789
被撕碎了的回忆
被撕碎了的回忆 2020-12-23 10:50

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         


        
5条回答
  •  春和景丽
    2020-12-23 11:43

    Track the state of the connection yourself. With a boolean. Set it to false at declaration. Use the various events (connect, disconnect, reconnect, etc.) to reassign the current boolean value. Note: Using undocumented API features (e.g., socket.connected), is not a good idea; the feature could get removed in a subsequent version without the removal being mentioned.

提交回复
热议问题