From 0cbad730ce453b36a14b5622cd918f48ccce0f5d Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 11 Mar 2015 13:30:14 -0700 Subject: [PATCH] Don't send keepalive if socket has closed Also shorten the timeout to see if it improves websocket connection reliability. --- js/libtextsecure.js | 16 +++++++++------- libtextsecure/websocket.js | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index dc27ce30e..b02aa93fd 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -15919,15 +15919,17 @@ window.axolotl.sessions = { function resetKeepAliveTimer() { clearTimeout(keepAliveTimer); keepAliveTimer = setTimeout(function() { - socket.send( - new textsecure.protobuf.WebSocketMessage({ - type: textsecure.protobuf.WebSocketMessage.Type.REQUEST, - request: { verb: 'GET', path: '/v1/keepalive' } - }).encode().toArrayBuffer() - ); + if (socket.readyState === WebSocket.OPEN) { + socket.send( + new textsecure.protobuf.WebSocketMessage({ + type: textsecure.protobuf.WebSocketMessage.Type.REQUEST, + request: { verb: 'GET', path: '/v1/keepalive' } + }).encode().toArrayBuffer() + ); + } resetKeepAliveTimer(); - }, 60000); + }, 55000); }; function onclose(e) { diff --git a/libtextsecure/websocket.js b/libtextsecure/websocket.js index 64c2a4c66..f97233e8d 100644 --- a/libtextsecure/websocket.js +++ b/libtextsecure/websocket.js @@ -39,15 +39,17 @@ function resetKeepAliveTimer() { clearTimeout(keepAliveTimer); keepAliveTimer = setTimeout(function() { - socket.send( - new textsecure.protobuf.WebSocketMessage({ - type: textsecure.protobuf.WebSocketMessage.Type.REQUEST, - request: { verb: 'GET', path: '/v1/keepalive' } - }).encode().toArrayBuffer() - ); + if (socket.readyState === WebSocket.OPEN) { + socket.send( + new textsecure.protobuf.WebSocketMessage({ + type: textsecure.protobuf.WebSocketMessage.Type.REQUEST, + request: { verb: 'GET', path: '/v1/keepalive' } + }).encode().toArrayBuffer() + ); + } resetKeepAliveTimer(); - }, 60000); + }, 55000); }; function onclose(e) {