This commit is contained in:
roblabla 2015-09-14 17:07:25 +00:00
parent a2abb70fc7
commit 8be7394864

View File

@ -14,24 +14,24 @@ function ping(options, cb) {
cb(err); cb(err);
}); });
client.once([states.STATUS, 0x00], function(packet) { client.once('server_info', function(packet) {
var data = JSON.parse(packet.response); var data = JSON.parse(packet.response);
var start = Date.now(); var start = Date.now();
client.once(0x01, function(packet) { client.once('ping', function(packet) {
data.latency = Date.now() - start; data.latency = Date.now() - start;
cb(null, data); cb(null, data);
client.end(); client.end();
}); });
client.write(0x01, {time: [0, 0]}); client.write('ping', {time: [0, 0]});
}); });
client.on('state', function(newState) { client.on('state', function(newState) {
if(newState === states.STATUS) if(newState === states.STATUS)
client.write(0x00, {}); client.write('ping_start', {});
}); });
client.on('connect', function() { client.on('connect', function() {
client.write(0x00, { client.write('set_protocol', {
protocolVersion: 4, protocolVersion: 4,
serverHost: host, serverHost: host,
serverPort: port, serverPort: port,