Merge pull request #28 from cubedro/develop

Added ping
This commit is contained in:
Marian OANCΞA 2015-04-02 18:28:49 +03:00
commit fe6083b669
1 changed files with 16 additions and 1 deletions

View File

@ -31,6 +31,8 @@ var socket = new Socket(process.env.WS_SERVER || 'ws://localhost:3000');
var WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret";
var MAX_BLOCKS_HISTORY = 36;
var UPDATE_INTERVAL = 5000;
var PING_INTERVAL = 2000;
function Node()
{
@ -86,6 +88,7 @@ function Node()
this.pendingFilter = false;
this.chainFilter = false;
this.updateInterval = false;
this.pingInterval = false;
socket.on('open', function open() {
socket.emit('hello', { id: self.id, info: self.info, secret: WS_SECRET });
@ -354,6 +357,11 @@ Node.prototype.update = function()
return this.stats;
};
Node.prototype.ping = function()
{
this.emit('node-ping', '');
};
Node.prototype.setWatches = function()
{
var self = this;
@ -370,7 +378,11 @@ Node.prototype.setWatches = function()
this.updateInterval = setInterval(function(){
self.update();
}, 5000);
}, UPDATE_INTERVAL);
this.pingInterval = setInterval(function(){
self.ping();
}, PING_INTERVAL);
}
Node.prototype.emit = function(message, payload)
@ -400,6 +412,9 @@ Node.prototype.stop = function()
if(this.updateInterval)
clearInterval(this.updateInterval);
if(this.pingInterval)
clearInterval(this.pingInterval);
web3.reset();
}