fixed api latency bug

This commit is contained in:
cubedro 2015-06-02 04:53:26 +03:00
parent b9a9321cac
commit 11cc9897fb

6
app.js
View File

@ -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,7 +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 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 });