Streaming: fail gracefully when WebSocket construction fails (mainly for Bromite browser)

merge-requests/808/head
Alex Gleason 2021-10-20 16:36:38 -05:00
rodzic 0b94774fbe
commit 97cc7eb804
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 32 dodań i 24 usunięć

Wyświetl plik

@ -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) {