if (canConnect() && getSetting("ENABLE_EVENT_SOURCE") && window.EventSource) {
closeConnections();
pollingServer = true;
-
- eventSource = new EventSource(getSetting("API_ENTRY_POINT") + "/sse/" + JSON.stringify(cmdsWithContext()));
- bindConnectionEvents(eventSource);
- return;
+ try {
+ eventSource = new EventSource(getSetting("API_ENTRY_POINT") + "/sse/" + JSON.stringify(cmdsWithContext()));
+ bindConnectionEvents(eventSource);
+ return;
+ } catch (e) {
+ pollingServer = false;
+ // failed, will fallback to XHR
+ }
}
pollServerWithXHR();
if (canConnect() && getSetting("ENABLE_WEBSOCKETS") && !blacklistWebsockets && window.WebSocket) {
closeConnections();
pollingServer = true;
-
- webSocket = new WebSocket(
- (window.location.protocol === "http:" ? "ws://" : "wss://") +
- window.location.host +
- getSetting("API_ENTRY_POINT") + "/ws/" +
- JSON.stringify(cmdsWithContext())
- );
-
- bindConnectionEvents(webSocket);
- return;
+ try {
+ webSocket = new WebSocket(
+ (window.location.protocol === "http:" ? "ws://" : "wss://") +
+ window.location.host +
+ getSetting("API_ENTRY_POINT") + "/ws/" +
+ JSON.stringify(cmdsWithContext())
+ );
+ bindConnectionEvents(webSocket);
+ return;
+ } catch (e) {
+ // failed, will fall back to event source
+ pollingServer = false;
+ }
}
pollServerWithEventSource();