expo connect backoff and reloading
This commit is contained in:
parent
787fd8ac90
commit
8f428f15a3
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user