I\'m trying to implement a WebSocket with a fallback to polling. If the WebSocket connection succeeds, readyState
becomes 1, but if it fails, readyState>
In my use case, I wanted to show an error on screen if the connection fails.
let $connectionError = document.getElementById("connection-error");
setTimeout( () => {
if (ws.readyState !== 1) {
$connectionError.classList.add( "show" );
}
}, 100 ); // ms
Note that in Safari (9.1.2) no error
event gets fired - otherwise I would have placed this in the error handler.