fix firefox / timing in connection

This commit is contained in:
Matias Alejo Garcia 2014-04-20 16:16:09 -03:00
commit 019e841b31
3 changed files with 29 additions and 14 deletions

View file

@ -97,8 +97,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 +105,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 +120,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 +240,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);

View file

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

View file

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