make it work with reconnections

This commit is contained in:
Manuel Araoz 2014-08-22 13:13:04 -04:00
commit 81a20cb1dc
2 changed files with 332 additions and 326 deletions

View file

@ -45,7 +45,6 @@ Network.prototype.cleanUp = function() {
this.copayerForPeer = {};
this.connections = {};
this.criticalErr = '';
this.removeAllListeners();
if (this.socket) {
this.socket.disconnect();
this.socket = null;
@ -224,6 +223,7 @@ Network.prototype._setupConnectionHandlers = function(cb) {
var self = this;
self.socket.on('connect', function() {
alert('socket connected!');
self.socket.on('disconnect', function() {
self.cleanUp();
});
@ -298,6 +298,7 @@ Network.prototype.start = function(opts, openCallback) {
this.socket.emit('subscribe', pubkey);
this.socket.emit('sync', opts.lastTimestamp);
this.started = true;
alert('started = true');
};
@ -305,6 +306,7 @@ Network.prototype.createSocket = function(host, port) {
var hostPort = host + ':' + port;
return io.connect(hostPort, {
reconnection: true,
'force new connection': true
});
};

View file

@ -124,6 +124,7 @@ angular.module('copayApp.services')
notification.error('Error', 'Received corrupt message from ' + peerId);
});
w.on('ready', function(myPeerID) {
alert('wallet ready!');
$rootScope.wallet = w;
if ($rootScope.pendingPayment) {
$location.path('send');
@ -290,7 +291,10 @@ angular.module('copayApp.services')
function getActionList(actions) {
var peers = Object.keys(actions).map(function(i) {
return {cId: i, actions: actions[i] }
return {
cId: i,
actions: actions[i]
}
});
return peers.sort(function(a, b) {