Fix WebSocketClientConnector lifecycle events

Fix drop being repeatedly emitted while reconnecting and close not being
emitted on connection timeout.
This commit is contained in:
Hornwitser committed 2020-05-09 16:28:07 +02:00
1 parent c87538ca58
commit 04ee3d3f96
1 file changed
+3 -6
+3 -6
View File
@@ -260,11 +260,8 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
this._lastReceivedSeq = null; this._lastReceivedSeq = null;
this._sessionToken = null; this._sessionToken = null;
this._sendBuffer.length = 0; this._sendBuffer.length = 0;
if (this._connected) {
this._connected = false; this._connected = false;
this.emit("close"); this.emit("close");
}
this.emit("invalidate");
return; return;
} }
@@ -290,17 +287,17 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
this._sessionToken = null; this._sessionToken = null;
this._sendBuffer.length = 0; this._sendBuffer.length = 0;
this._state = "new"; this._state = "new";
if (this._connected) {
this._connected = false; this._connected = false;
this.emit("close"); this.emit("close");
}
} else { } else {
this._state = "handshake"; this._state = "handshake";
this.reconnect(); this.reconnect();
if (this._connected) {
this._connected = false;
this.emit("drop"); this.emit("drop");
} }
}
this.stopHeartbeat(); this.stopHeartbeat();
}); });