Merge pull request #170 from cubedro/develop

Latency update
pull/5/head
Marian OANCΞA 10 years ago
commit 57cec43cc3
  1. 16
      app.js
  2. 2
      dist/js/netstats.min.js
  3. 2
      dist/js/netstats.min.js.map
  4. 6
      src/js/controllers.js

@ -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)
@ -264,7 +267,7 @@ client.on('connection', function(clientSpark)
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

@ -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;
}

Loading…
Cancel
Save