Merge pull request #100 from matiu/feature/ux7

fix firefox / timing in connection
This commit is contained in:
Ryan X. Charles 2014-04-20 16:52:53 -03:00
commit 3215d341bb
3 changed files with 44 additions and 28 deletions

View file

@ -50,17 +50,17 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
var inPKR = copay.PublicKeyRing.fromObj(data.publicKeyRing); var inPKR = copay.PublicKeyRing.fromObj(data.publicKeyRing);
var hasChanged = pkr.merge(inPKR, true); var hasChanged = pkr.merge(inPKR, true);
if (hasChanged && !data.isBroadcast) { if (hasChanged) {
this.log('### BROADCASTING PKR'); this.log('### BROADCASTING PKR');
recipients = null; recipients = null;
shouldSend = true; shouldSend = true;
} }
else if (isInbound && !data.isBroadcast) { // else if (isInbound && !data.isBroadcast) {
// always replying to connecting peer // // always replying to connecting peer
this.log('### REPLYING PKR TO:', senderId); // this.log('### REPLYING PKR TO:', senderId);
recipients = senderId; // recipients = senderId;
shouldSend = true; // shouldSend = true;
} // }
if (shouldSend) { if (shouldSend) {
this.sendPublicKeyRing(recipients); this.sendPublicKeyRing(recipients);
@ -78,17 +78,18 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
var mergeInfo = this.txProposals.merge(inTxp, true); var mergeInfo = this.txProposals.merge(inTxp, true);
var addSeen = this.addSeenToTxProposals(); var addSeen = this.addSeenToTxProposals();
if ((mergeInfo.merged && !data.isBroadcast) || addSeen) { // if ((mergeInfo.merged && !data.isBroadcast) || addSeen) {
if (mergeInfo.merged || addSeen) {
this.log('### BROADCASTING txProposals. ' ); this.log('### BROADCASTING txProposals. ' );
recipients = null; recipients = null;
shouldSend = true; shouldSend = true;
} }
else if (isInbound && !data.isBroadcast) { // else if (isInbound && !data.isBroadcast) {
// always replying to connecting peer // // always replying to connecting peer
this.log('### REPLYING txProposals TO:', senderId); // this.log('### REPLYING txProposals TO:', senderId);
recipients = senderId; // recipients = senderId;
shouldSend = true; // shouldSend = true;
} // }
if (shouldSend) if (shouldSend)
this.sendTxProposals(recipients); this.sendTxProposals(recipients);
@ -97,8 +98,7 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
}; };
Wallet.prototype._handleData = 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) { if (this.id !== data.walletId) {
this.emit('badMessage',senderId); this.emit('badMessage',senderId);
this.log('badMessage FROM:', senderId); //TODO this.log('badMessage FROM:', senderId); //TODO
@ -106,6 +106,12 @@ console.log('_handleData: senderId:',senderId); //TODO
} }
this.log('[Wallet.js.98]' , data.type); //TODO this.log('[Wallet.js.98]' , data.type); //TODO
switch(data.type) { switch(data.type) {
case 'walletReady':
console.log('[Wallet.js.109] RECV WALLETREADY'); //TODO
this.sendPublicKeyRing(senderId);
this.sendTxProposals(senderId);
break;
case 'publicKeyRing': case 'publicKeyRing':
this._handlePublicKeyRing(senderId, data, isInbound); this._handlePublicKeyRing(senderId, data, isInbound);
break; break;
@ -115,16 +121,15 @@ console.log('_handleData: senderId:',senderId); //TODO
} }
}; };
Wallet.prototype._handleNetworkChange = function(newPeer) { Wallet.prototype._handleNetworkChange = function(newPeerId) {
if (newPeer) { if (newPeerId) {
this.log('#### Setting new PEER:', newPeer); this.log('#### Setting new PEER:', newPeerId);
this.sendWalletId(newPeer); this.sendWalletId(newPeerId);
this.sendPublicKeyRing(newPeer);
this.sendTxProposals(newPeer);
} }
this.emit('refresh'); this.emit('refresh');
}; };
Wallet.prototype._optsToObj = function () { Wallet.prototype._optsToObj = function () {
var obj = { var obj = {
id: this.id, id: this.id,
@ -236,6 +241,15 @@ Wallet.prototype.sendTxProposals = function(recipients) {
this.emit('txProposalsUpdated', this.txProposals); 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) { Wallet.prototype.sendWalletId = function(recipients) {
this.log('### SENDING walletId TO:', recipients||'All', this.walletId); this.log('### SENDING walletId TO:', recipients||'All', this.walletId);

View file

@ -134,6 +134,7 @@ WalletFactory.prototype.getWalletIds = function() {
WalletFactory.prototype.remove = function(walletId) { WalletFactory.prototype.remove = function(walletId) {
// TODO remove wallet contents // 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.start(function() {
self.network.connectTo(peerId); self.network.connectTo(peerId);
self.network.on('walletId', function(data) { self.network.on('data', function(sender, data) {
data.opts.privateKey = privateKey; if (data.type ==='walletId') {
return cb(self.open(data.walletId, data.opts)); data.opts.privateKey = privateKey;
var w = self.open(data.walletId, data.opts);
w.sendWalletReady(peerId);
return cb(w);
}
}); });
}); });
}; };

View file

@ -104,9 +104,6 @@ Network.prototype._onData = function(data, isInbound) {
case 'disconnect': case 'disconnect':
this._onClose(obj.sender); this._onClose(obj.sender);
break; break;
case 'walletId':
this.emit('walletId', obj.data);
break;
default: default:
this.emit('data', obj.sender, obj.data, isInbound); this.emit('data', obj.sender, obj.data, isInbound);
} }