From 61e2db4e33d3a5ba108b20e49dad91aae9ffa662 Mon Sep 17 00:00:00 2001 From: cubedro Date: Thu, 2 Apr 2015 18:22:33 +0300 Subject: [PATCH 1/2] added ping --- lib/node.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/node.js b/lib/node.js index 849c397..a4c4051 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('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(); } From a8fb34ea1485f1c7c059d5db1c239aca6ba2f2dd Mon Sep 17 00:00:00 2001 From: cubedro Date: Thu, 2 Apr 2015 18:23:14 +0300 Subject: [PATCH 2/2] fixed ping conflict --- lib/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node.js b/lib/node.js index a4c4051..cea4b4c 100644 --- a/lib/node.js +++ b/lib/node.js @@ -359,7 +359,7 @@ Node.prototype.update = function() Node.prototype.ping = function() { - this.emit('ping', ''); + this.emit('node-ping', ''); }; Node.prototype.setWatches = function()