Skip to content

Commit fbf6955

Browse files
Refactor Module to use Handlers (#149)
* initial versions of refactoring * add feedback handler * added variable handler * created directory for handlers * simplified BaseExt interface * re-added polling of variables * removed eslint file (no longer needed) * added advanced config options * removed unused config option * added documentation for handlers * added osc forwarding to advanced options * created handler for osc-forwarding * added log info for osc forwarder creation * Fixes #162 * refactor: update visibility expressions for advanced options in config fields Increased default subscription interval to 9000ms * fix: re-add variable prefetching on connection ready * feature: added debug mode with timestamp and call stack * fix: prevent double sending of subscription command changed: added option to omit logging of command upon sending * changed: device detector is now a proper handler * simplified assignment of logger * refactor: move handler setup to functions * changed: optimized main module status updates and logging * try out wheter removing second command send is ok * made requestupdate dependent on structural change * removed async from subscribe * removed async from actionutil function * changed: gain, fader and panorama variable values are now rounded * fix: removed deprecated function call * closes [Feature]: Support for variables in feedback section Fixes #151 * added missing import of Dropdown * fix: adjust fader command * fix: main alt connection switch polarity * fix: led scribble light could not be turned off * fix: named channels appear correctly again * fix: scene name list works again * fix: removed await from actionutil * added: rounding variable values to 1 decimal place * fixed rebase issue --------- Co-authored-by: Elliot Matson <1711604+elliotmatson@users.noreply.github.com>
1 parent 7ee53f6 commit fbf6955

40 files changed

+3333
-2880
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/actions/cards.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export enum CardsActionId {
3232
}
3333

3434
export function createCardsActions(self: InstanceBaseExt<WingConfig>): CompanionActionDefinitions {
35-
const send = self.sendCommand
35+
const send = self.connection!.sendCommand.bind(self.connection)
3636

3737
const actions: { [id in CardsActionId]: CompanionActionWithCallback | undefined } = {
3838
[CardsActionId.SetLink]: {
@@ -41,8 +41,8 @@ export function createCardsActions(self: InstanceBaseExt<WingConfig>): Companion
4141
options: [...GetDropdownWithVariables('Link', 'link', getCardsLinkChoices())],
4242
callback: async (event) => {
4343
const cmd = Commands.WLiveSDLink()
44-
const link = await getStringWithVariables(event, 'link')
45-
send(cmd, link)
44+
const link = getStringWithVariables(event, 'link')
45+
await send(cmd, link)
4646
},
4747
},
4848
[CardsActionId.SetAutoInput]: {
@@ -51,8 +51,8 @@ export function createCardsActions(self: InstanceBaseExt<WingConfig>): Companion
5151
options: [...GetDropdownWithVariables('Selection', 'selection', getCardsAutoInChoices())],
5252
callback: async (event) => {
5353
const cmd = Commands.WLiveAutoIn()
54-
const selection = await getStringWithVariables(event, 'selection')
55-
send(cmd, selection)
54+
const selection = getStringWithVariables(event, 'selection')
55+
await send(cmd, selection)
5656
},
5757
},
5858
[CardsActionId.SetAutoStop]: {
@@ -61,8 +61,8 @@ export function createCardsActions(self: InstanceBaseExt<WingConfig>): Companion
6161
options: [...GetDropdownWithVariables('Selection', 'selection', getCardsAutoRoutingChoices())],
6262
callback: async (event) => {
6363
const cmd = Commands.WLiveAutoStop()
64-
const selection = await getStringWithVariables(event, 'selection')
65-
send(cmd, selection)
64+
const selection = getStringWithVariables(event, 'selection')
65+
await send(cmd, selection)
6666
},
6767
},
6868
[CardsActionId.SetAutoPlay]: {
@@ -71,8 +71,8 @@ export function createCardsActions(self: InstanceBaseExt<WingConfig>): Companion
7171
options: [...GetDropdownWithVariables('Selection', 'selection', getCardsAutoRoutingChoices())],
7272
callback: async (event) => {
7373
const cmd = Commands.WLiveAutoPlay()
74-
const selection = await getStringWithVariables(event, 'selection')
75-
send(cmd, selection)
74+
const selection = getStringWithVariables(event, 'selection')
75+
await send(cmd, selection)
7676
},
7777
},
7878
[CardsActionId.SetAutoRecord]: {
@@ -81,8 +81,8 @@ export function createCardsActions(self: InstanceBaseExt<WingConfig>): Companion
8181
options: [...GetDropdownWithVariables('Selection', 'selection', getCardsAutoRoutingChoices())],
8282
callback: async (event) => {
8383
const cmd = Commands.WLiveAutoRecord()
84-
const selection = await getStringWithVariables(event, 'selection')
85-
send(cmd, selection)
84+
const selection = getStringWithVariables(event, 'selection')
85+
await send(cmd, selection)
8686
},
8787
},
8888
[CardsActionId.CardAction]: {
@@ -93,10 +93,10 @@ export function createCardsActions(self: InstanceBaseExt<WingConfig>): Companion
9393
...GetDropdownWithVariables('Action', 'action', getCardsActionChoices()),
9494
],
9595
callback: async (event) => {
96-
const card = await getNumberWithVariables(event, 'card')
96+
const card = getNumberWithVariables(event, 'card')
9797
const cmd = Commands.WLiveCardControl(card)
98-
const action = await getStringWithVariables(event, 'action')
99-
send(cmd, action)
98+
const action = getStringWithVariables(event, 'action')
99+
await send(cmd, action)
100100
},
101101
},
102102
[CardsActionId.OpenSession]: {
@@ -107,10 +107,10 @@ export function createCardsActions(self: InstanceBaseExt<WingConfig>): Companion
107107
...GetNumberFieldWithVariables('Session Number', 'session', 1, 100, 1, 1),
108108
],
109109
callback: async (event) => {
110-
const card = await getNumberWithVariables(event, 'card')
111-
const session = await getNumberWithVariables(event, 'session')
110+
const card = getNumberWithVariables(event, 'card')
111+
const session = getNumberWithVariables(event, 'session')
112112
const cmd = Commands.WLiveCardOpenSession(card)
113-
send(cmd, session)
113+
await send(cmd, session)
114114
},
115115
},
116116
[CardsActionId.DeleteSession]: {
@@ -121,10 +121,10 @@ export function createCardsActions(self: InstanceBaseExt<WingConfig>): Companion
121121
...GetNumberFieldWithVariables('Session Number', 'session', 1, 100, 1, 1),
122122
],
123123
callback: async (event) => {
124-
const card = await getNumberWithVariables(event, 'card')
125-
const session = await getNumberWithVariables(event, 'session')
124+
const card = getNumberWithVariables(event, 'card')
125+
const session = getNumberWithVariables(event, 'session')
126126
const cmd = Commands.WLiveCardDeleteSession(card)
127-
send(cmd, session)
127+
await send(cmd, session)
128128
},
129129
},
130130
[CardsActionId.NameSession]: {
@@ -140,10 +140,10 @@ export function createCardsActions(self: InstanceBaseExt<WingConfig>): Companion
140140
),
141141
],
142142
callback: async (event) => {
143-
const card = await getNumberWithVariables(event, 'card')
144-
const name = await getStringWithVariables(event, 'name')
143+
const card = getNumberWithVariables(event, 'card')
144+
const name = getStringWithVariables(event, 'name')
145145
const cmd = Commands.WLiveCardNameSession(card)
146-
send(cmd, name)
146+
await send(cmd, name)
147147
},
148148
},
149149
[CardsActionId.SetPosition]: {
@@ -154,22 +154,22 @@ export function createCardsActions(self: InstanceBaseExt<WingConfig>): Companion
154154
...GetNumberFieldWithVariables('Position (ms)', 'position', 0, 36000000, 1, 0),
155155
],
156156
callback: async (event) => {
157-
const card = await getNumberWithVariables(event, 'card')
158-
const position = await getNumberWithVariables(event, 'position')
157+
const card = getNumberWithVariables(event, 'card')
158+
const position = getNumberWithVariables(event, 'position')
159159
const cmd = Commands.WLiveCardTime(card)
160-
send(cmd, position, true)
160+
await send(cmd, position, true)
161161
const cmd2 = Commands.WLiveCardGotoMarker(card)
162-
send(cmd2, 101)
162+
await send(cmd2, 101)
163163
},
164164
},
165165
[CardsActionId.AddMarker]: {
166166
name: 'WLive: Add Marker',
167167
description: 'Add a marker to a recording on a card.',
168168
options: [...GetDropdownWithVariables('Card', 'card', getCardsChoices())],
169169
callback: async (event) => {
170-
const card = await getNumberWithVariables(event, 'card')
170+
const card = getNumberWithVariables(event, 'card')
171171
const cmd = Commands.WLiveCardSetMarker(card)
172-
send(cmd, 1)
172+
await send(cmd, 1)
173173
},
174174
},
175175
[CardsActionId.EditMarker]: {
@@ -181,10 +181,10 @@ export function createCardsActions(self: InstanceBaseExt<WingConfig>): Companion
181181
],
182182

183183
callback: async (event) => {
184-
const card = await getNumberWithVariables(event, 'card')
185-
const marker = await getNumberWithVariables(event, 'marker')
184+
const card = getNumberWithVariables(event, 'card')
185+
const marker = getNumberWithVariables(event, 'marker')
186186
const cmd = Commands.WLiveCardEditMarker(card)
187-
send(cmd, marker)
187+
await send(cmd, marker)
188188
},
189189
},
190190
[CardsActionId.GotoMarker]: {
@@ -196,10 +196,10 @@ export function createCardsActions(self: InstanceBaseExt<WingConfig>): Companion
196196
],
197197

198198
callback: async (event) => {
199-
const card = await getNumberWithVariables(event, 'card')
200-
const marker = await getNumberWithVariables(event, 'marker')
199+
const card = getNumberWithVariables(event, 'card')
200+
const marker = getNumberWithVariables(event, 'marker')
201201
const cmd = Commands.WLiveCardGotoMarker(card)
202-
send(cmd, marker)
202+
await send(cmd, marker)
203203
},
204204
},
205205
[CardsActionId.DeleteMarker]: {
@@ -211,20 +211,20 @@ export function createCardsActions(self: InstanceBaseExt<WingConfig>): Companion
211211
],
212212

213213
callback: async (event) => {
214-
const card = await getNumberWithVariables(event, 'card')
215-
const marker = await getNumberWithVariables(event, 'marker')
214+
const card = getNumberWithVariables(event, 'card')
215+
const marker = getNumberWithVariables(event, 'marker')
216216
const cmd = Commands.WLiveCardDeleteMarker(card)
217-
send(cmd, marker)
217+
await send(cmd, marker)
218218
},
219219
},
220220
[CardsActionId.FormatCard]: {
221221
name: 'WLive: Format Card',
222222
description: 'Format (delete all contents) of a card.',
223223
options: [...GetDropdownWithVariables('Card', 'card', getCardsChoices())],
224224
callback: async (event) => {
225-
const card = await getNumberWithVariables(event, 'card')
225+
const card = getNumberWithVariables(event, 'card')
226226
const cmd = Commands.WLiveCardFormat(card)
227-
send(cmd, 1)
227+
await send(cmd, 1)
228228
},
229229
},
230230
}

src/actions/channel.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ export enum ChannelActions {
1818
}
1919

2020
export function createChannelActions(self: InstanceBaseExt<WingConfig>): CompanionActionDefinitions {
21-
const send = self.sendCommand
22-
const ensureLoaded = self.ensureLoaded
23-
const state = self.state
21+
const send = self.connection!.sendCommand.bind(self.connection)
22+
const ensureLoaded = self.stateHandler!.ensureLoaded.bind(self.stateHandler)
23+
const state = self.stateHandler?.state
24+
if (!state) throw new Error('State handler or state is not available')
2425

2526
const actions: { [id in ChannelActions]: CompanionActionWithCallback | undefined } = {
2627
[ChannelActions.SetChannelFilterModel]: {
@@ -31,10 +32,10 @@ export function createChannelActions(self: InstanceBaseExt<WingConfig>): Compani
3132
...GetDropdownWithVariables('Filter', 'filter', getFilterModelOptions()),
3233
],
3334
callback: async (event) => {
34-
const channel = await ActionUtil.getStringWithVariables(event, 'channel')
35-
const filter = await ActionUtil.getStringWithVariables(event, 'filter')
35+
const channel = ActionUtil.getStringWithVariables(event, 'channel')
36+
const filter = ActionUtil.getStringWithVariables(event, 'filter')
3637
const cmd = Commands.FilterModel(ActionUtil.getNodeNumberFromID(channel))
37-
send(cmd, filter)
38+
await send(cmd, filter)
3839
},
3940
},
4041
[ChannelActions.SetChannelEqType]: {
@@ -45,10 +46,10 @@ export function createChannelActions(self: InstanceBaseExt<WingConfig>): Compani
4546
...GetDropdownWithVariables('EQ Model', 'model', EqModelChoice),
4647
],
4748
callback: async (event) => {
48-
const channel = await ActionUtil.getStringWithVariables(event, 'channel')
49-
const model = await ActionUtil.getStringWithVariables(event, 'model')
49+
const channel = ActionUtil.getStringWithVariables(event, 'channel')
50+
const model = ActionUtil.getStringWithVariables(event, 'model')
5051
const cmd = Commands.EqModel(ActionUtil.getNodeNumberFromID(channel))
51-
send(cmd, model)
52+
await send(cmd, model)
5253
},
5354
},
5455
[ChannelActions.SetChannelEqParameter]: {
@@ -61,7 +62,7 @@ export function createChannelActions(self: InstanceBaseExt<WingConfig>): Compani
6162
],
6263
callback: async (event) => {
6364
const cmd = Commands.EqModel(ActionUtil.getNodeNumber(event, 'channel'))
64-
send(cmd, ActionUtil.getString(event, 'model'))
65+
await send(cmd, ActionUtil.getString(event, 'model'))
6566
},
6667
subscribe: (event) => {
6768
ensureLoaded(Commands.EqModel(ActionUtil.getNodeNumber(event, 'channel')))
@@ -81,10 +82,10 @@ export function createChannelActions(self: InstanceBaseExt<WingConfig>): Compani
8182
...GetDropdownWithVariables('Order', 'order', getChannelProcessOrderChoices()),
8283
],
8384
callback: async (event) => {
84-
const channel = await ActionUtil.getStringWithVariables(event, 'channel')
85-
const order = await ActionUtil.getStringWithVariables(event, 'order')
85+
const channel = ActionUtil.getStringWithVariables(event, 'channel')
86+
const order = ActionUtil.getStringWithVariables(event, 'order')
8687
const cmd = Commands.ProcessOrder(ActionUtil.getNodeNumberFromID(channel))
87-
send(cmd, order)
88+
await send(cmd, order)
8889
},
8990
},
9091
}

0 commit comments

Comments
 (0)