diff --git a/app/soapbox/stream.js b/app/soapbox/stream.js index 15764f4ce..c6d648d7d 100644 --- a/app/soapbox/stream.js +++ b/app/soapbox/stream.js @@ -26,37 +26,45 @@ export function connectStream(path, pollingRefresh = null, callbacks = () => ({ } }; - const subscription = getStream(streamingAPIBaseURL, accessToken, path, { - connected() { - if (pollingRefresh) { - clearPolling(); - } + let subscription; - onConnect(); - }, + // If the WebSocket fails to be created, don't crash the whole page, + // just proceed without a subscription. + try { + subscription = getStream(streamingAPIBaseURL, accessToken, path, { + connected() { + if (pollingRefresh) { + clearPolling(); + } - disconnected() { - if (pollingRefresh) { - polling = setTimeout(() => setupPolling(), randomIntUpTo(40000)); - } + onConnect(); + }, - onDisconnect(); - }, + disconnected() { + if (pollingRefresh) { + polling = setTimeout(() => setupPolling(), randomIntUpTo(40000)); + } - received(data) { - onReceive(data); - }, + onDisconnect(); + }, - reconnected() { - if (pollingRefresh) { - clearPolling(); - pollingRefresh(dispatch); - } + received(data) { + onReceive(data); + }, - onConnect(); - }, + reconnected() { + if (pollingRefresh) { + clearPolling(); + pollingRefresh(dispatch); + } - }); + onConnect(); + }, + + }); + } catch (e) { + console.error(e); + } const disconnect = () => { if (subscription) {