Merge pull request #38 from cubedro/develop

Added latency update
This commit is contained in:
Marian OANCΞA 2015-04-03 07:01:46 +03:00
commit 5a2f310d90
1 changed files with 7 additions and 1 deletions

View File

@ -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,7 +369,8 @@ Node.prototype.update = function()
Node.prototype.ping = function()
{
this.emit('node-ping', '');
this._latency = (new Date()).getTime();
this.emit('node-ping', { id: this.id });
};
Node.prototype.setWatches = function()