From: Raphaƫl Jakse Date: Mon, 13 Apr 2020 09:36:22 +0000 (+0200) Subject: Block WebSockets if we see that they don't work X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=5ccde0b27bd0eb7ae9b85a18c3a24da2d7443508;p=trivabble.git Block WebSockets if we see that they don't work --- 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; + } } };