|
|
@ -267,6 +267,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 +276,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); |
|
|
|