Send empty command as keep-alive.

Fixes #36.

Inspired from http://py-ts3.readthedocs.org/en/latest/_modules/ts3/query.html.
develop
Icedream 2016-02-16 18:23:59 +01:00
parent c48ea91682
commit 92c66a6bbc
1 changed files with 17 additions and 0 deletions

View File

@ -140,6 +140,22 @@ module.exports = class TS3ClientQuery extends EventEmitter
else
@emit "vars", response.args
# send keepalives to avoid connection timeout
@_resetKeepalive()
_sendKeepalive: (cb) =>
@_log.silly "Send: <keep-alive>"
@_tcpClient.write "\n\r", "utf8", () => cb?()
_stopKeepalive: () =>
if @_keepaliveInt is not undefined
clearInterval @_keepaliveInt
_resetKeepalive: () =>
@_stopKeepalive()
@_keepaliveInt = setInterval @_sendKeepalive, 60000
close: (cb) =>
if not @_tcpClient
cb?()
@ -165,6 +181,7 @@ module.exports = class TS3ClientQuery extends EventEmitter
@_log.silly "Send:", text.trim()
@_tcpClient.write text, "utf8", () => cb?()
@_resetKeepalive()
banadd: (cb) =>
throw new Error "Not implemented yet"