Skip to content

Commit

Permalink
Play Mode Feedback subscribe callback
Browse files Browse the repository at this point in the history
timer saftey
  • Loading branch information
phillipivan committed Jan 15, 2024
1 parent f11d7bb commit f291d71
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/feedbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 1 addition & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand Down
21 changes: 15 additions & 6 deletions src/tcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -46,7 +49,7 @@ module.exports = {
stopCmdQueue() {
this.log('debug', 'stopping cmdTimer')
clearTimeout(this.cmdTimer)
this.cmdTimer = null
delete this.cmdTimer
},

sendCommand(msg) {
Expand Down Expand Up @@ -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)
Expand All @@ -101,7 +107,7 @@ module.exports = {
stopKeepAlive() {
this.log('debug', 'stopping keepAlive')
clearTimeout(this.keepAliveTimer)
this.keepAliveTimer = null
delete this.keepAliveTimer
},

timeOut() {
Expand All @@ -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)
Expand All @@ -124,7 +133,7 @@ module.exports = {
stopTimeOut() {
this.log('debug', 'stopping timeOutTimer')
clearTimeout(this.timeOutTimer)
this.timeOutTimer = null
delete this.timeOutTimer
},

initTCP() {
Expand Down

0 comments on commit f291d71

Please sign in to comment.