Merge pull request #307 from roblabla/master

Add checkTimeoutInterval
This commit is contained in:
Romain Beaumont 2015-11-19 20:54:45 +01:00
commit cbd3168791
3 changed files with 10 additions and 1 deletions

View file

@ -1,5 +1,9 @@
# History
## 0.16.1 (unreleased)
* add checkTimeoutInterval to createClient
## 0.16.0
* cross version support exposed : version option in createClient and createServer

View file

@ -72,6 +72,7 @@ Returns a `Client` instance and perform login.
* clientToken : generated if a password is given
* accessToken : generated if a password is given
* keepAlive : send keep alive packets : default to true
* checkTimeoutInterval : default to `10*1000` (10s), check if keepalive received at that period, disconnect otherwise.
* version : 1.8 or 1.9 : default to 1.8
## mc.Client(isServer,version)

View file

@ -37,6 +37,7 @@ function createClient(options) {
assert.ok(options.username, "username is required");
var haveCredentials = options.password != null || (clientToken != null && options.session != null);
var keepAlive = options.keepAlive == null ? true : options.keepAlive;
var checkTimeoutInterval = options.checkTimeoutInterval || 10 * 1000;
var optVersion = options.version || require("./version").defaultVersion;
var mcData=require("minecraft-data")(optVersion);
@ -103,8 +104,11 @@ function createClient(options) {
function onCompressionRequest(packet) {
client.compressionThreshold = packet.threshold;
}
var timeout = null;
function onKeepAlive(packet) {
if (timeout)
clearTimeout(timeout);
timeout = setTimeout(() => client.end(), checkTimeoutInterval);
client.write('keep_alive', {
keepAliveId: packet.keepAliveId
});