Skip to content

Commit 5583114

Browse files
authored
Merge pull request #15 from phillipivan/main
v1.1.4
2 parents 5b244b4 + 5f51078 commit 5583114

File tree

6 files changed

+178
-195
lines changed

6 files changed

+178
-195
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ package-lock.json
88
*.log
99
*.npa
1010
*.bak
11-
DEBUG-*
11+
DEBUG-*
12+
peavy-ratc-*.tgz

Diff for: companion/HELP.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ The Action Recorder will translate any recieved numeric valueIs messages into Co
4949

5050
## Version History
5151

52-
### Version 1.1.2
52+
### Version 1.1.4
53+
54+
- Better sanitising of variable Ids
55+
56+
### Version 1.1.3
5357

5458
- Parse local variables
5559

Diff for: package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "peavy-ratc",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"main": "src/main.js",
55
"type": "module",
66
"scripts": {
@@ -19,13 +19,13 @@
1919
"@companion-module/base": "~1.11.3"
2020
},
2121
"devDependencies": {
22-
"@companion-module/tools": "^2.1.1",
23-
"eslint": "^9.21.0",
22+
"@companion-module/tools": "^2.2.3",
23+
"eslint": "^9.24.0",
2424
"prettier": "^3.5.3"
2525
},
2626
"engines": {
2727
"node": "^22.13"
2828
},
2929
"prettier": "@companion-module/tools/.prettierrc.json",
30-
"packageManager": "yarn@4.7.0"
30+
"packageManager": "yarn@4.8.1"
3131
}

Diff for: src/processcmd.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { resp, cmd, alert, aliasSep, paramSep, rawAliasIdent } from './consts.js'
22
import { InstanceStatus } from '@companion-module/base'
33

4+
/**
5+
* Remove illegal characters from variable Ids
6+
* @param {string} id variable id to sanitize
7+
* @param {'' | '.' | '-' | '_'} substitute Char to replace illegal characters
8+
* @since 1.1.4
9+
*/
10+
11+
const sanitiseVariableId = (id, substitute = '_') => id.replaceAll(/[^a-zA-Z0-9-_.]/gm, substitute)
12+
413
export function actionUpdate() {
514
if (this.actionTimer) {
615
clearTimeout(this.actionTimer)
@@ -45,7 +54,7 @@ export async function processCmd(chunk) {
4554
return true
4655
}
4756
}
48-
let newAlias = alias[1].replaceAll(/\/| /g, '_')
57+
let newAlias = sanitiseVariableId(alias[1])
4958
this.controlAliases.push({ id: alias[1], label: alias[1] })
5059
this.varList.push(
5160
{ variableId: `controlAliasName_${newAlias}`, name: `Control Alias Name ${newAlias}` },
@@ -80,14 +89,14 @@ export async function processCmd(chunk) {
8089
}
8190
switch (params[0]) {
8291
case resp.ratcV1.username:
83-
//this.sendCommand(this.config.username) - doing this will get stuck in a loop if user/pass is incorrect.
92+
//await this.sendCommand(this.config.username) - doing this will get stuck in a loop if user/pass is incorrect.
8493
if (this.config.v2) {
8594
this.updateStatus(InstanceStatus.BadConfig, 'Device in RATCv1 mode')
8695
this.log('error', `Device in RATCv1 mode`)
8796
}
8897
break
8998
case resp.ratcV1.password:
90-
//this.sendCommand(this.config.password)
99+
//await this.sendCommand(this.config.password)
91100
break
92101
case resp.ratcV1.ratcVersion:
93102
this.log('info', `${reply}`)
@@ -134,7 +143,7 @@ export async function processCmd(chunk) {
134143
)
135144
}
136145
}
137-
aliases[1] = aliases[1].replaceAll(/\/| /g, '_')
146+
aliases[1] = sanitiseVariableId(aliases[1])
138147
this.log('debug', `control data for alias: ${aliases[1]} value: ${valPos[0]} position: ${valPos[1]}`)
139148
aliasValues[`controlAliasValue_${aliases[1]}`] = valPos[0]
140149
if (this.config.v2) {
@@ -181,7 +190,7 @@ export async function processCmd(chunk) {
181190
this.log('debug', `${reply}`)
182191
this.log('debug', `params: ${params.toString()}`)
183192
if (params[1] == resp.ratcV1.aliasControlGroupList) {
184-
alias[0] = alias[1].replaceAll(/\/| /g, '_')
193+
alias[0] = sanitiseVariableId(alias[1])
185194
this.controlAliases.push({ id: alias[1], label: alias[1] })
186195
this.varList.push(
187196
{ variableId: `controlAliasName_${alias[0]}`, name: `Control Alias Name ${alias[0]}` },
@@ -291,7 +300,7 @@ export async function processCmd(chunk) {
291300
case resp.ratcV2.notLoggedIn:
292301
this.log('error', `${reply}`)
293302
this.updateStatus(InstanceStatus.BadConfig, `${reply}`)
294-
this.sendCommand(cmd.ratcV2.logIn + paramSep + this.config.username + paramSep + this.config.password)
303+
await this.sendCommand(cmd.ratcV2.logIn + paramSep + this.config.username + paramSep + this.config.password)
295304
break
296305
case resp.ratcV2.loginFailed:
297306
this.log('error', 'Username / Password is incorrect')

Diff for: src/tcp.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ export function stopCmdQueue() {
4848
}
4949
}
5050

51-
export function sendCommand(msg) {
51+
export async function sendCommand(msg) {
5252
if (msg !== undefined) {
5353
if (this.socket !== undefined && this.socket.isConnected) {
5454
//this.log('debug', `Sending Command: ${msg}`)
55-
this.socket.send(msg + EOM)
56-
return true
55+
return await this.socket.send(msg + EOM)
5756
} else {
5857
this.log('warn', `Socket not connected, tried to send: ${msg}`)
5958
}
@@ -64,23 +63,23 @@ export function sendCommand(msg) {
6463
}
6564

6665
//queries made on initial connection.
67-
export function queryOnConnect() {
66+
export async function queryOnConnect() {
6867
if (this.config.v2) {
6968
let msg =
7069
this.config.username === ''
7170
? ''
7271
: this.config.password === ''
7372
? paramSep + this.config.username
7473
: paramSep + this.config.username + paramSep + this.config.password
75-
this.sendCommand(cmd.ratcV2.logIn + msg)
74+
await this.sendCommand(cmd.ratcV2.logIn + msg)
7675
this.addCmdtoQueue(cmd.ratcV2.statusGet)
7776
this.addCmdtoQueue(cmd.ratcV2.keepAlive + paramSep + keepAliveValue)
7877
this.addCmdtoQueue(cmd.ratcV2.quietModeDisable)
7978
this.addCmdtoQueue(cmd.ratcV2.controlList)
8079
this.addCmdtoQueue(cmd.ratcV2.changeGroupSchedule + paramSep + groupSubscribeInterval)
8180
} else {
82-
this.sendCommand(this.config.username)
83-
this.sendCommand(this.config.password)
81+
await this.sendCommand(this.config.username)
82+
await this.sendCommand(this.config.password)
8483
}
8584
}
8685

@@ -174,11 +173,11 @@ export function initTCP() {
174173
this.startTimeOut()
175174
this.stopActionUpdateTimer()
176175
})
177-
this.socket.on('connect', () => {
176+
this.socket.on('connect', async () => {
178177
this.log('info', `Connected to ${this.config.host}:${this.config.port}`)
179178
this.updateStatus(InstanceStatus.Connecting, `Logging In`)
180179
this.receiveBuffer = ''
181-
this.queryOnConnect()
180+
await this.queryOnConnect()
182181
})
183182
this.socket.on('data', (chunk) => {
184183
let i = 0,

0 commit comments

Comments
 (0)