From b9969b14b6c3bdf272fe7af6d3e03e1a6a03a0f9 Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 11 Mar 2015 14:06:29 -0700 Subject: [PATCH] Always reconnect the socket except when there is an error Turns out we can get ABNORMAL_CODE (1006) for disconnects where (for instance) we pause the background page too long. However, in these cases there is no preceeding ErrorEvent. In contrast, when we have bad authentication credentials, there is an ErrorEvent. Thus, this change ensures that we only reconnect if there was no Error. --- js/libtextsecure.js | 8 ++++++-- libtextsecure/websocket.js | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index b02aa93f..99235a53 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -15915,6 +15915,7 @@ window.axolotl.sessions = { onerror : function() {}, getStatus : function() { return socket.readyState; } }; + var error; function resetKeepAliveTimer() { clearTimeout(keepAliveTimer); @@ -15933,16 +15934,19 @@ window.axolotl.sessions = { }; function onclose(e) { - if (e.code === 1000) { // CLOSE_NORMAL + if (!error) { reconnectSemaphore--; setTimeout(connect, reconnectTimeout); - } else { + } + if (e !== 1000 ) { // CLOSE_NORMAL console.log('websocket closed', e.code); } socketWrapper.onclose(e); }; function onerror(e) { + error = e; + console.log('websocket error'); socketWrapper.onerror(e); }; diff --git a/libtextsecure/websocket.js b/libtextsecure/websocket.js index f97233e8..df134e9e 100644 --- a/libtextsecure/websocket.js +++ b/libtextsecure/websocket.js @@ -35,6 +35,7 @@ onerror : function() {}, getStatus : function() { return socket.readyState; } }; + var error; function resetKeepAliveTimer() { clearTimeout(keepAliveTimer); @@ -53,16 +54,19 @@ }; function onclose(e) { - if (e.code === 1000) { // CLOSE_NORMAL + if (!error) { reconnectSemaphore--; setTimeout(connect, reconnectTimeout); - } else { + } + if (e !== 1000 ) { // CLOSE_NORMAL console.log('websocket closed', e.code); } socketWrapper.onclose(e); }; function onerror(e) { + error = e; + console.log('websocket error'); socketWrapper.onerror(e); };