How to check connection status of websocket?

In web application development, you’d face a moment that need to check websocket connection status.For example, you’d have a situation that your web backend needs to check if users are active in the browser. It’s as very simple as you just need to check websocket property WebSocket.readyState. It has 4 possible values; “CONNECTING”, “OPEN”, “CLOSING”, “CLOSE”. …