mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-25 19:08:04 +01:00
Move/refactor keepalive logic and add disconnect timer
We now disconnect ourselves if we don't get the server's response to a
keepalive request within 30s. This way we will eventually disconnect if
the network goes away but the socket is not closed.*
* See code.google.com/p/chromium/issues/detail?id=197841 and
https://stackoverflow.com/questions/11755605/chrome-websocket-connection-not-closed-when-browser-closed
We will then try to reconnect once a minute (See 8a10c96);
Keepalives belong at this level anyway, since the format is defined by
both the websocket resource protocol and our specific server url
structure.
// FREEBIE
This commit is contained in:
@@ -44,9 +44,26 @@
|
||||
}
|
||||
}
|
||||
|
||||
new WebSocketResource(this.socket, this.handleRequest.bind(this));
|
||||
this.wsr = new WebSocketResource(this.socket, this.handleRequest.bind(this));
|
||||
this.resetKeepAliveTimer();
|
||||
|
||||
},
|
||||
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();
|
||||
// TODO: handle different types of requests. for now we only expect
|
||||
// PUT /messages <encrypted IncomingPushMessageSignal>
|
||||
textsecure.crypto.decryptWebsocketMessage(request.body).then(function(plaintext) {
|
||||
|
||||
Reference in New Issue
Block a user