diff --git a/js/background.js b/js/background.js index f9200d20b966..ec5066671cc4 100644 --- a/js/background.js +++ b/js/background.js @@ -45,22 +45,22 @@ } }; + window.addEventListener('textsecure:message', onMessageReceived); + window.addEventListener('textsecure:receipt', onDeliveryReceipt); + window.addEventListener('textsecure:contact', onContactReceived); + window.addEventListener('textsecure:group', onGroupReceived); + window.addEventListener('textsecure:sent', onSentMessage); + window.addEventListener('textsecure:error', onError); + + if (open) { + openInbox(); + } + function init() { if (!textsecure.registration.isDone()) { return; } - window.addEventListener('textsecure:message', onMessageReceived); - window.addEventListener('textsecure:receipt', onDeliveryReceipt); - window.addEventListener('textsecure:contact', onContactReceived); - window.addEventListener('textsecure:group', onGroupReceived); - window.addEventListener('textsecure:sent', onSentMessage); - window.addEventListener('textsecure:error', onError); - // initialize the socket and start listening for messages messageReceiver = new textsecure.MessageReceiver(window); - - if (open) { - openInbox(); - } } function onContactReceived(ev) { @@ -132,6 +132,11 @@ return; } + if (e.name === 'HTTPError' && e.code == -1) { + setTimeout(init, 60000); + return; + } + if (ev.proto) { var envelope = ev.proto; var message = initIncomingMessage(envelope.source, envelope.timestamp.toNumber());