simply a little webRTC error handling, add more messages
This commit is contained in:
parent
c5aa3372d2
commit
521dd3efe5
6 changed files with 57 additions and 39 deletions
|
|
@ -161,6 +161,7 @@ Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
|||
Wallet.prototype._handleConnect = function(newCopayerId) {
|
||||
if (newCopayerId) {
|
||||
this.log('#### Setting new COPAYER:', newCopayerId);
|
||||
this.currentDelay = this.reconnectDelay;
|
||||
this.sendWalletId(newCopayerId);
|
||||
}
|
||||
var peerID = this.network.peerFromCopayer(newCopayerId)
|
||||
|
|
@ -232,18 +233,11 @@ Wallet.prototype.netStart = function() {
|
|||
net.on('connect', self._handleConnect.bind(self));
|
||||
net.on('disconnect', self._handleDisconnect.bind(self));
|
||||
net.on('data', self._handleData.bind(self));
|
||||
net.on('openError', function() {
|
||||
self.log('[Wallet.js.132:openError:] GOT openError'); //TODO
|
||||
self.emit('openError');
|
||||
});
|
||||
net.on('error', function() {
|
||||
self.emit('connectionError');
|
||||
});
|
||||
net.on('close', function() {
|
||||
self.emit('close');
|
||||
});
|
||||
net.on('serverError', function() {
|
||||
self.emit('serverError');
|
||||
net.on('serverError', function(msg) {
|
||||
self.emit('serverError', msg);
|
||||
});
|
||||
|
||||
var myId = self.getMyCopayerId();
|
||||
|
|
@ -271,9 +265,12 @@ Wallet.prototype.netStart = function() {
|
|||
|
||||
Wallet.prototype.scheduleConnect = function() {
|
||||
var self = this;
|
||||
self.currentDelay = self.currentDelay || self.reconnectDelay;
|
||||
|
||||
if (self.network.isOnline()) {
|
||||
self.connectToAll();
|
||||
setTimeout(self.scheduleConnect.bind(self), self.reconnectDelay);
|
||||
self.currentDelay *=2;
|
||||
setTimeout(self.scheduleConnect.bind(self), self.currentDelay);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ function Network(opts) {
|
|||
this.apiKey = opts.apiKey || 'lwjd5qra8257b9';
|
||||
this.debug = opts.debug || 3;
|
||||
this.maxPeers = opts.maxPeers || 10;
|
||||
this.reconnectAttempts = opts.reconnectAttempts || 3;
|
||||
this.sjclParams = opts.sjclParams || {
|
||||
salt: 'f28bfb49ef70573c',
|
||||
iter:500,
|
||||
|
|
@ -49,6 +50,7 @@ Network.prototype.cleanUp = function() {
|
|||
this.isInboundPeerAuth=[];
|
||||
this.copayerForPeer={};
|
||||
this.connections={};
|
||||
this.criticalErr='';
|
||||
if (this.peer) {
|
||||
this.peer.disconnect();
|
||||
this.peer.destroy();
|
||||
|
|
@ -187,11 +189,7 @@ Network.prototype._onData = function(encStr, isInbound, peerId) {
|
|||
}
|
||||
};
|
||||
|
||||
Network.prototype._checkAnyPeer = function() {
|
||||
if (!this.connectedPeers.length) {
|
||||
this.cleanUp();
|
||||
this.emit('openError');
|
||||
}
|
||||
Network.prototype._checkAnyPeer = function(msg) {
|
||||
if (this.connectedPeers.length === 1) {
|
||||
this.emit('onlyYou');
|
||||
}
|
||||
|
|
@ -246,10 +244,10 @@ Network.prototype._setupPeerHandlers = function(openCallback) {
|
|||
});
|
||||
|
||||
p.on('error', function(err) {
|
||||
if (!err.message.match(/Could\snot\sconnect\sto peer/)) {
|
||||
self.emit('error', err);
|
||||
console.log('RECV ERROR: ', err); //TODO
|
||||
if (!err.message.match(/Could\snot\sconnect\sto peer/) ) {
|
||||
self.criticalError=err.message;
|
||||
}
|
||||
self._checkAnyPeer();
|
||||
});
|
||||
|
||||
p.on('connection', function(dataConn) {
|
||||
|
|
@ -319,17 +317,18 @@ Network.prototype.start = function(opts, openCallback) {
|
|||
self.peer.removeAllListeners();
|
||||
}
|
||||
|
||||
if (self.tries < 2) {
|
||||
if (!self.criticalError && self.tries < self.reconnectAttempts) {
|
||||
self.tries++;
|
||||
self.peer = new Peer(self.peerId, self.opts);
|
||||
self.started = true;
|
||||
self._setupPeerHandlers(openCallback);
|
||||
|
||||
setTimeout(setupPeer, 3000); // Schedule retry
|
||||
return;
|
||||
}
|
||||
|
||||
self.emit('serverError');
|
||||
if (self.criticalError && self.criticalError.match(/taken/)) {
|
||||
self.criticalError=' Looks like you are already connected to this wallet please close all other Copay Wallets '
|
||||
}
|
||||
self.emit('serverError', self.criticalError);
|
||||
self.cleanUp();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue