From 5ccde0b27bd0eb7ae9b85a18c3a24da2d7443508 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Jakse?= Date: Mon, 13 Apr 2020 11:36:22 +0200 Subject: [PATCH] Block WebSockets if we see that they don't work --- trivabble.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/trivabble.js b/trivabble.js index 1262ac1..d5a644f 100644 --- a/trivabble.js +++ b/trivabble.js @@ -31,6 +31,7 @@ const POLLING_DELAY = 2000; const ENABLE_WEBSOCKETS = true; const ENABLE_EVENT_SOURCE = true; + const MAX_WEBSOCKET_ERRORS = 2; const _ = (window.libD && libD.l10n) ? libD.l10n() : function (s) {return s;}; @@ -837,19 +838,31 @@ } let blacklistWebsockets = false; + let webSocketErrors = 0; function bindConnectionEvents(connection) { connection.onopen = connectionReady; connection.onmessage = function (e) { + if (connection === webSocket) { + webSocketErrors = 0; + } + connectionReady(); parseAndHandleReceivedData(e.data); }; connection.onerror = function (e) { console.error("Connection error:", e); + if (connection === eventSource) { retryPolling(); + } else { + webSocketErrors++; + + if (webSocketErrors > MAX_WEBSOCKET_ERRORS) { + blacklistWebsockets = true; + } } }; -- 2.30.2