Keepalive provisioning socket

Fixes #315

// FREEBIE
This commit is contained in:
lilia 2015-07-27 17:59:48 -07:00
parent 0d0bdbf998
commit d9d4e281cc
5 changed files with 92 additions and 34 deletions

View file

@ -45,25 +45,11 @@
}
this.wsr = new WebSocketResource(this.socket, this.handleRequest.bind(this));
this.resetKeepAliveTimer();
this.keepalive = new KeepAlive(this.wsr, this.socket);
},
resetKeepAliveTimer: function() {
clearTimeout(this.keepAliveTimer);
clearTimeout(this.disconnectTimer);
this.keepAliveTimer = setTimeout(function() {
if (this.getStatus() === WebSocket.OPEN) {
this.wsr.sendRequest({
verb: 'GET',
path: '/v1/keepalive',
success: this.resetKeepAliveTimer.bind(this)
});
}
this.disconnectTimer = setTimeout(this.socket.close, 30000);
}.bind(this), 55000);
},
handleRequest: function(request) {
this.resetKeepAliveTimer();
this.keepalive.reset();
// TODO: handle different types of requests. for now we only expect
// PUT /messages <encrypted IncomingPushMessageSignal>
textsecure.crypto.decryptWebsocketMessage(request.body).then(function(plaintext) {