close socket on disconnect

This commit is contained in:
Manuel Araoz 2014-08-22 11:51:40 -04:00
parent 04080c6ac6
commit 4fff3a9d4d
2 changed files with 5 additions and 21 deletions

View File

@ -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() {

View File

@ -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);