Streaming: fail gracefully when WebSocket construction fails (mainly for Bromite browser)
This commit is contained in:
parent
0b94774fbe
commit
97cc7eb804
1 changed files with 32 additions and 24 deletions
|
@ -26,37 +26,45 @@ export function connectStream(path, pollingRefresh = null, callbacks = () => ({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const subscription = getStream(streamingAPIBaseURL, accessToken, path, {
|
let subscription;
|
||||||
connected() {
|
|
||||||
if (pollingRefresh) {
|
|
||||||
clearPolling();
|
|
||||||
}
|
|
||||||
|
|
||||||
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() {
|
onConnect();
|
||||||
if (pollingRefresh) {
|
},
|
||||||
polling = setTimeout(() => setupPolling(), randomIntUpTo(40000));
|
|
||||||
}
|
|
||||||
|
|
||||||
onDisconnect();
|
disconnected() {
|
||||||
},
|
if (pollingRefresh) {
|
||||||
|
polling = setTimeout(() => setupPolling(), randomIntUpTo(40000));
|
||||||
|
}
|
||||||
|
|
||||||
received(data) {
|
onDisconnect();
|
||||||
onReceive(data);
|
},
|
||||||
},
|
|
||||||
|
|
||||||
reconnected() {
|
received(data) {
|
||||||
if (pollingRefresh) {
|
onReceive(data);
|
||||||
clearPolling();
|
},
|
||||||
pollingRefresh(dispatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
onConnect();
|
reconnected() {
|
||||||
},
|
if (pollingRefresh) {
|
||||||
|
clearPolling();
|
||||||
|
pollingRefresh(dispatch);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
onConnect();
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
const disconnect = () => {
|
const disconnect = () => {
|
||||||
if (subscription) {
|
if (subscription) {
|
||||||
|
|
Loading…
Reference in a new issue