From 8b345c5a25a24712e0d40e722b8207bb319ea099 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Jakse?= Date: Tue, 14 Apr 2020 20:37:45 +0200 Subject: [PATCH] Ensure we close the active connection when opening another in the client --- trivabble.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 + -- 2.30.2