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
1 changed files with 15 additions and 3 deletions

View File

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