ws.on('open', function open() {
console.log('client is opened');
ws.send(JSON.stringify({
uuid: uuid,
key: key,
lock: true
}));
});
can we do a check if ws is opened?
something like:
if(ws.isOpen){
ws.send('foo');
}
else{
ws.on('open', function open() {
console.log('client is opened');
ws.send('foo'));
});
}
You can check the readyState.
if (ws.readyState === WebSocket.OPEN) {
...
}
thanks!
What I did for now, I put this in the top of my code:
js
ws.once('open', function open() {
ws.isOpen = true;
});
:) but thanks, I will probably do it the more canonical way
Closing this, please comment or reopen if needed.
Most helpful comment
You can check the
readyState.