-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.js
271 lines (251 loc) · 8.74 KB
/
actions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
const CRLF = '\r\n'
// Sends data over TCP. Ensures that a host is configured and that the TCP socket is connected.
function sendData(self, sendBuf) {
if (!self.config.host) {
self.log('error', 'Host configuration is missing.')
return
}
self.log('debug', `Sending to ${self.config.host}:${self.config.port} -> ${sendBuf.toString()}`)
if (self.config.prot === 'tcp') {
if (self.socket?.isConnected) {
self.socket.send(sendBuf)
} else {
self.log('error', 'TCP socket not connected.')
}
} else {
self.log('error', 'Unknown protocol')
}
}
// Helper: Ensures that the composition ID is in the format "compX".
// Returns "comp1" when "1" is entered.
function parseCompositionID(input) {
input = input || '' // fallback to empty string if undefined
if (input.toLowerCase().startsWith("comp")) {
return input
}
return "comp" + input
}
// Shared callback logic: Sends the command and automatically requests the current composition status.
async function handleCallback(self, options, commandPrefix) {
try {
// Ensure transformation of the composition_id:
const compID = parseCompositionID(options.composition_id)
const variableValue = options.variable_value ? await self.parseVariablesInString(options.variable_value) : ''
const fullCommand = `${commandPrefix}${compID}${variableValue ? ',' + variableValue : ''}`
const sendBuf = Buffer.from(fullCommand + CRLF, 'latin1')
sendData(self, sendBuf)
// Automatically request composition status
getCompositionStatus(self, compID)
} catch (error) {
self.log('error', `Error in callback: ${error.message}`)
}
}
// Requests the status of a composition.
function getCompositionStatus(self, composition) {
const statusCommand = `get:status,${composition}`
const statusBuf = Buffer.from(statusCommand + CRLF, 'latin1')
self.statusRequestQueue.push(composition)
sendData(self, statusBuf)
}
// Requests the current volume status of a composition.
function getVolumeStatus(self, composition) {
const volumeCommand = `get:vol,${composition}`
const volumeBuf = Buffer.from(volumeCommand + CRLF, 'latin1')
self.volumeRequestQueue.push(composition)
sendData(self, volumeBuf)
}
// Exports the action definitions for the module.
export function getActionDefinitions(self) {
return {
transportmode: {
name: 'Transport Mode',
options: [
{
type: 'dropdown',
id: 'command',
label: 'Command:',
default: 'play',
choices: [
{ id: 'play', label: 'Play' },
{ id: 'pause', label: 'Pause' },
{ id: 'stop', label: 'Stop' },
],
},
{
type: 'textinput',
id: 'composition_id',
label: 'Choose composition ID',
default: 'comp1',
tooltip: 'Enter the composition ID manually. E.g. "1" or "comp1".',
},
],
callback: async (action) => {
// Ensure transformation of the input ID:
const compID = parseCompositionID(action.options.composition_id)
action.options.composition_id = compID
await handleCallback(self, action.options, action.options.command + ',')
getCompositionStatus(self, compID)
},
},
go_to_cue: {
name: 'Go to Cue',
options: [
{
type: 'textinput',
id: 'composition_id',
label: 'Choose composition ID',
default: 'comp1',
tooltip: 'Enter the composition ID manually. E.g. "1" or "comp1".',
},
{
type: 'textinput',
id: 'cue_number',
label: 'Cue Number:',
default: '',
tooltip: 'Enter the cue number to jump to.',
useVariables: true,
},
],
callback: async (action) => {
const compID = parseCompositionID(action.options.composition_id)
action.options.composition_id = compID
action.options.variable_value = action.options.cue_number
await handleCallback(self, action.options, 'set:cue,')
// Update the cue_index for this composition (go_to_cue action)
self.compositionStatuses[compID] = self.compositionStatuses[compID] || {}
self.compositionStatuses[compID].cue_index = action.options.variable_value
self.updateCompositionVariables(compID)
getCompositionStatus(self, compID)
},
},
play_cuelist_clip: {
name: 'Play Cuelist Clip',
options: [
{
type: 'textinput',
id: 'composition_id',
label: 'Choose composition ID',
default: 'comp1',
tooltip: 'Enter the composition ID manually. E.g. "1" or "comp1".',
},
{
type: 'textinput',
id: 'clip_number',
label: 'Clip Number:',
default: '',
tooltip: 'Enter the clip number to play.',
useVariables: true,
},
],
callback: async (action) => {
const compID = parseCompositionID(action.options.composition_id)
action.options.composition_id = compID
action.options.variable_value = action.options.clip_number
await handleCallback(self, action.options, 'set:cue,')
// Set the new clip_index variable for this composition (play_cuelist_clip action)
self.compositionStatuses[compID] = self.compositionStatuses[compID] || {}
self.compositionStatuses[compID].clip_index = action.options.variable_value
self.updateCompositionVariables(compID)
getCompositionStatus(self, compID)
},
},
volume: {
name: 'Set Volume',
options: [
{
type: 'textinput',
id: 'composition_id',
label: 'Choose composition ID',
default: 'comp1',
tooltip: 'Enter the composition ID manually. E.g. "1" or "comp1".',
},
{
type: 'number',
id: 'volume_value',
label: 'Volume (0-100):',
default: 50,
min: 0,
max: 100,
step: 1,
tooltip: 'Enter the desired volume level.',
},
],
callback: async (action) => {
const compID = parseCompositionID(action.options.composition_id)
action.options.composition_id = compID
action.options.variable_value = action.options.volume_value
await handleCallback(self, action.options, 'set:vol,')
getVolumeStatus(self, compID)
},
},
volume_adjust: {
name: 'Volume Adjust +/-',
options: [
{
type: 'textinput',
id: 'composition_id',
label: 'Choose composition ID',
default: 'comp1',
tooltip: 'Enter the composition ID manually. E.g. "1" or "comp1".',
},
{
type: 'dropdown',
id: 'adjustment',
label: 'Adjust Volume:',
default: '+',
choices: [
{ id: '+', label: 'Increase (+10%)' },
{ id: '-', label: 'Decrease (-10%)' },
],
},
],
callback: async (action) => {
try {
const compID = parseCompositionID(action.options.composition_id)
action.options.composition_id = compID
const { adjustment } = action.options
self.volumeState = self.volumeState || {}
self.volumeState[compID] = self.volumeState[compID] ?? 50
if (adjustment === '+') {
self.volumeState[compID] = Math.min(self.volumeState[compID] + 10, 100)
} else if (adjustment === '-') {
self.volumeState[compID] = Math.max(self.volumeState[compID] - 10, 0)
}
const fullCommand = `set:vol,${compID},${self.volumeState[compID]}`
const sendBuf = Buffer.from(fullCommand + CRLF, 'latin1')
sendData(self, sendBuf)
getVolumeStatus(self, compID)
} catch (error) {
self.log('error', `Error in volume_adjust callback: ${error.message}`)
}
},
},
jump_to_time: {
name: 'Jump to Time',
options: [
{
type: 'textinput',
id: 'composition_id',
label: 'Choose composition ID',
default: 'comp1',
tooltip: 'Enter the composition ID manually. E.g. "1" or "comp1".',
},
{
type: 'textinput',
id: 'time_in_seconds',
label: 'Time in Seconds:',
default: '',
tooltip: 'Enter the time (in seconds) to jump to.',
useVariables: true,
},
],
callback: async (action) => {
const compID = parseCompositionID(action.options.composition_id)
action.options.composition_id = compID
action.options.variable_value = action.options.time_in_seconds
await handleCallback(self, action.options, 'set:cuetime,')
getCompositionStatus(self, compID)
},
},
}
}