Merge pull request #100 from matiu/feature/ux7
fix firefox / timing in connection
This commit is contained in:
commit
3215d341bb
3 changed files with 44 additions and 28 deletions
|
|
@ -50,17 +50,17 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
|||
var inPKR = copay.PublicKeyRing.fromObj(data.publicKeyRing);
|
||||
|
||||
var hasChanged = pkr.merge(inPKR, true);
|
||||
if (hasChanged && !data.isBroadcast) {
|
||||
if (hasChanged) {
|
||||
this.log('### BROADCASTING PKR');
|
||||
recipients = null;
|
||||
shouldSend = true;
|
||||
}
|
||||
else if (isInbound && !data.isBroadcast) {
|
||||
// always replying to connecting peer
|
||||
this.log('### REPLYING PKR TO:', senderId);
|
||||
recipients = senderId;
|
||||
shouldSend = true;
|
||||
}
|
||||
// else if (isInbound && !data.isBroadcast) {
|
||||
// // always replying to connecting peer
|
||||
// this.log('### REPLYING PKR TO:', senderId);
|
||||
// recipients = senderId;
|
||||
// shouldSend = true;
|
||||
// }
|
||||
|
||||
if (shouldSend) {
|
||||
this.sendPublicKeyRing(recipients);
|
||||
|
|
@ -78,17 +78,18 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
|
|||
var mergeInfo = this.txProposals.merge(inTxp, true);
|
||||
|
||||
var addSeen = this.addSeenToTxProposals();
|
||||
if ((mergeInfo.merged && !data.isBroadcast) || addSeen) {
|
||||
// if ((mergeInfo.merged && !data.isBroadcast) || addSeen) {
|
||||
if (mergeInfo.merged || addSeen) {
|
||||
this.log('### BROADCASTING txProposals. ' );
|
||||
recipients = null;
|
||||
shouldSend = true;
|
||||
}
|
||||
else if (isInbound && !data.isBroadcast) {
|
||||
// always replying to connecting peer
|
||||
this.log('### REPLYING txProposals TO:', senderId);
|
||||
recipients = senderId;
|
||||
shouldSend = true;
|
||||
}
|
||||
// else if (isInbound && !data.isBroadcast) {
|
||||
// // always replying to connecting peer
|
||||
// this.log('### REPLYING txProposals TO:', senderId);
|
||||
// recipients = senderId;
|
||||
// shouldSend = true;
|
||||
// }
|
||||
|
||||
if (shouldSend)
|
||||
this.sendTxProposals(recipients);
|
||||
|
|
@ -97,8 +98,7 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
|
|||
};
|
||||
|
||||
Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
||||
console.log('_handleData: senderId:',senderId); //TODO
|
||||
|
||||
// TODO check message signature
|
||||
if (this.id !== data.walletId) {
|
||||
this.emit('badMessage',senderId);
|
||||
this.log('badMessage FROM:', senderId); //TODO
|
||||
|
|
@ -106,6 +106,12 @@ console.log('_handleData: senderId:',senderId); //TODO
|
|||
}
|
||||
this.log('[Wallet.js.98]' , data.type); //TODO
|
||||
switch(data.type) {
|
||||
case 'walletReady':
|
||||
|
||||
console.log('[Wallet.js.109] RECV WALLETREADY'); //TODO
|
||||
this.sendPublicKeyRing(senderId);
|
||||
this.sendTxProposals(senderId);
|
||||
break;
|
||||
case 'publicKeyRing':
|
||||
this._handlePublicKeyRing(senderId, data, isInbound);
|
||||
break;
|
||||
|
|
@ -115,16 +121,15 @@ console.log('_handleData: senderId:',senderId); //TODO
|
|||
}
|
||||
};
|
||||
|
||||
Wallet.prototype._handleNetworkChange = function(newPeer) {
|
||||
if (newPeer) {
|
||||
this.log('#### Setting new PEER:', newPeer);
|
||||
this.sendWalletId(newPeer);
|
||||
this.sendPublicKeyRing(newPeer);
|
||||
this.sendTxProposals(newPeer);
|
||||
Wallet.prototype._handleNetworkChange = function(newPeerId) {
|
||||
if (newPeerId) {
|
||||
this.log('#### Setting new PEER:', newPeerId);
|
||||
this.sendWalletId(newPeerId);
|
||||
}
|
||||
this.emit('refresh');
|
||||
};
|
||||
|
||||
|
||||
Wallet.prototype._optsToObj = function () {
|
||||
var obj = {
|
||||
id: this.id,
|
||||
|
|
@ -236,6 +241,15 @@ Wallet.prototype.sendTxProposals = function(recipients) {
|
|||
this.emit('txProposalsUpdated', this.txProposals);
|
||||
};
|
||||
|
||||
Wallet.prototype.sendWalletReady = function(recipients) {
|
||||
this.log('### SENDING WalletReady TO:', recipients);
|
||||
|
||||
this.network.send( recipients, {
|
||||
type: 'walletReady',
|
||||
walletId: this.id,
|
||||
});
|
||||
this.emit('walletReady');
|
||||
};
|
||||
|
||||
Wallet.prototype.sendWalletId = function(recipients) {
|
||||
this.log('### SENDING walletId TO:', recipients||'All', this.walletId);
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ WalletFactory.prototype.getWalletIds = function() {
|
|||
|
||||
WalletFactory.prototype.remove = function(walletId) {
|
||||
// TODO remove wallet contents
|
||||
console.log('TODO: remove wallet contents');
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -147,9 +148,13 @@ WalletFactory.prototype.joinCreateSession = function(peerId, cb) {
|
|||
|
||||
self.network.start(function() {
|
||||
self.network.connectTo(peerId);
|
||||
self.network.on('walletId', function(data) {
|
||||
data.opts.privateKey = privateKey;
|
||||
return cb(self.open(data.walletId, data.opts));
|
||||
self.network.on('data', function(sender, data) {
|
||||
if (data.type ==='walletId') {
|
||||
data.opts.privateKey = privateKey;
|
||||
var w = self.open(data.walletId, data.opts);
|
||||
w.sendWalletReady(peerId);
|
||||
return cb(w);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -104,9 +104,6 @@ Network.prototype._onData = function(data, isInbound) {
|
|||
case 'disconnect':
|
||||
this._onClose(obj.sender);
|
||||
break;
|
||||
case 'walletId':
|
||||
this.emit('walletId', obj.data);
|
||||
break;
|
||||
default:
|
||||
this.emit('data', obj.sender, obj.data, isInbound);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue