Merge pull request #173 from cubedro/develop

Added web3 reconnect
This commit is contained in:
Marian OANCΞA 2015-06-12 22:05:43 +03:00
commit df25414acd
1 changed files with 40 additions and 6 deletions

View File

@ -174,13 +174,38 @@ Node.prototype.checkWeb3Connection = function()
} }
} }
Node.prototype.reconnectWeb3 = function()
{
this._web3 = false;
if(this.updateInterval)
clearInterval(this.updateInterval);
if(this.pingInterval)
clearInterval(this.pingInterval);
try
{
web3.reset();
}
catch (err)
{
console.error("Web3 reset error:", err);
}
this.checkWeb3Connection();
}
Node.prototype.startSocketConnection = function() Node.prototype.startSocketConnection = function()
{ {
console.info('wsc', 'Starting socket connection'); if( !this._socket )
{
console.info('wsc', 'Starting socket connection');
socket = new Socket( process.env.WS_SERVER || 'ws://localhost:3000' ); socket = new Socket( process.env.WS_SERVER || 'ws://localhost:3000' );
this.setupSockets(); this.setupSockets();
}
} }
Node.prototype.setupSockets = function() Node.prototype.setupSockets = function()
@ -327,13 +352,17 @@ Node.prototype.setInactive = function()
{ {
this.stats.active = false; this.stats.active = false;
this.stats.peers = 0; this.stats.peers = 0;
this.stats.pending = 0;
this.stats.mining = false; this.stats.mining = false;
this.stats.hashrate = 0; this.stats.hashrate = 0;
this.stats.gasPrice = 0;
this.stats.minerName = false;
this._down++; this._down++;
this.setUptime();
this.sendStatsUpdate(true);
// Schedule web3 reconnect
this.reconnectWeb3();
return this; return this;
} }
@ -688,6 +717,11 @@ Node.prototype.setWatches = function()
var time = now - self._lastChainLog; var time = now - self._lastChainLog;
self._lastChainLog = now; self._lastChainLog = now;
if(hash === null)
{
hash = web3.eth.blockNumber;
}
console.info('>>>', 'Chain Filter triggered: ', chalk.reset.red(hash), '- last trigger:', chalk.reset.cyan(time)); console.info('>>>', 'Chain Filter triggered: ', chalk.reset.red(hash), '- last trigger:', chalk.reset.cyan(time));
if(time < 5) if(time < 5)