rm disconnect message, rename disconnect fn

This commit is contained in:
Matias Alejo Garcia 2014-08-28 18:58:43 -03:00
parent 2809a145e2
commit 6aa959dcf5
4 changed files with 16 additions and 32 deletions

View File

@ -49,12 +49,8 @@ angular.module('copayApp.controllers').controller('SidebarController', function(
}; };
function logout() { function logout() {
var w = $rootScope.wallet;
if (w) {
w.disconnect();
controllerUtils.logout(); controllerUtils.logout();
} }
}
// ng-repeat defined number of times instead of repeating over array? // ng-repeat defined number of times instead of repeating over array?
$scope.getNumber = function(num) { $scope.getNumber = function(num) {

View File

@ -323,6 +323,7 @@ Wallet.prototype._onData = function(senderId, data, ts) {
preconditions.checkArgument(ts); preconditions.checkArgument(ts);
preconditions.checkArgument(typeof ts === 'number'); preconditions.checkArgument(typeof ts === 'number');
//console.log('RECV', senderId, data);
if (data.type !== 'walletId' && this.id !== data.walletId) { if (data.type !== 'walletId' && this.id !== data.walletId) {
this.emit('corrupt', senderId); this.emit('corrupt', senderId);
@ -358,12 +359,13 @@ Wallet.prototype._onData = function(senderId, data, ts) {
case 'addressbook': case 'addressbook':
this._onAddressBook(senderId, data); this._onAddressBook(senderId, data);
break; break;
// unused messages
case 'disconnect': case 'disconnect':
this._onDisconnect(senderId, data);
break; break;
default: default:
throw new Error('unknown message type received: '+ data.type + ' from: ' + senderId) throw new Error('unknown message type received: '+ data.type + ' from: ' + senderId)
} }
this.updateTimestamp(ts); this.updateTimestamp(ts);
}; };
@ -376,12 +378,6 @@ Wallet.prototype._onConnect = function(newCopayerId) {
this.emit('connect', peerID); this.emit('connect', peerID);
}; };
Wallet.prototype._onDisconnect = function(peerID) {
this.currentDelay = null;
this.emit('disconnect', peerID);
};
Wallet.prototype.getNetworkName = function() { Wallet.prototype.getNetworkName = function() {
return this.publicKeyRing.network.name; return this.publicKeyRing.network.name;
}; };
@ -1746,15 +1742,10 @@ Wallet.prototype.indexDiscovery = function(start, change, copayerIndex, gap, cb)
} }
Wallet.prototype.disconnect = function() { Wallet.prototype.close = function() {
this.log('## DISCONNECTING'); this.log('## CLOSING');
this.lock.release(); this.lock.release();
var self = this; this.network.cleanUp();
self.send(null, {
type: 'disconnect',
walletId: this.id,
});
self.network.cleanUp();
}; };
Wallet.prototype.getNetwork = function() { Wallet.prototype.getNetwork = function() {

View File

@ -220,7 +220,7 @@ Network.prototype._setupConnectionHandlers = function(cb) {
}); });
self.socket.on('error', self._onError.bind(self)); self.socket.on('error', self._onError.bind(self));
self.socket.on('no messages', self.bind(self, 'no messages')); self.socket.on('no messages', self.emit.bind(self, 'no messages'));
self.socket.on('connect', function() { self.socket.on('connect', function() {
@ -348,23 +348,23 @@ Network.prototype.send = function(dest, payload, cb) {
dest = this.getCopayerIds(); dest = this.getCopayerIds();
payload.isBroadcast = 1; payload.isBroadcast = 1;
} }
console.log('SEND to: ' + to, payload);
if (typeof dest === 'string') if (typeof dest === 'string')
dest = [dest]; dest = [dest];
var l = dest.length; var l = dest.length;
var i = 0; var i = 0;
dest.forEach(function(to) { for(var ii in dest){
if (to === this.copayerId) var to = dest[ii];
if (to == this.copayerId)
continue; continue;
console.log('SEND to: ' + to, this.copayerId, payload);
//console.log('\t to ' + to); var message = this.encode(to, payload);
var message = self.encode(to, payload); this.socket.emit('message', message);
}
self.socket.emit('message', message);
});
if (typeof cb === 'function') cb(); if (typeof cb === 'function') cb();
}; };

View File

@ -22,7 +22,7 @@ angular.module('copayApp.services')
root.logout = function() { root.logout = function() {
if ($rootScope.wallet) if ($rootScope.wallet)
$rootScope.wallet.disconnect(); $rootScope.wallet.close();
Socket.removeAllListeners(); Socket.removeAllListeners();
@ -179,9 +179,6 @@ angular.module('copayApp.services')
} }
$rootScope.$digest(); $rootScope.$digest();
}); });
w.on('disconnect', function(peerID) {
$rootScope.$digest();
});
w.on('close', root.onErrorDigest); w.on('close', root.onErrorDigest);
w.on('locked', root.onErrorDigest.bind(this)); w.on('locked', root.onErrorDigest.bind(this));
w.netStart(); w.netStart();