make it work with reconnections
This commit is contained in:
parent
4fff3a9d4d
commit
81a20cb1dc
2 changed files with 332 additions and 326 deletions
|
|
@ -45,7 +45,6 @@ Network.prototype.cleanUp = function() {
|
||||||
this.copayerForPeer = {};
|
this.copayerForPeer = {};
|
||||||
this.connections = {};
|
this.connections = {};
|
||||||
this.criticalErr = '';
|
this.criticalErr = '';
|
||||||
this.removeAllListeners();
|
|
||||||
if (this.socket) {
|
if (this.socket) {
|
||||||
this.socket.disconnect();
|
this.socket.disconnect();
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
|
|
@ -224,6 +223,7 @@ Network.prototype._setupConnectionHandlers = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.socket.on('connect', function() {
|
self.socket.on('connect', function() {
|
||||||
|
alert('socket connected!');
|
||||||
self.socket.on('disconnect', function() {
|
self.socket.on('disconnect', function() {
|
||||||
self.cleanUp();
|
self.cleanUp();
|
||||||
});
|
});
|
||||||
|
|
@ -298,6 +298,7 @@ Network.prototype.start = function(opts, openCallback) {
|
||||||
this.socket.emit('subscribe', pubkey);
|
this.socket.emit('subscribe', pubkey);
|
||||||
this.socket.emit('sync', opts.lastTimestamp);
|
this.socket.emit('sync', opts.lastTimestamp);
|
||||||
this.started = true;
|
this.started = true;
|
||||||
|
alert('started = true');
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -305,6 +306,7 @@ Network.prototype.createSocket = function(host, port) {
|
||||||
var hostPort = host + ':' + port;
|
var hostPort = host + ':' + port;
|
||||||
return io.connect(hostPort, {
|
return io.connect(hostPort, {
|
||||||
reconnection: true,
|
reconnection: true,
|
||||||
|
'force new connection': true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
|
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('controllerUtils', function($rootScope, $sce, $location, notification, $timeout, Socket, video, uriHandler) {
|
.factory('controllerUtils', function($rootScope, $sce, $location, notification, $timeout, Socket, video, uriHandler) {
|
||||||
var root = {};
|
var root = {};
|
||||||
root.getVideoMutedStatus = function(copayer) {
|
root.getVideoMutedStatus = function(copayer) {
|
||||||
if (!$rootScope.videoInfo) return;
|
if (!$rootScope.videoInfo) return;
|
||||||
|
|
@ -124,6 +124,7 @@ angular.module('copayApp.services')
|
||||||
notification.error('Error', 'Received corrupt message from ' + peerId);
|
notification.error('Error', 'Received corrupt message from ' + peerId);
|
||||||
});
|
});
|
||||||
w.on('ready', function(myPeerID) {
|
w.on('ready', function(myPeerID) {
|
||||||
|
alert('wallet ready!');
|
||||||
$rootScope.wallet = w;
|
$rootScope.wallet = w;
|
||||||
if ($rootScope.pendingPayment) {
|
if ($rootScope.pendingPayment) {
|
||||||
$location.path('send');
|
$location.path('send');
|
||||||
|
|
@ -161,7 +162,7 @@ angular.module('copayApp.services')
|
||||||
notification.info('Transaction Update', 'A transaction was rejected by ' + user);
|
notification.info('Transaction Update', 'A transaction was rejected by ' + user);
|
||||||
break;
|
break;
|
||||||
case 'corrupt':
|
case 'corrupt':
|
||||||
notification.error('Transaction Error', 'Received corrupt transaction from '+user);
|
notification.error('Transaction Error', 'Received corrupt transaction from ' + user);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -290,7 +291,10 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
function getActionList(actions) {
|
function getActionList(actions) {
|
||||||
var peers = Object.keys(actions).map(function(i) {
|
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) {
|
return peers.sort(function(a, b) {
|
||||||
|
|
@ -313,7 +317,7 @@ angular.module('copayApp.services')
|
||||||
// Retry
|
// Retry
|
||||||
if (status == 1) return; // Skip the first try
|
if (status == 1) return; // Skip the first try
|
||||||
connectionLost = true;
|
connectionLost = true;
|
||||||
notification.error('Networking problem', 'Connection to Insight lost, reconnecting (attempt number ' + (status-1) + ')');
|
notification.error('Networking problem', 'Connection to Insight lost, reconnecting (attempt number ' + (status - 1) + ')');
|
||||||
});
|
});
|
||||||
|
|
||||||
root._setCommError = function(e) {
|
root._setCommError = function(e) {
|
||||||
|
|
@ -375,4 +379,4 @@ angular.module('copayApp.services')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return root;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue