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

22
app.js
View File

@ -211,7 +211,10 @@ api.on('connection', function(spark) {
spark.on('node-ping', function(data)
{
spark.emit('node-pong');
spark.emit('node-pong', {
clientTime: data.clientTime,
serverTime: _.now()
});
});
spark.on('latency', function(data)
@ -250,9 +253,9 @@ api.on('connection', function(spark) {
});
});
client.on('connection', function(clientSpark)
client.on('connection', function (clientSpark)
{
clientSpark.on('ready', function(data)
clientSpark.on('ready', function (data)
{
clientSpark.emit('init', { nodes: Nodes.all() });
@ -262,9 +265,9 @@ 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 });
});
@ -272,9 +275,12 @@ client.on('connection', function(clientSpark)
var latencyTimeout = setInterval( function ()
{
clientLatency = _.now();
client.write({ action: 'client-ping' });
client.write({
action: 'client-ping',
data: {
serverTime: _.now()
}
});
}, 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;
// TODO: Remove when everybody updates api client to 0.0.12
case "update":
var index = findIndex({id: data.id});
@ -332,7 +333,10 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
break;
case "client-ping":
socket.emit('client-pong');
socket.emit('client-pong', {
serverTime: data.serverTime,
clientTime: _.now()
});
break;
}