Merge pull request #870 from matiu/bug/handlerNetErrors

Bug/handler net errors
This commit is contained in:
Gustavo Maximiliano Cortez 2014-07-08 15:59:40 -03:00
commit 937369d0c7
3 changed files with 117 additions and 35 deletions

View file

@ -223,17 +223,24 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
key: privateKey.getIdKey()
};
self.network.cleanUp();
// This is a hack to reconize if the connection was rejected or the peer wasn't there.
var connectedOnce = false;
self.network.on('connected', function(sender, data) {
connectedOnce = true;
});
self.network.on('onlyYou', function(sender, data) {
return cb(connectedOnce ? 'walletFull' : 'joinError');
});
self.network.on('serverError', function() {
console.log('[WalletFactory.js.236]'); //TODO
return cb('joinError');
});
self.network.start(opts, function() {
self.network.connectTo(s.pubKey);
// This is a hack to reconize if the connection was rejected or the peer wasn't there.
var connectedOnce = false;
self.network.on('connected', function(sender, data) {
connectedOnce = true;
});
self.network.on('onlyYou', function(sender, data) {
return cb(connectedOnce ? 'walletFull' : 'joinError');
});
self.network.on('data', function(sender, data) {
if (data.type === 'walletId') {
if (data.networkName !== self.networkName) {