add polling as default transport in socket.io

This commit is contained in:
Matias Alejo Garcia 2014-10-06 13:35:06 -03:00
commit a70fd64442
4 changed files with 27 additions and 9 deletions

View file

@ -15,10 +15,12 @@ var defaultConfig = {
// network layer config // network layer config
network: { network: {
testnet: { testnet: {
url: 'https://test-insight.bitpay.com:443' url: 'https://test-insight.bitpay.com:443',
transports: ['polling'],
}, },
livenet: { livenet: {
url: 'https://insight.bitpay.com:443' url: 'https://insight.bitpay.com:443',
transports: ['polling'],
}, },
}, },

View file

@ -18,6 +18,16 @@ function Network(opts) {
this.url = opts.url; this.url = opts.url;
this.secretNumber = opts.secretNumber; this.secretNumber = opts.secretNumber;
this.cleanUp(); 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); nodeUtil.inherits(Network, EventEmitter);
@ -191,7 +201,7 @@ Network.prototype._onMessage = function(enc) {
this._deletePeer(sender); this._deletePeer(sender);
return; return;
} }
log.debug('receiving ' + JSON.stringify(payload)); log.debug('Async: receiving ' + JSON.stringify(payload));
var self = this; var self = this;
switch (payload.type) { switch (payload.type) {
@ -254,6 +264,8 @@ Network.prototype._setupConnectionHandlers = function(opts, cb) {
self.socket.on('connect', function() { self.socket.on('connect', function() {
var pubkey = self.getKey().public.toString('hex'); var pubkey = self.getKey().public.toString('hex');
log.debug('Async subcribing to:pubkey:',pubkey);
self.socket.emit('subscribe', pubkey); self.socket.emit('subscribe', pubkey);
self.socket.on('disconnect', function() { self.socket.on('disconnect', function() {
@ -324,11 +336,9 @@ Network.prototype.start = function(opts, openCallback) {
}; };
Network.prototype.createSocket = function() { Network.prototype.createSocket = function() {
return io.connect(this.url, {
reconnection: true, console.log('Async: Connecting to socket:', this.url, this.socketOptions); //TODO
'force new connection': true, return io.connect(this.url, this.socketOptions);
'secure': this.url.indexOf('https') === 0,
});
}; };
Network.prototype.getOnlinePeerIDs = function() { Network.prototype.getOnlinePeerIDs = function() {

View file

@ -42,6 +42,11 @@ var Insight = function(opts) {
'secure': opts.url.indexOf('https') === 0 'secure': opts.url.indexOf('https') === 0
}; };
if (opts.transports) {
this.opts['transports'] = opts.transports;
}
this.socket = this.getSocket(); this.socket = this.getSocket();
} }

View file

@ -893,8 +893,9 @@ Wallet.prototype.netStart = function() {
self.emit('connectionError'); self.emit('connectionError');
}); });
log.debug('Starting wallet networking'); log.debug('Wallet: Starting networking');
net.start(startOpts, function() { net.start(startOpts, function() {
log.debug('Wallet: Networking ready');
self._setBlockchainListeners(); self._setBlockchainListeners();
self.emit('ready', net.getPeer()); self.emit('ready', net.getPeer());
setTimeout(function() { setTimeout(function() {