Merge pull request #170 from cubedro/develop

Latency update
This commit is contained in:
Marian OANCΞA 2015-06-02 04:38:10 +03:00
commit 57cec43cc3
4 changed files with 21 additions and 11 deletions

16
app.js
View File

@ -211,7 +211,10 @@ api.on('connection', function(spark) {
spark.on('node-ping', function(data) spark.on('node-ping', function(data)
{ {
spark.emit('node-pong'); spark.emit('node-pong', {
clientTime: data.clientTime,
serverTime: _.now()
});
}); });
spark.on('latency', function(data) spark.on('latency', function(data)
@ -264,7 +267,7 @@ client.on('connection', function(clientSpark)
clientSpark.on('client-pong', function (data) clientSpark.on('client-pong', function (data)
{ {
var latency = Math.ceil( (_.now() - clientLatency) / 2 ); var latency = Math.ceil( (_.now() - data.serverTime) / 2 );
clientSpark.emit('client-latency', { latency: latency }); clientSpark.emit('client-latency', { latency: latency });
}); });
@ -272,9 +275,12 @@ client.on('connection', function(clientSpark)
var latencyTimeout = setInterval( function () var latencyTimeout = setInterval( function ()
{ {
clientLatency = _.now(); client.write({
action: 'client-ping',
client.write({ action: 'client-ping' }); data: {
serverTime: _.now()
}
});
}, 5000); }, 5000);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -150,6 +150,7 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
break; break;
// TODO: Remove when everybody updates api client to 0.0.12
case "update": case "update":
var index = findIndex({id: data.id}); var index = findIndex({id: data.id});
@ -332,7 +333,10 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
break; break;
case "client-ping": case "client-ping":
socket.emit('client-pong'); socket.emit('client-pong', {
serverTime: data.serverTime,
clientTime: _.now()
});
break; break;
} }