fixes handling networking errors and retries. Adds tests

This commit is contained in:
Matias Alejo Garcia 2014-07-08 15:25:12 -03:00
commit bbac45ee7a
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) {