expo connect backoff and reloading

This commit is contained in:
ntr 2019-11-06 19:05:28 +11:00
parent 787fd8ac90
commit 8f428f15a3

View File

@ -318,8 +318,11 @@ function createSocket(events) {
return handlers[msgType](params);
}
let attempts = 1;
// Connection opened
function onOpen() {
attempts = 0;
toast.info({
message: 'connected',
position: 'topRight',
@ -338,12 +341,21 @@ function createSocket(events) {
}
function onClose(event) {
attempts *= 2;
if (attempts > 10) {
toast.warning({
message: 'unable to connect, refreshing...',
position: 'topRight',
});
setTimeout(() => window.location.reload(true), 2000);
}
console.error('WebSocket closed', event);
toast.warning({
message: 'disconnected',
position: 'topRight',
});
return setTimeout(connect, 5000);
return setTimeout(connect, attempts * 1000);
}
function connect() {