From 4fff3a9d4d7fb1bb78638eb5330e05febad82d8f Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Fri, 22 Aug 2014 11:51:40 -0400 Subject: [PATCH] close socket on disconnect --- js/models/core/Wallet.js | 3 +-- js/models/network/Async.js | 23 ++++------------------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index a9c9584af..1b809ec73 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -1753,9 +1753,8 @@ Wallet.prototype.disconnect = function() { self.send(null, { type: 'disconnect', walletId: this.id, - }, function() { - self.network.cleanUp(); }); + self.network.cleanUp(); }; Wallet.prototype.getNetwork = function() { diff --git a/js/models/network/Async.js b/js/models/network/Async.js index 36b0e7437..a8aaf1fa1 100644 --- a/js/models/network/Async.js +++ b/js/models/network/Async.js @@ -46,25 +46,15 @@ Network.prototype.cleanUp = function() { this.connections = {}; this.criticalErr = ''; this.removeAllListeners(); + if (this.socket) { + this.socket.disconnect(); + this.socket = null; + } }; Network.parent = EventEmitter; // Array helpers -Network._arrayDiff = function(a, b) { - var seen = []; - var diff = []; - - for (var i = 0; i < b.length; i++) - seen[b[i]] = true; - - for (var j = 0; j < a.length; j++) - if (!seen[a[j]]) - diff.push(a[j]); - - return diff; -}; - Network._inArray = function(el, array) { return array.indexOf(el) > -1; }; @@ -303,11 +293,6 @@ Network.prototype.start = function(opts, openCallback) { this.setCopayerId(opts.copayerId); this.maxPeers = opts.maxPeers || this.maxPeers; - if (this.socket) { - this.socket.destroy(); - this.socket.removeAllListeners(); - } - this.socket = this.createSocket(this.host, this.port); this._setupConnectionHandlers(openCallback); this.socket.emit('subscribe', pubkey);