From: Raphaƫl Jakse Date: Tue, 14 Apr 2020 18:37:45 +0000 (+0200) Subject: Ensure we close the active connection when opening another in the client X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=8b345c5a25a24712e0d40e722b8207bb319ea099;p=trivabble.git Ensure we close the active connection when opening another in the client --- diff --git a/trivabble.js b/trivabble.js index 3dc1dba..ff14bd9 100644 --- a/trivabble.js +++ b/trivabble.js @@ -813,7 +813,7 @@ } } - function stopConnection() { + function closeConnections() { if (eventSource) { eventSource.onerror = null; eventSource.close(); @@ -826,6 +826,10 @@ webSocket.close(); webSocket = null; } + } + + function stopConnection() { + closeConnections(); if (retryPollingTimeout) { clearTimeout(retryPollingTimeout); @@ -882,6 +886,7 @@ function pollServerWithEventSource() { if (ENABLE_EVENT_SOURCE && window.EventSource) { + closeConnections(); eventSource = new EventSource("/:trivabble/sse/" + JSON.stringify(cmdsWithContext())); bindConnectionEvents(eventSource); return; @@ -892,6 +897,7 @@ function pollServerWithWebSocket() { if (ENABLE_WEBSOCKETS && !blacklistWebsockets && window.WebSocket) { + closeConnections(); webSocket = new WebSocket( (window.location.protocol === "http:" ? "ws://" : "wss://") + window.location.host +