connect working
This commit is contained in:
parent
132920f909
commit
55ba5e6d37
4 changed files with 24 additions and 25 deletions
|
|
@ -49,12 +49,16 @@ Wallet.getRandomId = function() {
|
|||
return r;
|
||||
};
|
||||
|
||||
Wallet.prototype.seedCopayer = function(pubKey) {
|
||||
this.seededCopayerId = pubKey;
|
||||
};
|
||||
|
||||
Wallet.prototype.connectToAll = function() {
|
||||
var all = this.publicKeyRing.getAllCopayerIds();
|
||||
this.network.connectToCopayers(all);
|
||||
if (this.firstCopayerId) {
|
||||
this.sendWalletReady(this.firstCopayerId);
|
||||
this.firstCopayerId = null;
|
||||
if (this.seededCopayerId) {
|
||||
this.sendWalletReady(this.seededCopayerId);
|
||||
this.seededCopayerId = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -121,14 +125,17 @@ Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
|||
}
|
||||
};
|
||||
|
||||
Wallet.prototype._handleNetworkChange = function(newCopayerId) {
|
||||
Wallet.prototype._handleConnect = function(newCopayerId) {
|
||||
if (newCopayerId) {
|
||||
this.log('#### Setting new COPAYER:', newCopayerId);
|
||||
this.sendWalletId(newCopayerId);
|
||||
this.emit('peer', this.network.peerFromCopayer(newCopayerId));
|
||||
}
|
||||
var peerID = this.network.peerFromCopayer(newCopayerId)
|
||||
this.emit('connect', peerID);
|
||||
};
|
||||
|
||||
Wallet.prototype._handleDisconnect = function(copayerID) {
|
||||
};
|
||||
|
||||
Wallet.prototype._optsToObj = function() {
|
||||
var obj = {
|
||||
|
|
@ -181,9 +188,9 @@ Wallet.prototype.netStart = function() {
|
|||
var self = this;
|
||||
var net = this.network;
|
||||
net.removeAllListeners();
|
||||
net.on('networkChange', self._handleNetworkChange.bind(self));
|
||||
net.on('connect', self._handleConnect.bind(self));
|
||||
net.on('disconnect', self._handleDisconnect.bind(self));
|
||||
net.on('data', self._handleData.bind(self));
|
||||
net.on('open', function() {}); // TODO
|
||||
net.on('openError', function() {
|
||||
self.log('[Wallet.js.132:openError:] GOT openError'); //TODO
|
||||
self.emit('openError');
|
||||
|
|
@ -283,7 +290,6 @@ Wallet.prototype.sendWalletReady = function(recipients) {
|
|||
type: 'walletReady',
|
||||
walletId: this.id,
|
||||
});
|
||||
this.emit('walletReady');
|
||||
};
|
||||
|
||||
Wallet.prototype.sendWalletId = function(recipients) {
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
|
|||
data.opts.passphrase = passphrase;
|
||||
data.opts.id = data.walletId;
|
||||
var w = self.create(data.opts);
|
||||
w.firstCopayerId = s.pubKey;
|
||||
w.seedCopayer(s.pubKey);
|
||||
return cb(null, w);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ var bitcore = require('bitcore');
|
|||
var util = bitcore.util;
|
||||
/*
|
||||
* Emits
|
||||
* 'networkChange'
|
||||
* 'connect'
|
||||
* when network layout has change (new/lost peers, etc)
|
||||
*
|
||||
* 'data'
|
||||
|
|
@ -117,7 +117,7 @@ Network.prototype._deletePeer = function(peerId) {
|
|||
|
||||
Network.prototype._onClose = function(peerId) {
|
||||
this._deletePeer(peerId);
|
||||
this._notifyNetworkChange();
|
||||
this.emit('disconnect');
|
||||
};
|
||||
|
||||
Network.prototype.connectToCopayers = function(copayerIds) {
|
||||
|
|
@ -128,8 +128,7 @@ Network.prototype.connectToCopayers = function(copayerIds) {
|
|||
if (this.allowedCopayerIds && !this.allowedCopayerIds[copayerId]) {
|
||||
console.log('### IGNORING STRANGE COPAYER:', copayerId);
|
||||
this._deletePeer(this.peerFromCopayer(copayerId));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.log('### CONNECTING TO:', copayerId);
|
||||
self.connectTo(copayerId);
|
||||
}
|
||||
|
|
@ -178,8 +177,7 @@ Network.prototype._onData = function(encStr, isInbound, peerId) {
|
|||
console.log('#### Peer sent hello. Setting it up.'); //TODO
|
||||
this._addConnectedCopayer(payload.copayerId, isInbound);
|
||||
this._setInboundPeerAuth(peerId, true);
|
||||
this._notifyNetworkChange( isInbound ? payload.copayerId : null);
|
||||
this.emit('open');
|
||||
this.emit('connect', payload.copayerId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -227,6 +225,7 @@ Network.prototype._setupConnectionHandlers = function(dataConn, toCopayerId) {
|
|||
if(toCopayerId) {
|
||||
self._addConnectedCopayer(toCopayerId);
|
||||
self._sendHello(toCopayerId);
|
||||
self.emit('connect', toCopayerId); // TODO: try to unify both 'connect' emits
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -251,10 +250,6 @@ Network.prototype._setupConnectionHandlers = function(dataConn, toCopayerId) {
|
|||
});
|
||||
};
|
||||
|
||||
Network.prototype._notifyNetworkChange = function(newCopayerId) {
|
||||
this.emit('networkChange', newCopayerId);
|
||||
};
|
||||
|
||||
Network.prototype._setupPeerHandlers = function(openCallback) {
|
||||
var self = this;
|
||||
var p = this.peer;
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ angular.module('copay.controllerUtils')
|
|||
var vi = $rootScope.videoInfo[copayer]
|
||||
if (!vi) return;
|
||||
|
||||
//alert($rootScope.wallet.getOnlinePeerIDs());
|
||||
//alert(copayer);
|
||||
if ($rootScope.wallet.getOnlinePeerIDs().indexOf(copayer) === -1) {
|
||||
// peer disconnected, remove his video
|
||||
delete $rootScope.videoInfo[copayer]
|
||||
|
|
@ -81,7 +79,6 @@ angular.module('copay.controllerUtils')
|
|||
$rootScope.$digest();
|
||||
});
|
||||
w.on('refresh', function() {
|
||||
//alert('refresh');
|
||||
root.updateBalance(function() {
|
||||
$rootScope.$digest();
|
||||
});
|
||||
|
|
@ -93,9 +90,10 @@ angular.module('copay.controllerUtils')
|
|||
});
|
||||
});
|
||||
w.on('openError', root.onErrorDigest);
|
||||
w.on('peer', function(peerID) {
|
||||
//alert('peer');
|
||||
video.callPeer(peerID, handlePeerVideo);
|
||||
w.on('connect', function(peerID) {
|
||||
if (peerID) {
|
||||
video.callPeer(peerID, handlePeerVideo);
|
||||
}
|
||||
$rootScope.$digest();
|
||||
});
|
||||
w.on('close', root.onErrorDigest);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue