From f291d71545cd81201144e93df6008020bd05e12c Mon Sep 17 00:00:00 2001 From: Phillip Pietruschka Date: Mon, 15 Jan 2024 13:46:27 +1100 Subject: [PATCH] Play Mode Feedback subscribe callback timer saftey --- src/feedbacks.js | 3 +++ src/main.js | 5 +---- src/tcp.js | 21 +++++++++++++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/feedbacks.js b/src/feedbacks.js index 5586947..e512e07 100644 --- a/src/feedbacks.js +++ b/src/feedbacks.js @@ -95,6 +95,9 @@ module.exports = async function (self) { callback: ({ options }) => { return options.status == self.recorder.playMode }, + subscribe: () => { + self.addCmdtoQueue(SOM + cmd.playModeSense) + }, }, mechaStatus: { name: 'Mecha Status', diff --git a/src/main.js b/src/main.js index 3f24589..d9b389c 100644 --- a/src/main.js +++ b/src/main.js @@ -13,9 +13,6 @@ class TASCAM_SS_CDR250N extends InstanceBase { constructor(internal) { super(internal) Object.assign(this, { ...config, ...tcp, ...processCmd, ...choices }) - this.keepAliveTimer = {} - this.cmdTimer = {} - this.timeOutTimer = {} this.cmdQueue = [] } async init(config) { @@ -32,13 +29,13 @@ class TASCAM_SS_CDR250N extends InstanceBase { // When module gets deleted async destroy() { this.log('debug', `destroy. ID: ${this.id}`) - clearTimeout(this.keepAliveTimer) this.stopCmdQueue() this.stopTimeOut() this.stopKeepAlive() if (this.socket) { this.sendCommand(EndSession) this.socket.destroy() + delete this.socket } this.updateStatus(InstanceStatus.Disconnected) } diff --git a/src/tcp.js b/src/tcp.js index 6b8a471..c076900 100644 --- a/src/tcp.js +++ b/src/tcp.js @@ -37,7 +37,10 @@ module.exports = { startCmdQueue() { this.log('debug', 'starting cmdTimer') - clearTimeout(this.cmdTimer) + if (this.cmdTimer) { + clearTimeout(this.cmdTimer) + delete this.cmdTimer + } this.cmdTimer = setTimeout(() => { this.processCmdQueue() }, msgDelay) @@ -46,7 +49,7 @@ module.exports = { stopCmdQueue() { this.log('debug', 'stopping cmdTimer') clearTimeout(this.cmdTimer) - this.cmdTimer = null + delete this.cmdTimer }, sendCommand(msg) { @@ -92,7 +95,10 @@ module.exports = { startKeepAlive() { this.log('debug', 'starting keepAlive') - clearTimeout(this.keepAliveTimer) + if (this.keepAliveTimer) { + clearTimeout(this.keepAliveTimer) + delete this.keepAliveTimer + } this.keepAliveTimer = setTimeout(() => { this.keepAlive() }, keepAliveInterval) @@ -101,7 +107,7 @@ module.exports = { stopKeepAlive() { this.log('debug', 'stopping keepAlive') clearTimeout(this.keepAliveTimer) - this.keepAliveTimer = null + delete this.keepAliveTimer }, timeOut() { @@ -115,7 +121,10 @@ module.exports = { startTimeOut() { this.log('debug', 'starting timeOutTimer') - clearTimeout(this.timeOutTimer) + if (this.timeOutTimer) { + clearTimeout(this.timeOutTimer) + delete this.timeOutTimer + } this.timeOutTimer = setTimeout(() => { this.timeOut() }, timeOutInterval) @@ -124,7 +133,7 @@ module.exports = { stopTimeOut() { this.log('debug', 'stopping timeOutTimer') clearTimeout(this.timeOutTimer) - this.timeOutTimer = null + delete this.timeOutTimer }, initTCP() {