fixed client latency

This commit is contained in:
cubedro 2015-06-02 04:49:34 +03:00
parent 69a619804d
commit b9a9321cac

5
app.js
View File

@ -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);