added web3 reconnect

This commit is contained in:
cubedro 2015-06-12 22:03:40 +03:00
parent d2ec7e55af
commit c634623bec
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()
{
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()
@ -327,13 +352,17 @@ Node.prototype.setInactive = function()
{
this.stats.active = false;
this.stats.peers = 0;
this.stats.pending = 0;
this.stats.mining = false;
this.stats.hashrate = 0;
this.stats.gasPrice = 0;
this.stats.minerName = false;
this._down++;
this.setUptime();
this.sendStatsUpdate(true);
// Schedule web3 reconnect
this.reconnectWeb3();
return this;
}
@ -688,6 +717,11 @@ Node.prototype.setWatches = function()
var time = now - self._lastChainLog;
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));
if(time < 5)