Skip to content

Commit

Permalink
add: variable support for actions
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaldrummerj committed Jul 5, 2023
1 parent 7822928 commit afcc21d
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,15 @@ class RemoteShow extends InstanceBase<RemoteShowConfig> {
this.socket.destroy()
}

this.updateStatus(InstanceStatus.Connecting)

if (this.config.host) {
this.socket = new TCPHelper(this.config.host, 61001, { reconnect: false })

this.socket.on('status_change', (status, message) => {
this.updateStatus(status, message)
})

this.socket.on('error', (err) => {
this.updateStatus(InstanceStatus.ConnectionFailure, err.message)
this.log('error', `Network error: ${err.message}`)
})

this.socket.on('connect', () => {
if (this.lastState !== InstanceStatus.Ok) {
this.updateStatus(InstanceStatus.Ok)
this.lastState = InstanceStatus.Ok
}

if (typeof cb == 'function') {
cb()
}
Expand Down Expand Up @@ -113,11 +102,13 @@ class RemoteShow extends InstanceBase<RemoteShowConfig> {
this.log('info', 'config changing!')
this.config = config
this.saveConfig(config)
this.updateStatus(InstanceStatus.Connecting)
this.updateActions()
this.updatefeedbacks()
this.updateVariables()
this.updatePresets()
this.initPing()
this.updateStatus(InstanceStatus.Ok)
this.log('info', 'config changed!')
return Promise.resolve()
}
Expand Down Expand Up @@ -148,10 +139,12 @@ class RemoteShow extends InstanceBase<RemoteShowConfig> {
label: 'filename',
id: 'file',
default: '',
useVariables: true,
},
],
callback: async (action) => {
const cmd = 'OPEN ' + '"' + action.options.file + '"'
callback: async (action, context) => {
let fileName = await context.parseVariablesInString((action.options.file as string).trim())
const cmd = 'OPEN ' + '"' + fileName + '"'
await this.sendCommand(cmd)
},
},
Expand All @@ -163,10 +156,12 @@ class RemoteShow extends InstanceBase<RemoteShowConfig> {
label: 'filename',
id: 'file',
default: '',
useVariables: true,
},
],
callback: async (action) => {
const cmd = 'CLOSE ' + '"' + action.options.file + '"'
callback: async (action, context) => {
let fileName = await context.parseVariablesInString((action.options.file as string).trim())
const cmd = 'CLOSE ' + '"' + fileName + '"'
await this.sendCommand(cmd)
},
},
Expand All @@ -178,10 +173,12 @@ class RemoteShow extends InstanceBase<RemoteShowConfig> {
label: 'filename (optional)',
id: 'file',
default: '',
useVariables: true,
},
],
callback: async (action) => {
const cmd = 'RUN ' + '"' + action.options.file + '"'
callback: async (action, context) => {
let fileName = await context.parseVariablesInString((action.options.file as string).trim())
const cmd = 'RUN ' + '"' + fileName + '"'
await this.sendCommand(cmd)
},
},
Expand All @@ -201,10 +198,12 @@ class RemoteShow extends InstanceBase<RemoteShowConfig> {
label: 'filename (optional)',
id: 'file',
default: '',
useVariables: true,
},
],
callback: async (action) => {
const cmd = 'STOP ' + '"' + action.options.file + '"'
callback: async (action, context) => {
let fileName = await context.parseVariablesInString((action.options.file as string).trim())
const cmd = 'STOP ' + '"' + fileName + '"'
await this.sendCommand(cmd)
},
},
Expand All @@ -228,16 +227,16 @@ class RemoteShow extends InstanceBase<RemoteShowConfig> {
name: 'Goto Slide',
options: [
{
type: 'number',
type: 'textinput',
label: 'slide nr',
id: 'slide',
default: 1,
min: 1,
max: 999,
default: '',
useVariables: true,
},
],
callback: async (action) => {
const cmd = 'GO ' + action.options.slide
callback: async (action, context) => {
let slideNumber = Number(await context.parseVariablesInString((action.options.slide as string).trim()))
const cmd = 'GO ' + slideNumber
await this.sendCommand(cmd)
},
},
Expand All @@ -249,10 +248,19 @@ class RemoteShow extends InstanceBase<RemoteShowConfig> {
label: 'section name',
id: 'section',
default: '',
useVariables: true,
},
],
callback: async (action) => {
const cmd = 'GO ' + action.options.section
callback: async (action, context) => {
let sectionName = await context.parseVariablesInString((action.options.section as string).trim())
if (sectionName.startsWith('"') === false) {
sectionName = `"${sectionName}`
}

if (sectionName.endsWith('"') === false) {
sectionName += '"'
}
const cmd = 'GO ' + sectionName
await this.sendCommand(cmd)
},
},
Expand Down

0 comments on commit afcc21d

Please sign in to comment.