|
|
|
@ -267,6 +267,7 @@ client.on('connection', function (clientSpark) |
|
|
|
|
|
|
|
|
|
clientSpark.on('client-pong', function (data) |
|
|
|
|
{ |
|
|
|
|
var start = (!_.isUndefined(data) && !_.isUndefined(data.serverTime) ? data.serverTime : clientLatency) |
|
|
|
|
var latency = Math.ceil( (_.now() - data.serverTime) / 2 ); |
|
|
|
|
|
|
|
|
|
clientSpark.emit('client-latency', { latency: latency }); |
|
|
|
@ -275,10 +276,12 @@ client.on('connection', function (clientSpark) |
|
|
|
|
|
|
|
|
|
var latencyTimeout = setInterval( function () |
|
|
|
|
{ |
|
|
|
|
clientLatency = _.now(); |
|
|
|
|
|
|
|
|
|
client.write({ |
|
|
|
|
action: 'client-ping', |
|
|
|
|
data: { |
|
|
|
|
serverTime: _.now() |
|
|
|
|
serverTime: clientLatency |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, 5000); |
|
|
|
|