fixed client latency
This commit is contained in:
parent
69a619804d
commit
b9a9321cac
5
app.js
5
app.js
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user