From 6f9488865914b14e4c222e9e483d4deb8c03bf9e Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 16 Sep 2015 15:01:08 -0700 Subject: [PATCH] Use online event listener to reconnect more smrtly No need to retry if we know we're offline. // FREEBIE --- js/background.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/background.js b/js/background.js index 44107d9b..7410bb40 100644 --- a/js/background.js +++ b/js/background.js @@ -47,6 +47,7 @@ } function init() { + window.removeEventListener('online', init); if (!textsecure.registration.isDone()) { return; } // initialize the socket and start listening for messages @@ -124,7 +125,12 @@ } if (e.name === 'HTTPError' && e.code == -1) { - setTimeout(init, 60000); + // Failed to connect to server + if (navigator.onLine) { + setTimeout(init, 60000); + } else { + window.addEventListener('online', init); + } return; }