I would like to connect to the server and then do some things as soon as the connection is open. But if the connection stops, I want to trap and not do this, and possibly cancel the pending connection.
function doStuff () {
var connection = new WebSocket('wss://someURL');
}
I was looking for some features like
connection.addEventListener('timeout',...);
since when setting up my WS server I don’t respond (simulate a server that is too slow), the Chrome Network Inspector constantly shows the connection as "Waiting". Due to the lack of this feature, my first pass:
function doStuff () {
var connection = new WebSocket('wss://someURL');
connection.addEventListener('open', onOpen, false);
var socketTimer = setTimeout(onNotResponding, 10000);
function onOpen () {
clearTimeout(socketTimer);
}
function onNotResponding () {
}
}
source
share