Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
break;
case WebSocket.CLOSED:
// nothing to be done
break;
case WebSocket.CONNECTING:
// imitate missing abort API
this.socket.onopen = () => 0;
this.socket.onclose = () => 0;
this.socket.onerror = () => 0;
this.socket.onmessage = () => 0;
this.socket = undefined;
if (this.closeHandler) {
this.closeHandler({ wasClean: false, code: 4001 });
}
break;
case WebSocket.CLOSING:
// already closing. Let it proceed
break;
default:
throw new Error(`Unknown readyState: ${this.socket.readyState}`);
}
}
ws.onclose = () => {
if (ws && ws.readyState !== WebSocket.CLOSED && ws.readyState !== WebSocket.CLOSING) {
ws.close();
}
if (ws.reconcileTimer) {
clearInterval(ws.reconcileTimer);
ws.reconcileTimer = null;
}
if (this.ws === ws) {
this.ws = null;
if (Object.keys(this.messageIdToSubscription).length) {
this.initSocket();
}
}
};