Implement exponential backoff for websocket
This commit is contained in:
parent
62af36f332
commit
33e53cda3d
1 changed files with 15 additions and 3 deletions
|
@ -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() {
|
||||||
|
|
Loading…
Reference in a new issue