Add auto-disconnect config to keepalive constructor
Disconnects on no keepalive response by default. // FREEBIE
This commit is contained in:
parent
d9fe783488
commit
7d2b41db11
3 changed files with 30 additions and 10 deletions
|
@ -38629,8 +38629,13 @@ TextSecureWebSocket = function (url, opts) {
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function KeepAlive(websocketResource) {
|
function KeepAlive(websocketResource, opts) {
|
||||||
if (websocketResource instanceof WebSocketResource) {
|
if (websocketResource instanceof WebSocketResource) {
|
||||||
|
opts = opts || {};
|
||||||
|
this.disconnect = opts.disconnect;
|
||||||
|
if (this.disconnect === undefined) {
|
||||||
|
this.disconnect = true;
|
||||||
|
}
|
||||||
this.wsr = websocketResource;
|
this.wsr = websocketResource;
|
||||||
this.reset();
|
this.reset();
|
||||||
} else {
|
} else {
|
||||||
|
@ -38644,14 +38649,19 @@ KeepAlive.prototype = {
|
||||||
clearTimeout(this.keepAliveTimer);
|
clearTimeout(this.keepAliveTimer);
|
||||||
clearTimeout(this.disconnectTimer);
|
clearTimeout(this.disconnectTimer);
|
||||||
this.keepAliveTimer = setTimeout(function() {
|
this.keepAliveTimer = setTimeout(function() {
|
||||||
this.disconnectTimer = setTimeout(function() {
|
|
||||||
this.wsr.close(3001, 'No response to keepalive request');
|
|
||||||
}.bind(this), 5000);
|
|
||||||
this.wsr.sendRequest({
|
this.wsr.sendRequest({
|
||||||
verb: 'GET',
|
verb: 'GET',
|
||||||
path: '/v1/keepalive',
|
path: '/v1/keepalive',
|
||||||
success: this.reset.bind(this)
|
success: this.reset.bind(this)
|
||||||
});
|
});
|
||||||
|
if (this.disconnect) {
|
||||||
|
// automatically disconnect if server doesn't ack
|
||||||
|
this.disconnectTimer = setTimeout(function() {
|
||||||
|
this.wsr.close(3001, 'No response to keepalive request');
|
||||||
|
}.bind(this), 1000);
|
||||||
|
} else {
|
||||||
|
this.reset();
|
||||||
|
}
|
||||||
}.bind(this), 55000);
|
}.bind(this), 55000);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -39402,7 +39412,7 @@ TextSecureServer = function () {
|
||||||
console.log('Unknown websocket message', request.path);
|
console.log('Unknown websocket message', request.path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
new KeepAlive(wsr);
|
new KeepAlive(wsr, { disconnect: false });
|
||||||
});
|
});
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
return generateKeys(100, progressCallback);
|
return generateKeys(100, progressCallback);
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
console.log('Unknown websocket message', request.path);
|
console.log('Unknown websocket message', request.path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
new KeepAlive(wsr);
|
new KeepAlive(wsr, { disconnect: false });
|
||||||
});
|
});
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
return generateKeys(100, progressCallback);
|
return generateKeys(100, progressCallback);
|
||||||
|
|
|
@ -14,8 +14,13 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function KeepAlive(websocketResource) {
|
function KeepAlive(websocketResource, opts) {
|
||||||
if (websocketResource instanceof WebSocketResource) {
|
if (websocketResource instanceof WebSocketResource) {
|
||||||
|
opts = opts || {};
|
||||||
|
this.disconnect = opts.disconnect;
|
||||||
|
if (this.disconnect === undefined) {
|
||||||
|
this.disconnect = true;
|
||||||
|
}
|
||||||
this.wsr = websocketResource;
|
this.wsr = websocketResource;
|
||||||
this.reset();
|
this.reset();
|
||||||
} else {
|
} else {
|
||||||
|
@ -29,14 +34,19 @@ KeepAlive.prototype = {
|
||||||
clearTimeout(this.keepAliveTimer);
|
clearTimeout(this.keepAliveTimer);
|
||||||
clearTimeout(this.disconnectTimer);
|
clearTimeout(this.disconnectTimer);
|
||||||
this.keepAliveTimer = setTimeout(function() {
|
this.keepAliveTimer = setTimeout(function() {
|
||||||
this.disconnectTimer = setTimeout(function() {
|
|
||||||
this.wsr.close(3001, 'No response to keepalive request');
|
|
||||||
}.bind(this), 5000);
|
|
||||||
this.wsr.sendRequest({
|
this.wsr.sendRequest({
|
||||||
verb: 'GET',
|
verb: 'GET',
|
||||||
path: '/v1/keepalive',
|
path: '/v1/keepalive',
|
||||||
success: this.reset.bind(this)
|
success: this.reset.bind(this)
|
||||||
});
|
});
|
||||||
|
if (this.disconnect) {
|
||||||
|
// automatically disconnect if server doesn't ack
|
||||||
|
this.disconnectTimer = setTimeout(function() {
|
||||||
|
this.wsr.close(3001, 'No response to keepalive request');
|
||||||
|
}.bind(this), 1000);
|
||||||
|
} else {
|
||||||
|
this.reset();
|
||||||
|
}
|
||||||
}.bind(this), 55000);
|
}.bind(this), 55000);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue