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) { 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 +105,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 +120,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 +240,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);
} }