From 92c66a6bbc07f5aa9d0d467458305bd657ca0b8f Mon Sep 17 00:00:00 2001 From: Carl Kittelberger Date: Tue, 16 Feb 2016 18:23:59 +0100 Subject: [PATCH] Send empty command as keep-alive. Fixes #36. Inspired from http://py-ts3.readthedocs.org/en/latest/_modules/ts3/query.html. --- ts3query.iced | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ts3query.iced b/ts3query.iced index 4ff1230..56e1da6 100644 --- a/ts3query.iced +++ b/ts3query.iced @@ -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: " + + @_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"