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); return handlers[msgType](params);
} }
let attempts = 1;
// Connection opened // Connection opened
function onOpen() { function onOpen() {
attempts = 0;
toast.info({ toast.info({
message: 'connected', message: 'connected',
position: 'topRight', position: 'topRight',
@ -338,12 +341,21 @@ function createSocket(events) {
} }
function onClose(event) { 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); console.error('WebSocket closed', event);
toast.warning({ toast.warning({
message: 'disconnected', message: 'disconnected',
position: 'topRight', position: 'topRight',
}); });
return setTimeout(connect, 5000); return setTimeout(connect, attempts * 1000);
} }
function connect() { function connect() {