mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
commit
cbd3168791
3 changed files with 10 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue