Implement exponential backoff for websocket

This commit is contained in:
Daniel Gröber 2018-08-01 13:49:07 +02:00
parent 62af36f332
commit 33e53cda3d

View file

@ -27,10 +27,22 @@ var its = (function() {
url.protocol = url.protocol == 'https:' ? 'wss' : 'ws'; url.protocol = url.protocol == 'https:' ? 'wss' : 'ws';
url += 'its-open-ws/'; url += 'its-open-ws/';
var reconnect_delay = 1000;
var reconnect_giveup = 1000000;
function connect() { function connect() {
console.log('isitopen: reconnecting'); if(reconnect_delay > reconnect_giveup)
var ws = new WebSocket(url); return;
register(ws);
setTimeout(function() {
console.log('isitopen: reconnecting');
var ws = new WebSocket(url);
register(ws);
}, reconnect_delay);
reconnect_delay *= 2;
} }
function refresh() { function refresh() {