commit
904c34388c
9
app.js
9
app.js
@ -211,8 +211,10 @@ api.on('connection', function(spark) {
|
|||||||
|
|
||||||
spark.on('node-ping', function(data)
|
spark.on('node-ping', function(data)
|
||||||
{
|
{
|
||||||
|
var start = (!_.isUndefined(data) && !_.isUndefined(data.clientTime) ? data.clientTime : null);
|
||||||
|
|
||||||
spark.emit('node-pong', {
|
spark.emit('node-pong', {
|
||||||
clientTime: data.clientTime,
|
clientTime: start,
|
||||||
serverTime: _.now()
|
serverTime: _.now()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -267,6 +269,7 @@ client.on('connection', function (clientSpark)
|
|||||||
|
|
||||||
clientSpark.on('client-pong', function (data)
|
clientSpark.on('client-pong', function (data)
|
||||||
{
|
{
|
||||||
|
var start = (!_.isUndefined(data) && !_.isUndefined(data.serverTime) ? data.serverTime : clientLatency);
|
||||||
var latency = Math.ceil( (_.now() - data.serverTime) / 2 );
|
var latency = Math.ceil( (_.now() - data.serverTime) / 2 );
|
||||||
|
|
||||||
clientSpark.emit('client-latency', { latency: latency });
|
clientSpark.emit('client-latency', { latency: latency });
|
||||||
@ -275,10 +278,12 @@ client.on('connection', function (clientSpark)
|
|||||||
|
|
||||||
var latencyTimeout = setInterval( function ()
|
var latencyTimeout = setInterval( function ()
|
||||||
{
|
{
|
||||||
|
clientLatency = _.now();
|
||||||
|
|
||||||
client.write({
|
client.write({
|
||||||
action: 'client-ping',
|
action: 'client-ping',
|
||||||
data: {
|
data: {
|
||||||
serverTime: _.now()
|
serverTime: clientLatency
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
Loading…
Reference in New Issue
Block a user