diff --git a/config.js b/config.js index 13f6db28e..3ac6bde6e 100644 --- a/config.js +++ b/config.js @@ -15,10 +15,12 @@ var defaultConfig = { // network layer config network: { testnet: { - url: 'https://test-insight.bitpay.com:443' + url: 'https://test-insight.bitpay.com:443', + transports: ['polling'], }, livenet: { - url: 'https://insight.bitpay.com:443' + url: 'https://insight.bitpay.com:443', + transports: ['polling'], }, }, diff --git a/js/models/Async.js b/js/models/Async.js index 217eb9869..ee1e897ed 100644 --- a/js/models/Async.js +++ b/js/models/Async.js @@ -18,6 +18,16 @@ function Network(opts) { this.url = opts.url; this.secretNumber = opts.secretNumber; this.cleanUp(); + + this.socketOptions = { + reconnection: true, + 'force new connection': true, + 'secure': this.url.indexOf('https') === 0, + }; + + if (opts.transports) { + this.socketOptions['transports'] = opts.transports; + } } nodeUtil.inherits(Network, EventEmitter); @@ -191,7 +201,7 @@ Network.prototype._onMessage = function(enc) { this._deletePeer(sender); return; } - log.debug('receiving ' + JSON.stringify(payload)); + log.debug('Async: receiving ' + JSON.stringify(payload)); var self = this; switch (payload.type) { @@ -254,6 +264,8 @@ Network.prototype._setupConnectionHandlers = function(opts, cb) { self.socket.on('connect', function() { var pubkey = self.getKey().public.toString('hex'); + log.debug('Async subcribing to:pubkey:',pubkey); + self.socket.emit('subscribe', pubkey); self.socket.on('disconnect', function() { @@ -324,11 +336,9 @@ Network.prototype.start = function(opts, openCallback) { }; Network.prototype.createSocket = function() { - return io.connect(this.url, { - reconnection: true, - 'force new connection': true, - 'secure': this.url.indexOf('https') === 0, - }); + + console.log('Async: Connecting to socket:', this.url, this.socketOptions); //TODO + return io.connect(this.url, this.socketOptions); }; Network.prototype.getOnlinePeerIDs = function() { diff --git a/js/models/Insight.js b/js/models/Insight.js index 5b6e0e32c..4c1a4be52 100644 --- a/js/models/Insight.js +++ b/js/models/Insight.js @@ -42,6 +42,11 @@ var Insight = function(opts) { 'secure': opts.url.indexOf('https') === 0 }; + + if (opts.transports) { + this.opts['transports'] = opts.transports; + } + this.socket = this.getSocket(); } diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 88cc0f7cb..18869f218 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -893,8 +893,9 @@ Wallet.prototype.netStart = function() { self.emit('connectionError'); }); - log.debug('Starting wallet networking'); + log.debug('Wallet: Starting networking'); net.start(startOpts, function() { + log.debug('Wallet: Networking ready'); self._setBlockchainListeners(); self.emit('ready', net.getPeer()); setTimeout(function() {