I'm using WebSockets to connect to a server that I don't have control over. This is a chat app so I am expecting when the user's internet gets cut off for any reason I would show a "reconnecting" alert and try reconnecting every 2 sec.
The issue is the .onclose event takes up to 1 min to fire up when you turn off your modem for example and there is no way for me to know if the user still has connection to the servers.
code example :
<script type="text/javascript"> var ws = new WebSocket("wss://echo.websocket.org"); ws.onerror = function () { console.log("error happened") } ws.onclose = function () { // websocket is closed. console.log("Connection is closed..."); }; </script>