Skip to content

Commit

Permalink
Fix issue with Companion actions going missing
Browse files Browse the repository at this point in the history
  • Loading branch information
zoton2 committed Feb 17, 2024
1 parent caf813d commit c5e864d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
48 changes: 21 additions & 27 deletions companion-plugin/companion-module-esa/src/actions.ts
Original file line number Diff line number Diff line change
@@ -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?
Expand Down Expand Up @@ -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;
9 changes: 4 additions & 5 deletions companion-plugin/companion-module-esa/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -157,10 +157,9 @@ class ModuleInstance extends InstanceBase<Config> {
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);
}
});
}
Expand Down

0 comments on commit c5e864d

Please sign in to comment.