}
}
+ function canConnect() {
+ return !pollingServer && !needsRestart && !connectionStopped && navigator.onLine !== false;
+ // DO NOT change navigator.onLine !== false by navigator.onLine === true
+ // This would block connection on a browser not supporting this property
+ }
+
function pollServerWithEventSource() {
- if (ENABLE_EVENT_SOURCE && window.EventSource) {
+ if (canConnect() && ENABLE_EVENT_SOURCE && window.EventSource) {
closeConnections();
+ pollingServer = true;
+
eventSource = new EventSource("/:trivabble/sse/" + JSON.stringify(cmdsWithContext()));
bindConnectionEvents(eventSource);
return;
}
function pollServerWithWebSocket() {
- if (ENABLE_WEBSOCKETS && !blacklistWebsockets && window.WebSocket) {
+ if (canConnect() && ENABLE_WEBSOCKETS && !blacklistWebsockets && window.WebSocket) {
closeConnections();
+ pollingServer = true;
+
webSocket = new WebSocket(
(window.location.protocol === "http:" ? "ws://" : "wss://") +
window.location.host +
}
function pollServerWithXHR() {
+ if (!canConnect()) {
+ return;
+ }
+
+ pollingServer = true;
+
let currentIndex = 0;
let expectedLength = 0;
}
function startConnection() {
- if (pollingServer || needsRestart || connectionStopped || navigator.onLine === false) {
- return;
- }
-
- pollingServer = true;
pollServerWithWebSocket();
}