From 2ce486db284bf08d55b012052f389ccc4a178d8c Mon Sep 17 00:00:00 2001 From: cubedro Date: Fri, 3 Apr 2015 07:00:26 +0300 Subject: [PATCH] added latency update --- lib/node.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/node.js b/lib/node.js index ddeb5a7..88be379 100644 --- a/lib/node.js +++ b/lib/node.js @@ -82,6 +82,7 @@ function Node() this._tries = 0; this._down = 0; this._lastSent = 0; + this._latency = 0; this.blocks = []; @@ -106,6 +107,10 @@ function Node() .on('reconnecting', function reconnecting(opts) { console.warn('We are scheduling a reconnect operation', opts); }) + .on('node-pong', function(data) { + var latency = (new Date()).getTime() - self._latency; + socket.emit('latency', { id: self.id, latency: latency }); + }) .on('data', function incoming(data) { console.info('Received some data', data); }); @@ -364,6 +369,7 @@ Node.prototype.update = function() Node.prototype.ping = function() { + this._latency = (new Date()).getTime(); this.emit('node-ping', { id: this.id }); };