diff --git a/companion-plugin/companion-module-esa/src/actions.ts b/companion-plugin/companion-module-esa/src/actions.ts index 8bfe9047..a35bd347 100644 --- a/companion-plugin/companion-module-esa/src/actions.ts +++ b/companion-plugin/companion-module-esa/src/actions.ts @@ -1,35 +1,10 @@ -import { CompanionActionDefinition } from '@companion-module/base'; import type ModuleInstance from './index'; -let instance: ModuleInstance; - -export const videoPlayAction = ( - videos: { name: string, sum: string }[], -): CompanionActionDefinition => ({ - name: 'Video Play', - description: 'Plays the chosen video', - options: [ - { - id: 'video', - type: 'dropdown', - label: 'Video', - choices: videos.map(({ name, sum }) => ({ id: sum, label: name })), - default: '', - }, - ], - callback: (action) => { - if (action.options.video) { - instance.wsSend({ name: 'video_play', value: action.options.video }); - } - }, -}); - /** * Called by module instance class when actions should be set up. * @param instance Copy of current module instance class */ -export function initActions(instance_: ModuleInstance) { - instance = instance_; +function initActions(instance: ModuleInstance, videos?: { name: string, sum: string }[]) { instance.setActionDefinitions({ // Blank action that can be attached if connection status is needed but nothing else. // There may be another way of doing this, just not found it yet? @@ -116,6 +91,25 @@ export function initActions(instance_: ModuleInstance) { } }, }, - video_play: videoPlayAction([]), + video_play: { + name: 'Video Play', + description: 'Plays the chosen video', + options: [ + { + id: 'video', + type: 'dropdown', + label: 'Video', + choices: videos?.map(({ name, sum }) => ({ id: sum, label: name })) || [], + default: '', + }, + ], + callback: (action) => { + if (action.options.video) { + instance.wsSend({ name: 'video_play', value: action.options.video }); + } + }, + }, }); } + +export default initActions; diff --git a/companion-plugin/companion-module-esa/src/index.ts b/companion-plugin/companion-module-esa/src/index.ts index 0602d49c..b600fe32 100644 --- a/companion-plugin/companion-module-esa/src/index.ts +++ b/companion-plugin/companion-module-esa/src/index.ts @@ -1,6 +1,6 @@ import { InstanceBase, InstanceStatus, SomeCompanionConfigField, runEntrypoint } from '@companion-module/base'; import { WebSocket } from 'ws'; -import { initActions, videoPlayAction } from './actions'; +import initActions from './actions'; import { Config, getConfigFields } from './config'; import { initFeedbacks, obsSceneFeedback, setObsSceneKeys } from './feedbacks'; import initPresets from './presets'; @@ -157,10 +157,9 @@ class ModuleInstance extends InstanceBase { sum: string; // Other unimportant (at the moment) types omitted. }[]; - // Updates the dropdown with the video information. - this.setActionDefinitions({ - video_play: videoPlayAction(videos), - }); + // Updates the dropdown with the video information by re-initialising all actions. + // TODO: Is there a better way? + initActions(this, videos); } }); }