From b8018d4b6d09d06c6909430271d395aac127f8e2 Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Mon, 1 May 2017 15:32:40 +0100 Subject: [PATCH] Reconnect on 1000 if client didn't close --- src/client/websocket/WebSocketConnection.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/client/websocket/WebSocketConnection.js b/src/client/websocket/WebSocketConnection.js index 9b1c10d44..b4705caf4 100644 --- a/src/client/websocket/WebSocketConnection.js +++ b/src/client/websocket/WebSocketConnection.js @@ -369,13 +369,13 @@ class WebSocketConnection extends EventEmitter { */ onClose(event) { this.debug(`${this.expectingClose ? 'Server' : 'Client'} closed WebSocket connection: ${event.code}`); - this.expectingClose = false; this.closeSequence = this.sequence; // Reset the state before trying to fix anything this.emit('close', event); this.heartbeat(-1); // Should we reconnect? - if (Constants.WSCodes[event.code]) { + if (event.code === 1000 ? this.expectingClose : Constants.WSCodes[event.code]) { + this.expectingClose = false; /** * Emitted when the client's WebSocket disconnects and will no longer attempt to reconnect. * @event Client#disconnect @@ -386,6 +386,7 @@ class WebSocketConnection extends EventEmitter { this.destroy(); return; } + this.expectingClose = false; this.reconnect(); }