From 675be2b5693f4e99be5cc0d5dd906aca360849e2 Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 5 Nov 2015 12:45:18 -0800 Subject: [PATCH] Don't reconnect if close was called Fixes a bug during re-registration where we continue to re-open the socket using old credentials. // FREEBIE --- js/libtextsecure.js | 7 +++++-- libtextsecure/message_receiver.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index e6cf78bc..8053efa5 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -39312,7 +39312,7 @@ MessageReceiver.prototype = { this.pending = Promise.resolve(); }, close: function() { - this.wsr.close(); + this.socket.close(3000, 'called close'); delete this.listeners; }, onopen: function() { @@ -39322,8 +39322,11 @@ MessageReceiver.prototype = { console.log('websocket error'); }, onclose: function(ev) { + console.log('websocket closed', ev.code, ev.reason || ''); + if (ev.code === 3000) { + return; + } var eventTarget = this; - console.log('websocket closed', ev.code); // possible 403 or network issue. Make an request to confirm this.server.getDevices(this.number). then(this.connect.bind(this)). // No HTTP error? Reconnect diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 2d6f39fd..55e65d19 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -32,7 +32,7 @@ MessageReceiver.prototype = { this.pending = Promise.resolve(); }, close: function() { - this.wsr.close(); + this.socket.close(3000, 'called close'); delete this.listeners; }, onopen: function() { @@ -42,8 +42,11 @@ MessageReceiver.prototype = { console.log('websocket error'); }, onclose: function(ev) { + console.log('websocket closed', ev.code, ev.reason || ''); + if (ev.code === 3000) { + return; + } var eventTarget = this; - console.log('websocket closed', ev.code); // possible 403 or network issue. Make an request to confirm this.server.getDevices(this.number). then(this.connect.bind(this)). // No HTTP error? Reconnect