From 63361538d6be9ebffdb255b2140cb60fec21b2f9 Mon Sep 17 00:00:00 2001 From: David-dp- Date: Wed, 3 Jun 2020 13:26:11 -0700 Subject: [PATCH] Fix issue 6 Issue 6 (an error occurs in the constructor of both the source and minified versions) always occurred for me in current Chrome/Win10 before this change, and doesn't after this change. This change is the one suggested by others in issue 6. --- reconnecting-websocket.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/reconnecting-websocket.js b/reconnecting-websocket.js index 0cd4332..2ec130a 100644 --- a/reconnecting-websocket.js +++ b/reconnecting-websocket.js @@ -228,7 +228,9 @@ console.debug('ReconnectingWebSocket', 'connection-timeout', self.url); } timedOut = true; - localWs.close(); + if (!!localWs && localWs.readyState !== WebSocket.CLOSED) { + localWs.close(); + } timedOut = false; }, self.timeoutInterval); @@ -330,7 +332,7 @@ * For example, if the app suspects bad data / missed heart beats, it can try to refresh. */ this.refresh = function() { - if (ws) { + if (!!ws && ws.readyState !== WebSocket.CLOSED) { ws.close(); } };