Merge pull request #170 from cubedro/develop

Latency update
pull/5/head
Marian OANCΞA 10 years ago
commit 57cec43cc3
  1. 22
      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.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)
@ -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() }); 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 }); 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

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

Loading…
Cancel
Save