@companion-module/base 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/entrypoint.d.ts +2 -2
- package/dist/entrypoint.d.ts.map +1 -1
- package/dist/entrypoint.js +79 -78
- package/dist/entrypoint.js.map +1 -1
- package/dist/helpers/telnet.d.ts.map +1 -1
- package/dist/helpers/telnet.js +2 -2
- package/dist/helpers/telnet.js.map +1 -1
- package/dist/helpers/udp.d.ts.map +1 -1
- package/dist/helpers/udp.js +6 -8
- package/dist/helpers/udp.js.map +1 -1
- package/dist/host-api/api.d.ts +17 -9
- package/dist/host-api/api.d.ts.map +1 -1
- package/dist/host-api/ipc-wrapper.d.ts.map +1 -1
- package/dist/host-api/ipc-wrapper.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/internal/actions.d.ts +17 -0
- package/dist/internal/actions.d.ts.map +1 -0
- package/dist/internal/actions.js +213 -0
- package/dist/internal/actions.js.map +1 -0
- package/dist/internal/base.d.ts +1 -1
- package/dist/internal/base.d.ts.map +1 -1
- package/dist/internal/feedback.d.ts +22 -4
- package/dist/internal/feedback.d.ts.map +1 -1
- package/dist/internal/feedback.js +361 -18
- package/dist/internal/feedback.js.map +1 -1
- package/dist/internal/upgrade.d.ts +5 -12
- package/dist/internal/upgrade.d.ts.map +1 -1
- package/dist/internal/upgrade.js +3 -2
- package/dist/internal/upgrade.js.map +1 -1
- package/dist/module-api/action.d.ts +10 -5
- package/dist/module-api/action.d.ts.map +1 -1
- package/dist/module-api/base.d.ts +18 -27
- package/dist/module-api/base.d.ts.map +1 -1
- package/dist/module-api/base.js +75 -342
- package/dist/module-api/base.js.map +1 -1
- package/dist/module-api/common.d.ts +13 -0
- package/dist/module-api/common.d.ts.map +1 -0
- package/dist/module-api/common.js +3 -0
- package/dist/module-api/common.js.map +1 -0
- package/dist/module-api/config.d.ts +1 -1
- package/dist/module-api/config.d.ts.map +1 -1
- package/dist/module-api/enums.d.ts.map +1 -1
- package/dist/module-api/enums.js +1 -0
- package/dist/module-api/enums.js.map +1 -1
- package/dist/module-api/feedback.d.ts +13 -8
- package/dist/module-api/feedback.d.ts.map +1 -1
- package/dist/module-api/index.d.ts +11 -11
- package/dist/module-api/index.d.ts.map +1 -1
- package/dist/module-api/index.js +11 -11
- package/dist/module-api/index.js.map +1 -1
- package/dist/module-api/preset.d.ts +3 -3
- package/dist/module-api/preset.d.ts.map +1 -1
- package/dist/module-api/upgrade.d.ts +2 -2
- package/dist/module-api/upgrade.d.ts.map +1 -1
- package/dist/util.d.ts +0 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +1 -13
- package/dist/util.js.map +1 -1
- package/package.json +10 -2
package/dist/module-api/base.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InstanceBase = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const util_1 = require("../util");
|
|
6
6
|
const p_queue_1 = tslib_1.__importDefault(require("p-queue"));
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
7
|
+
const base_1 = require("../internal/base");
|
|
8
|
+
const upgrade_1 = require("../internal/upgrade");
|
|
9
|
+
const feedback_1 = require("../internal/feedback");
|
|
10
|
+
const ipc_wrapper_1 = require("../host-api/ipc-wrapper");
|
|
11
|
+
const actions_1 = require("../internal/actions");
|
|
11
12
|
class InstanceBase {
|
|
12
13
|
#ipcWrapper;
|
|
13
14
|
#upgradeScripts;
|
|
@@ -15,11 +16,9 @@ class InstanceBase {
|
|
|
15
16
|
#lifecycleQueue = new p_queue_1.default({ concurrency: 1 });
|
|
16
17
|
#initialized = false;
|
|
17
18
|
#recordingActions = false;
|
|
18
|
-
#
|
|
19
|
-
#
|
|
19
|
+
#actionManager;
|
|
20
|
+
#feedbackManager;
|
|
20
21
|
#variableDefinitions = new Map();
|
|
21
|
-
#feedbackInstances = new Map();
|
|
22
|
-
#actionInstances = new Map();
|
|
23
22
|
#variableValues = new Map();
|
|
24
23
|
#options;
|
|
25
24
|
get instanceOptions() {
|
|
@@ -29,12 +28,12 @@ class InstanceBase {
|
|
|
29
28
|
* Create an instance of the module
|
|
30
29
|
*/
|
|
31
30
|
constructor(internal) {
|
|
32
|
-
if (!(0,
|
|
31
|
+
if (!(0, base_1.isInstanceBaseProps)(internal) || !internal._isInstanceBaseProps)
|
|
33
32
|
throw new Error(`Module instance is being constructed incorrectly. Make sure you aren't trying to do this manually`);
|
|
34
33
|
this.#options = {
|
|
35
34
|
disableVariableValidation: false,
|
|
36
35
|
};
|
|
37
|
-
this.#ipcWrapper = new
|
|
36
|
+
this.#ipcWrapper = new ipc_wrapper_1.IpcWrapper({
|
|
38
37
|
init: this._handleInit.bind(this),
|
|
39
38
|
destroy: this._handleDestroy.bind(this),
|
|
40
39
|
updateConfig: this._handleConfigUpdate.bind(this),
|
|
@@ -46,12 +45,15 @@ class InstanceBase {
|
|
|
46
45
|
learnAction: this._handleLearnAction.bind(this),
|
|
47
46
|
learnFeedback: this._handleLearnFeedback.bind(this),
|
|
48
47
|
startStopRecordActions: this._handleStartStopRecordActions.bind(this),
|
|
48
|
+
variablesChanged: this._handleVariablesChanged.bind(this),
|
|
49
49
|
}, (msg) => {
|
|
50
50
|
process.send(msg);
|
|
51
51
|
}, 5000);
|
|
52
52
|
process.on('message', (msg) => {
|
|
53
53
|
this.#ipcWrapper.receivedMessage(msg);
|
|
54
54
|
});
|
|
55
|
+
this.#actionManager = new actions_1.ActionManager(async (msg) => this.#ipcWrapper.sendWithCb('parseVariablesInString', msg), (msg) => this.#ipcWrapper.sendWithNoCb('setActionDefinitions', msg), this.log.bind(this));
|
|
56
|
+
this.#feedbackManager = new feedback_1.FeedbackManager(async (msg) => this.#ipcWrapper.sendWithCb('parseVariablesInString', msg), (msg) => this.#ipcWrapper.sendWithNoCb('updateFeedbackValues', msg), (msg) => this.#ipcWrapper.sendWithNoCb('setFeedbackDefinitions', msg), this.log.bind(this));
|
|
55
57
|
this.#upgradeScripts = internal.upgradeScripts;
|
|
56
58
|
this.id = internal.id;
|
|
57
59
|
this.log('debug', 'Initializing');
|
|
@@ -79,7 +81,7 @@ class InstanceBase {
|
|
|
79
81
|
* Performing upgrades during init requires a fair chunk of work.
|
|
80
82
|
* Some actions/feedbacks will be using the upgradeIndex of the instance, but some may have their own upgradeIndex on themselves if they are from an import.
|
|
81
83
|
*/
|
|
82
|
-
const { updatedActions, updatedFeedbacks, updatedConfig } = (0,
|
|
84
|
+
const { updatedActions, updatedFeedbacks, updatedConfig } = (0, upgrade_1.runThroughUpgradeScripts)(actions, feedbacks, msg.lastUpgradeIndex, this.#upgradeScripts, config);
|
|
83
85
|
config = updatedConfig ?? config;
|
|
84
86
|
// Send the upgraded data back to companion now. Just so that if the init crashes, this doesnt have to be repeated
|
|
85
87
|
const pSendUpgrade = this.#ipcWrapper.sendWithCb('upgradedItems', {
|
|
@@ -101,8 +103,12 @@ class InstanceBase {
|
|
|
101
103
|
}
|
|
102
104
|
setImmediate(() => {
|
|
103
105
|
// Subscribe all of the actions and feedbacks
|
|
104
|
-
this._handleUpdateActions({ actions }, true)
|
|
105
|
-
|
|
106
|
+
this._handleUpdateActions({ actions }, true).catch((e) => {
|
|
107
|
+
this.log('error', `Receive actions failed: ${e}`);
|
|
108
|
+
});
|
|
109
|
+
this._handleUpdateFeedbacks({ feedbacks }, true).catch((e) => {
|
|
110
|
+
this.log('error', `Receive feedbacks failed: ${e}`);
|
|
111
|
+
});
|
|
106
112
|
});
|
|
107
113
|
return {
|
|
108
114
|
hasHttpHandler: typeof this.handleHttpRequest === 'function',
|
|
@@ -128,130 +134,41 @@ class InstanceBase {
|
|
|
128
134
|
});
|
|
129
135
|
}
|
|
130
136
|
async _handleExecuteAction(msg) {
|
|
131
|
-
|
|
132
|
-
if (!actionDefinition)
|
|
133
|
-
throw new Error(`Unknown action: ${msg.action.actionId}`);
|
|
134
|
-
await actionDefinition.callback({
|
|
135
|
-
id: msg.action.id,
|
|
136
|
-
actionId: msg.action.actionId,
|
|
137
|
-
controlId: msg.action.controlId,
|
|
138
|
-
options: msg.action.options,
|
|
139
|
-
_deviceId: msg.deviceId,
|
|
140
|
-
_page: msg.action.page,
|
|
141
|
-
_bank: msg.action.bank,
|
|
142
|
-
});
|
|
137
|
+
return this.#actionManager.handleExecuteAction(msg);
|
|
143
138
|
}
|
|
144
139
|
async _handleUpdateFeedbacks(msg, skipUpgrades) {
|
|
145
|
-
const newValues = [];
|
|
146
140
|
// Run through upgrade scripts if needed
|
|
147
141
|
if (!skipUpgrades) {
|
|
148
|
-
(0,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
try {
|
|
157
|
-
definition.unsubscribe((0, feedback_js_1.convertFeedbackInstanceToEvent)(definition.type, existing));
|
|
158
|
-
}
|
|
159
|
-
catch (e) {
|
|
160
|
-
console.error(`Feedback unsubscribe failed: ${JSON.stringify(existing)} - ${e?.message ?? e} ${e?.stack}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (!feedback || feedback.disabled) {
|
|
165
|
-
// Deleted
|
|
166
|
-
this.#feedbackInstances.delete(id);
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
// TODO module-lib - deep freeze the feedback to avoid mutation?
|
|
170
|
-
this.#feedbackInstances.set(id, feedback);
|
|
171
|
-
// Inserted or updated
|
|
172
|
-
const definition = this.#feedbackDefinitions.get(feedback.feedbackId);
|
|
173
|
-
if (definition?.subscribe) {
|
|
174
|
-
try {
|
|
175
|
-
definition.subscribe((0, feedback_js_1.convertFeedbackInstanceToEvent)(definition.type, feedback));
|
|
176
|
-
}
|
|
177
|
-
catch (e) {
|
|
178
|
-
console.error(`Feedback subscribe failed: ${JSON.stringify(feedback)} - ${e?.message ?? e} ${e?.stack}`);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
// Calculate the new value for the feedback
|
|
182
|
-
if (definition) {
|
|
183
|
-
let value;
|
|
184
|
-
try {
|
|
185
|
-
value = (0, feedback_js_1.callFeedbackOnDefinition)(definition, feedback);
|
|
186
|
-
}
|
|
187
|
-
catch (e) {
|
|
188
|
-
console.error(`Feedback check failed: ${JSON.stringify(feedback)} - ${e?.message ?? e} ${e?.stack}`);
|
|
189
|
-
}
|
|
190
|
-
if (value instanceof Promise) {
|
|
191
|
-
value = undefined;
|
|
192
|
-
console.error(`Feedback check returned Promise, this is not allowed: ${JSON.stringify(feedback)}`);
|
|
193
|
-
}
|
|
194
|
-
newValues.push({
|
|
195
|
-
id: id,
|
|
196
|
-
controlId: feedback.controlId,
|
|
197
|
-
value: value,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
// Send the new values back
|
|
203
|
-
if (Object.keys(newValues).length > 0) {
|
|
204
|
-
this.#ipcWrapper.sendWithNoCb('updateFeedbackValues', {
|
|
205
|
-
values: newValues,
|
|
142
|
+
const res = (0, upgrade_1.runThroughUpgradeScripts)({}, msg.feedbacks, null, this.#upgradeScripts, undefined);
|
|
143
|
+
this.#ipcWrapper
|
|
144
|
+
.sendWithCb('upgradedItems', {
|
|
145
|
+
updatedActions: res.updatedActions,
|
|
146
|
+
updatedFeedbacks: res.updatedFeedbacks,
|
|
147
|
+
})
|
|
148
|
+
.catch((e) => {
|
|
149
|
+
this.log('error', `Failed to save upgraded feedbacks: ${e}`);
|
|
206
150
|
});
|
|
207
151
|
}
|
|
152
|
+
this.#feedbackManager.handleUpdateFeedbacks(msg.feedbacks);
|
|
208
153
|
}
|
|
209
154
|
async _handleUpdateActions(msg, skipUpgrades) {
|
|
210
155
|
// Run through upgrade scripts if needed
|
|
211
156
|
if (!skipUpgrades) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
// Call unsubscribe
|
|
222
|
-
const definition = this.#actionDefinitions.get(existing.actionId);
|
|
223
|
-
if (definition?.unsubscribe) {
|
|
224
|
-
try {
|
|
225
|
-
definition.unsubscribe(existing);
|
|
226
|
-
}
|
|
227
|
-
catch (e) {
|
|
228
|
-
console.error(`Action unsubscribe failed: ${JSON.stringify(existing)} - ${e?.message ?? e} ${e?.stack}`);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
if (!action || action.disabled) {
|
|
233
|
-
// Deleted
|
|
234
|
-
this.#actionInstances.delete(id);
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
// TODO module-lib - deep freeze the action to avoid mutation?
|
|
238
|
-
this.#actionInstances.set(id, action);
|
|
239
|
-
// Inserted or updated
|
|
240
|
-
const definition = this.#actionDefinitions.get(action.actionId);
|
|
241
|
-
if (definition?.subscribe) {
|
|
242
|
-
try {
|
|
243
|
-
definition.subscribe(action);
|
|
244
|
-
}
|
|
245
|
-
catch (e) {
|
|
246
|
-
console.error(`Action subscribe failed: ${JSON.stringify(action)} - ${e?.message ?? e} ${e?.stack}`);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
157
|
+
const res = (0, upgrade_1.runThroughUpgradeScripts)(msg.actions, {}, null, this.#upgradeScripts, undefined);
|
|
158
|
+
this.#ipcWrapper
|
|
159
|
+
.sendWithCb('upgradedItems', {
|
|
160
|
+
updatedActions: res.updatedActions,
|
|
161
|
+
updatedFeedbacks: res.updatedFeedbacks,
|
|
162
|
+
})
|
|
163
|
+
.catch((e) => {
|
|
164
|
+
this.log('error', `Failed to save upgraded actions: ${e}`);
|
|
165
|
+
});
|
|
250
166
|
}
|
|
167
|
+
this.#actionManager.handleUpdateActions(msg.actions);
|
|
251
168
|
}
|
|
252
169
|
async _handleGetConfigFields(_msg) {
|
|
253
170
|
return {
|
|
254
|
-
fields: (0,
|
|
171
|
+
fields: (0, base_1.serializeIsVisibleFn)(this.getConfigFields()),
|
|
255
172
|
};
|
|
256
173
|
}
|
|
257
174
|
async _handleHttpRequest(msg) {
|
|
@@ -261,48 +178,10 @@ class InstanceBase {
|
|
|
261
178
|
return { response: res };
|
|
262
179
|
}
|
|
263
180
|
async _handleLearnAction(msg) {
|
|
264
|
-
|
|
265
|
-
if (definition && definition.learn) {
|
|
266
|
-
const newOptions = await definition.learn({
|
|
267
|
-
id: msg.action.id,
|
|
268
|
-
actionId: msg.action.actionId,
|
|
269
|
-
controlId: msg.action.controlId,
|
|
270
|
-
options: msg.action.options,
|
|
271
|
-
_deviceId: undefined,
|
|
272
|
-
_page: msg.action.page,
|
|
273
|
-
_bank: msg.action.bank,
|
|
274
|
-
});
|
|
275
|
-
return {
|
|
276
|
-
options: newOptions,
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
// Not supported
|
|
281
|
-
return {
|
|
282
|
-
options: undefined,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
181
|
+
return this.#actionManager.handleLearnAction(msg);
|
|
285
182
|
}
|
|
286
183
|
async _handleLearnFeedback(msg) {
|
|
287
|
-
|
|
288
|
-
if (definition && definition.learn) {
|
|
289
|
-
const newOptions = await definition.learn({
|
|
290
|
-
id: msg.feedback.id,
|
|
291
|
-
feedbackId: msg.feedback.feedbackId,
|
|
292
|
-
controlId: msg.feedback.controlId,
|
|
293
|
-
options: msg.feedback.options,
|
|
294
|
-
type: definition.type,
|
|
295
|
-
});
|
|
296
|
-
return {
|
|
297
|
-
options: newOptions,
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
// Not supported
|
|
302
|
-
return {
|
|
303
|
-
options: undefined,
|
|
304
|
-
};
|
|
305
|
-
}
|
|
184
|
+
return this.#feedbackManager.handleLearnFeedback(msg);
|
|
306
185
|
}
|
|
307
186
|
async _handleStartStopRecordActions(msg) {
|
|
308
187
|
if (!msg.recording) {
|
|
@@ -324,6 +203,9 @@ class InstanceBase {
|
|
|
324
203
|
this.#recordingActions = msg.recording;
|
|
325
204
|
this.handleStartStopRecordActions(this.#recordingActions);
|
|
326
205
|
}
|
|
206
|
+
async _handleVariablesChanged(msg) {
|
|
207
|
+
this.#feedbackManager.handleVariablesChanged(msg);
|
|
208
|
+
}
|
|
327
209
|
/**
|
|
328
210
|
* Save an updated configuration object
|
|
329
211
|
* @param newConfig The new config object
|
|
@@ -336,46 +218,14 @@ class InstanceBase {
|
|
|
336
218
|
* @param actions The action definitions
|
|
337
219
|
*/
|
|
338
220
|
setActionDefinitions(actions) {
|
|
339
|
-
|
|
340
|
-
this.#actionDefinitions.clear();
|
|
341
|
-
for (const [actionId, action] of Object.entries(actions)) {
|
|
342
|
-
if (action) {
|
|
343
|
-
hostActions.push({
|
|
344
|
-
id: actionId,
|
|
345
|
-
name: action.name,
|
|
346
|
-
description: action.description,
|
|
347
|
-
options: (0, base_js_1.serializeIsVisibleFn)(action.options),
|
|
348
|
-
hasLearn: !!action.learn,
|
|
349
|
-
});
|
|
350
|
-
// Remember the definition locally
|
|
351
|
-
this.#actionDefinitions.set(actionId, action);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
this.#ipcWrapper.sendWithNoCb('setActionDefinitions', { actions: hostActions });
|
|
221
|
+
this.#actionManager.setActionDefinitions(actions);
|
|
355
222
|
}
|
|
356
223
|
/**
|
|
357
224
|
* Set the feedback definitions for this instance
|
|
358
225
|
* @param feedbacks The feedback definitions
|
|
359
226
|
*/
|
|
360
227
|
setFeedbackDefinitions(feedbacks) {
|
|
361
|
-
|
|
362
|
-
this.#feedbackDefinitions.clear();
|
|
363
|
-
for (const [feedbackId, feedback] of Object.entries(feedbacks)) {
|
|
364
|
-
if (feedback) {
|
|
365
|
-
hostFeedbacks.push({
|
|
366
|
-
id: feedbackId,
|
|
367
|
-
name: feedback.name,
|
|
368
|
-
description: feedback.description,
|
|
369
|
-
options: (0, base_js_1.serializeIsVisibleFn)(feedback.options),
|
|
370
|
-
type: feedback.type,
|
|
371
|
-
defaultStyle: 'defaultStyle' in feedback ? feedback.defaultStyle : undefined,
|
|
372
|
-
hasLearn: !!feedback.learn,
|
|
373
|
-
});
|
|
374
|
-
// Remember the definition locally
|
|
375
|
-
this.#feedbackDefinitions.set(feedbackId, feedback);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
this.#ipcWrapper.sendWithNoCb('setFeedbackDefinitions', { feedbacks: hostFeedbacks });
|
|
228
|
+
this.#feedbackManager.setFeedbackDefinitions(feedbacks);
|
|
379
229
|
}
|
|
380
230
|
/**
|
|
381
231
|
* Set the peset definitions for this instance
|
|
@@ -471,11 +321,23 @@ class InstanceBase {
|
|
|
471
321
|
}
|
|
472
322
|
/**
|
|
473
323
|
* Parse and replace all the variables in a string
|
|
324
|
+
* Note: You must not use this for feedbacks, as your feedback will not update when the variable changes.
|
|
325
|
+
* There is an alternate version of this supplied to each of the action/feedback callbacks that tracks
|
|
326
|
+
* usages properly and will retrigger the feedback when the variables change.
|
|
474
327
|
* @param text The text to parse
|
|
475
328
|
* @returns The string with variables replaced with their values
|
|
476
329
|
*/
|
|
477
330
|
async parseVariablesInString(text) {
|
|
478
|
-
const
|
|
331
|
+
const currentContext = this.#feedbackManager.parseVariablesContext;
|
|
332
|
+
if (currentContext) {
|
|
333
|
+
this.log('debug', `parseVariablesInString called while in: ${currentContext}. You should use the parseVariablesInString provided to the callback instead`);
|
|
334
|
+
}
|
|
335
|
+
const res = await this.#ipcWrapper.sendWithCb('parseVariablesInString', {
|
|
336
|
+
text: text,
|
|
337
|
+
controlId: undefined,
|
|
338
|
+
actionInstanceId: undefined,
|
|
339
|
+
feedbackInstanceId: undefined,
|
|
340
|
+
});
|
|
479
341
|
return res.text;
|
|
480
342
|
}
|
|
481
343
|
/**
|
|
@@ -483,84 +345,18 @@ class InstanceBase {
|
|
|
483
345
|
* @param feedbackTypes The feedback types to check
|
|
484
346
|
*/
|
|
485
347
|
checkFeedbacks(...feedbackTypes) {
|
|
486
|
-
|
|
487
|
-
const types = new Set(feedbackTypes);
|
|
488
|
-
for (const [id, feedback] of this.#feedbackInstances.entries()) {
|
|
489
|
-
const definition = this.#feedbackDefinitions.get(feedback.feedbackId);
|
|
490
|
-
if (definition) {
|
|
491
|
-
if (types.size > 0 && !types.has(feedback.feedbackId)) {
|
|
492
|
-
// Not to be considered
|
|
493
|
-
continue;
|
|
494
|
-
}
|
|
495
|
-
try {
|
|
496
|
-
// Calculate the new value for the feedback
|
|
497
|
-
let value = (0, feedback_js_1.callFeedbackOnDefinition)(definition, feedback);
|
|
498
|
-
if (value instanceof Promise) {
|
|
499
|
-
value = undefined;
|
|
500
|
-
console.error(`Feedback check returned Promise, this is not allowed: ${JSON.stringify(feedback)}`);
|
|
501
|
-
}
|
|
502
|
-
newValues.push({
|
|
503
|
-
id: id,
|
|
504
|
-
controlId: feedback.controlId,
|
|
505
|
-
value: value,
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
catch (e) {
|
|
509
|
-
console.error(`Feedback check failed: ${JSON.stringify(feedback)} - ${e?.message ?? e} ${e?.stack}`);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
// Send the new values back
|
|
514
|
-
if (Object.keys(newValues).length > 0) {
|
|
515
|
-
this.#ipcWrapper.sendWithNoCb('updateFeedbackValues', {
|
|
516
|
-
values: newValues,
|
|
517
|
-
});
|
|
518
|
-
}
|
|
348
|
+
this.#feedbackManager.checkFeedbacks(feedbackTypes);
|
|
519
349
|
}
|
|
520
350
|
/**
|
|
521
351
|
* Request the specified feedback instances to be checked for changes
|
|
522
352
|
* @param feedbackIds The ids of the feedback instances to check
|
|
523
353
|
*/
|
|
524
354
|
checkFeedbacksById(...feedbackIds) {
|
|
525
|
-
|
|
526
|
-
for (const id of feedbackIds) {
|
|
527
|
-
const feedback = this.#feedbackInstances.get(id);
|
|
528
|
-
const definition = feedback && this.#feedbackDefinitions.get(feedback.feedbackId);
|
|
529
|
-
if (feedback && definition) {
|
|
530
|
-
try {
|
|
531
|
-
// Calculate the new value for the feedback
|
|
532
|
-
let value = (0, feedback_js_1.callFeedbackOnDefinition)(definition, feedback);
|
|
533
|
-
if (value instanceof Promise) {
|
|
534
|
-
value = undefined;
|
|
535
|
-
console.error(`Feedback check returned Promise, this is not allowed: ${JSON.stringify(feedback)}`);
|
|
536
|
-
}
|
|
537
|
-
// Calculate the new value for the feedback
|
|
538
|
-
newValues.push({
|
|
539
|
-
id: id,
|
|
540
|
-
controlId: feedback.controlId,
|
|
541
|
-
value: value,
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
catch (e) {
|
|
545
|
-
console.error(`Feedback check failed: ${JSON.stringify(feedback)} - ${e?.message ?? e} ${e?.stack}`);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
// Send the new values back
|
|
550
|
-
if (Object.keys(newValues).length > 0) {
|
|
551
|
-
this.#ipcWrapper.sendWithNoCb('updateFeedbackValues', {
|
|
552
|
-
values: newValues,
|
|
553
|
-
});
|
|
554
|
-
}
|
|
355
|
+
this.#feedbackManager.checkFeedbacksById(feedbackIds);
|
|
555
356
|
}
|
|
556
357
|
/** @deprecated */
|
|
557
358
|
_getAllActions() {
|
|
558
|
-
return
|
|
559
|
-
id: act.id,
|
|
560
|
-
actionId: act.actionId,
|
|
561
|
-
controlId: act.controlId,
|
|
562
|
-
options: act.options,
|
|
563
|
-
}));
|
|
359
|
+
return this.#actionManager._getAllActions();
|
|
564
360
|
}
|
|
565
361
|
/**
|
|
566
362
|
* Call subscribe on all currently known placed actions.
|
|
@@ -568,21 +364,7 @@ class InstanceBase {
|
|
|
568
364
|
* @param actionIds The actionIds to call subscribe for. If no values are provided, then all are called.
|
|
569
365
|
*/
|
|
570
366
|
subscribeActions(...actionIds) {
|
|
571
|
-
|
|
572
|
-
const actionIdSet = new Set(actionIds);
|
|
573
|
-
if (actionIdSet.size)
|
|
574
|
-
actions = actions.filter((fb) => actionIdSet.has(fb.actionId));
|
|
575
|
-
for (const act of actions) {
|
|
576
|
-
const def = this.#actionDefinitions.get(act.actionId);
|
|
577
|
-
if (def?.subscribe) {
|
|
578
|
-
def.subscribe({
|
|
579
|
-
id: act.id,
|
|
580
|
-
actionId: act.actionId,
|
|
581
|
-
controlId: act.controlId,
|
|
582
|
-
options: act.options,
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
}
|
|
367
|
+
this.#actionManager.subscribeActions(actionIds);
|
|
586
368
|
}
|
|
587
369
|
/**
|
|
588
370
|
* Call unsubscribe on all currently known placed actions.
|
|
@@ -590,30 +372,11 @@ class InstanceBase {
|
|
|
590
372
|
* @param actionIds The actionIds to call subscribe for. If no values are provided, then all are called.
|
|
591
373
|
*/
|
|
592
374
|
unsubscribeActions(...actionIds) {
|
|
593
|
-
|
|
594
|
-
const actionIdSet = new Set(actionIds);
|
|
595
|
-
if (actionIdSet.size)
|
|
596
|
-
actions = actions.filter((fb) => actionIdSet.has(fb.actionId));
|
|
597
|
-
for (const act of actions) {
|
|
598
|
-
const def = this.#actionDefinitions.get(act.actionId);
|
|
599
|
-
if (def && def.unsubscribe) {
|
|
600
|
-
def.unsubscribe({
|
|
601
|
-
id: act.id,
|
|
602
|
-
actionId: act.actionId,
|
|
603
|
-
controlId: act.controlId,
|
|
604
|
-
options: act.options,
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
}
|
|
375
|
+
this.#actionManager.unsubscribeActions(actionIds);
|
|
608
376
|
}
|
|
609
377
|
/** @deprecated */
|
|
610
378
|
_getAllFeedbacks() {
|
|
611
|
-
return
|
|
612
|
-
id: fb.id,
|
|
613
|
-
feedbackId: fb.feedbackId,
|
|
614
|
-
controlId: fb.controlId,
|
|
615
|
-
options: fb.options,
|
|
616
|
-
}));
|
|
379
|
+
return this.#feedbackManager._getAllFeedbacks();
|
|
617
380
|
}
|
|
618
381
|
/**
|
|
619
382
|
* Call subscribe on all currently known placed feedbacks.
|
|
@@ -621,22 +384,7 @@ class InstanceBase {
|
|
|
621
384
|
* @param feedbackIds The feedbackIds to call subscribe for. If no values are provided, then all are called.
|
|
622
385
|
*/
|
|
623
386
|
subscribeFeedbacks(...feedbackIds) {
|
|
624
|
-
|
|
625
|
-
const feedbackIdSet = new Set(feedbackIds);
|
|
626
|
-
if (feedbackIdSet.size)
|
|
627
|
-
feedbacks = feedbacks.filter((fb) => feedbackIdSet.has(fb.feedbackId));
|
|
628
|
-
for (const fb of feedbacks) {
|
|
629
|
-
const def = this.#feedbackDefinitions.get(fb.feedbackId);
|
|
630
|
-
if (def?.subscribe) {
|
|
631
|
-
def.subscribe({
|
|
632
|
-
type: def.type,
|
|
633
|
-
id: fb.id,
|
|
634
|
-
feedbackId: fb.feedbackId,
|
|
635
|
-
controlId: fb.controlId,
|
|
636
|
-
options: fb.options,
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
}
|
|
387
|
+
this.#feedbackManager.subscribeFeedbacks(feedbackIds);
|
|
640
388
|
}
|
|
641
389
|
/**
|
|
642
390
|
* Call unsubscribe on all currently known placed feedbacks.
|
|
@@ -644,22 +392,7 @@ class InstanceBase {
|
|
|
644
392
|
* @param feedbackIds The feedbackIds to call subscribe for. If no values are provided, then all are called.
|
|
645
393
|
*/
|
|
646
394
|
unsubscribeFeedbacks(...feedbackIds) {
|
|
647
|
-
|
|
648
|
-
const feedbackIdSet = new Set(feedbackIds);
|
|
649
|
-
if (feedbackIdSet.size)
|
|
650
|
-
feedbacks = feedbacks.filter((fb) => feedbackIdSet.has(fb.feedbackId));
|
|
651
|
-
for (const fb of feedbacks) {
|
|
652
|
-
const def = this.#feedbackDefinitions.get(fb.feedbackId);
|
|
653
|
-
if (def && def.unsubscribe) {
|
|
654
|
-
def.unsubscribe({
|
|
655
|
-
type: def.type,
|
|
656
|
-
id: fb.id,
|
|
657
|
-
feedbackId: fb.feedbackId,
|
|
658
|
-
controlId: fb.controlId,
|
|
659
|
-
options: fb.options,
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
}
|
|
395
|
+
this.#feedbackManager.unsubscribeFeedbacks(feedbackIds);
|
|
663
396
|
}
|
|
664
397
|
/**
|
|
665
398
|
* Add an action to the current recording session
|
|
@@ -678,13 +411,13 @@ class InstanceBase {
|
|
|
678
411
|
/**
|
|
679
412
|
* Experimental: This method may change without notice. Do not use!
|
|
680
413
|
* Set the value of a custom variable
|
|
681
|
-
* @param
|
|
414
|
+
* @param variableName
|
|
682
415
|
* @param value
|
|
683
416
|
* @returns Promise which resolves upon success, or rejects if the variable no longer exists
|
|
684
417
|
*/
|
|
685
|
-
setCustomVariableValue(
|
|
418
|
+
setCustomVariableValue(variableName, value) {
|
|
686
419
|
this.#ipcWrapper.sendWithNoCb('setCustomVariable', {
|
|
687
|
-
customVariableId:
|
|
420
|
+
customVariableId: variableName,
|
|
688
421
|
value,
|
|
689
422
|
});
|
|
690
423
|
}
|
|
@@ -696,7 +429,7 @@ class InstanceBase {
|
|
|
696
429
|
* @param args mesage arguments
|
|
697
430
|
*/
|
|
698
431
|
oscSend(host, port, path, args) {
|
|
699
|
-
this.#ipcWrapper.sendWithNoCb('send-osc', (0,
|
|
432
|
+
this.#ipcWrapper.sendWithNoCb('send-osc', (0, util_1.literal)({
|
|
700
433
|
host,
|
|
701
434
|
port,
|
|
702
435
|
path,
|
|
@@ -714,7 +447,7 @@ class InstanceBase {
|
|
|
714
447
|
* ```
|
|
715
448
|
*/
|
|
716
449
|
updateStatus(status, message) {
|
|
717
|
-
this.#ipcWrapper.sendWithNoCb('set-status', (0,
|
|
450
|
+
this.#ipcWrapper.sendWithNoCb('set-status', (0, util_1.literal)({
|
|
718
451
|
status,
|
|
719
452
|
message: message ?? null,
|
|
720
453
|
}));
|
|
@@ -725,7 +458,7 @@ class InstanceBase {
|
|
|
725
458
|
* @param message The message text to write
|
|
726
459
|
*/
|
|
727
460
|
log(level, message) {
|
|
728
|
-
this.#ipcWrapper.sendWithNoCb('log-message', (0,
|
|
461
|
+
this.#ipcWrapper.sendWithNoCb('log-message', (0, util_1.literal)({
|
|
729
462
|
level,
|
|
730
463
|
message,
|
|
731
464
|
}));
|