refactored client ping-pong

pull/5/head
cubedro 10 years ago
parent da45dfbdf9
commit 69a619804d
  1. 17
      app.js
  2. 2
      dist/js/netstats.min.js
  3. 2
      dist/js/netstats.min.js.map
  4. 5
      src/js/controllers.js

@ -253,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() });
@ -265,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 });
});
@ -275,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

@ -333,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