refactored client ping-pong
This commit is contained in:
parent
da45dfbdf9
commit
69a619804d
17
app.js
17
app.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);
|
||||
|
||||
|
||||
|
2
dist/js/netstats.min.js
vendored
2
dist/js/netstats.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/js/netstats.min.js.map
vendored
2
dist/js/netstats.min.js.map
vendored
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…
Reference in New Issue
Block a user