From 9be5efc5714ab4dcc07ca6281eef2ee2ce28e97f Mon Sep 17 00:00:00 2001 From: lilia Date: Fri, 23 Oct 2015 14:43:15 -0700 Subject: [PATCH] Simplify keepalive resets Websocket resources should have their keepalive timers reset whenever a message comes in. This is a nicety that slightly reduces the amount of traffic we send when actively messaging. Previously this was handled by MessageReceiver, but it's a bit cleaner to just have the WebsocketResource add an extra 'message' event handler. // FREEBIE --- js/libtextsecure.js | 6 +++--- libtextsecure/message_receiver.js | 1 - libtextsecure/websocket-resources.js | 5 +++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 632f70f50f9..749d2e80377 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -38461,8 +38461,9 @@ axolotlInternal.RecipientRecord = function() { path : opts.keepalive.path, disconnect : opts.keepalive.disconnect }); - this.resetKeepAliveTimer = keepalive.reset.bind(keepalive); - socket.addEventListener('connect', this.resetKeepAliveTimer); + var resetKeepAliveTimer = keepalive.reset.bind(keepalive); + socket.addEventListener('connect', resetKeepAliveTimer); + socket.addEventListener('message', resetKeepAliveTimer); socket.addEventListener('close', keepalive.stop.bind(keepalive)); } @@ -39261,7 +39262,6 @@ MessageReceiver.prototype = { }); }, handleRequest: function(request) { - this.wsr.resetKeepAliveTimer(); // TODO: handle different types of requests. for now we only expect // PUT /messages textsecure.crypto.decryptWebsocketMessage(request.body, this.signalingKey).then(function(plaintext) { diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 67bfdc04edf..9c505730cb4 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -53,7 +53,6 @@ MessageReceiver.prototype = { }); }, handleRequest: function(request) { - this.wsr.resetKeepAliveTimer(); // TODO: handle different types of requests. for now we only expect // PUT /messages textsecure.crypto.decryptWebsocketMessage(request.body, this.signalingKey).then(function(plaintext) { diff --git a/libtextsecure/websocket-resources.js b/libtextsecure/websocket-resources.js index 1fc269097ef..9b3cd653509 100644 --- a/libtextsecure/websocket-resources.js +++ b/libtextsecure/websocket-resources.js @@ -134,8 +134,9 @@ path : opts.keepalive.path, disconnect : opts.keepalive.disconnect }); - this.resetKeepAliveTimer = keepalive.reset.bind(keepalive); - socket.addEventListener('connect', this.resetKeepAliveTimer); + var resetKeepAliveTimer = keepalive.reset.bind(keepalive); + socket.addEventListener('connect', resetKeepAliveTimer); + socket.addEventListener('message', resetKeepAliveTimer); socket.addEventListener('close', keepalive.stop.bind(keepalive)); }