many bugs fix in peer connections, and ux

This commit is contained in:
Matias Alejo Garcia 2014-04-12 13:37:41 -03:00
commit a28e98e85d
5 changed files with 58 additions and 41 deletions

View file

@ -67,6 +67,7 @@ CopayPeer.prototype._showConnectedPeers = function() {
};
CopayPeer.prototype._onClose = function(peerId) {
console.log('[CopayPeer.js.70] _onClose'); //TODO
this.connectedPeers = CopayPeer._arrayRemove(peerId, this.connectedPeers);
this._notify();
};
@ -92,7 +93,7 @@ CopayPeer.prototype._onData = function(data, isInbound) {
console.log('### ERROR ON DATA: "%s" ', data, isInbound, e);
return;
};
console.log('### RECEIVED TYPE: %s FROM %s', obj.data.type, obj.sender);
console.log('### RECEIVED TYPE: %s FROM %s', obj.data.type, obj.sender, obj.data);
switch(obj.data.type) {
case 'peerList':
@ -156,13 +157,16 @@ CopayPeer.prototype._setupConnectionHandlers = function(
});
dataConn.on('close', function() {
console.log('### CLOSE RECV FROM:', dataConn.peer); //TODO
if (self.closing) return;
console.log('### CLOSE RECV FROM:', dataConn.peer);
self._onClose(dataConn.peer);
if (typeof closeCallback === 'function') closeCallback();
});
};
CopayPeer.prototype._notify = function(newPeer) {
console.log('[CopayPeer.js.168:_notify:]'); //TODO
this._showConnectedPeers();
this.emit('networkChange', newPeer);
};
@ -182,6 +186,10 @@ CopayPeer.prototype._setupPeerHandlers = function(openCallback) {
p.on('error', function(err) {
console.log('### PEER ERROR:', err);
self.peer.disconnect();
self.peer.destroy();
self.peer = null;
this.emit('abort');
});
p.on('connection', function(dataConn) {
@ -266,9 +274,13 @@ CopayPeer.prototype.connectTo = function(peerId, openCallback, closeCallback ) {
};
CopayPeer.prototype.disconnect = function(peerId, cb) {
console.log('[CopayPeer.js.268:disconnect:]'); //TODO
var self = this;
self.closing = 1;
this.send(null, { type: 'disconnect' }, function() {
console.log('[CopayPeer.js.273] disconnect CB'); //TODO
self.connectedPeers = [];
self.peerId = null;
if (self.peer) {
@ -276,6 +288,7 @@ CopayPeer.prototype.disconnect = function(peerId, cb) {
self.peer.destroy();
self.peer = null;
}
self.closing = 0;
if (typeof cb === 'function') cb();
});
};

View file

@ -72,6 +72,7 @@ PublicKeyRing.fromObj = function (data) {
var w = new PublicKeyRing(config);
w.id = data.id;
w.requiredCopayers = data.requiredCopayers;
w.totalCopayers = data.totalCopayers;
w.addressIndex = data.addressIndex;