diff --git a/lib/node.js b/lib/node.js index 849c397..cea4b4c 100644 --- a/lib/node.js +++ b/lib/node.js @@ -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(); }