Skip to content

Commit 4d34cec

Browse files
authored
feat: Set sub-device peripheralDeviceId from deviceOptions parentDeviceName (#1505)
1 parent ec399ee commit 4d34cec

File tree

2 files changed

+49
-25
lines changed

2 files changed

+49
-25
lines changed

packages/blueprints-integration/src/api/studio.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ export interface BlueprintResultApplyStudioConfig {
155155
/** Parent device settings */
156156
parentDevices: Record<string, BlueprintParentDeviceSettings>
157157
/** Playout-gateway subdevices */
158-
playoutDevices: Record<string, TSR.DeviceOptionsAny>
158+
playoutDevices: Record<string, { parentDeviceName?: string; options: TSR.DeviceOptionsAny }>
159159
/** Ingest-gateway subdevices, the types here depend on the gateway you use */
160-
ingestDevices: Record<string, BlueprintMosDeviceConfig | unknown>
160+
ingestDevices: Record<string, { parentDeviceName?: string; options: BlueprintMosDeviceConfig | unknown }>
161161
/** Input-gateway subdevices */
162-
inputDevices: Record<string, unknown>
162+
inputDevices: Record<string, { parentDeviceName?: string; options: unknown }>
163163
/** Route Sets */
164164
routeSets?: Record<string, StudioRouteSet>
165165
/** Route Set Exclusivity Groups */

packages/job-worker/src/playout/upgrade.ts

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { CommonContext } from '../blueprints/context/index.js'
3030
import { JobContext } from '../jobs/index.js'
3131
import { FixUpBlueprintConfigContext } from '@sofie-automation/corelib/dist/fixUpBlueprintConfig/context'
3232
import { DEFAULT_MINIMUM_TAKE_SPAN } from '@sofie-automation/shared-lib/dist/core/constants'
33+
import { PERIPHERAL_SUBTYPE_PROCESS, PeripheralDevice } from '@sofie-automation/corelib/dist/dataModel/PeripheralDevice'
3334

3435
/**
3536
* Run the Blueprint applyConfig for the studio
@@ -58,37 +59,60 @@ export async function handleBlueprintUpgradeForStudio(context: JobContext, _data
5859
dev[0],
5960
literal<Complete<StudioDeviceSettings>>({
6061
name: dev[1].name ?? '',
61-
options: dev[1],
62+
options: dev[1].options ?? {},
6263
}),
6364
])
6465
)
66+
67+
const peripheralDevices = (await context.directCollections.PeripheralDevices.findFetch(
68+
{ subType: PERIPHERAL_SUBTYPE_PROCESS, 'studioAndConfigId.studioId': context.studioId },
69+
{ projection: { _id: 1, studioAndConfigId: 1 } }
70+
)) as Array<Pick<PeripheralDevice, '_id' | 'studioAndConfigId'>>
71+
6572
const playoutDevices = Object.fromEntries(
66-
Object.entries<TSR.DeviceOptionsAny>(result.playoutDevices ?? {}).map((dev) => [
67-
dev[0],
68-
literal<Complete<StudioPlayoutDevice>>({
69-
peripheralDeviceId: undefined,
70-
options: dev[1],
71-
}),
72-
])
73+
Object.entries<{ parentDeviceName?: string; options: TSR.DeviceOptionsAny }>(result.playoutDevices ?? {}).map(
74+
(dev) => {
75+
return [
76+
dev[0],
77+
literal<Complete<StudioPlayoutDevice>>({
78+
peripheralDeviceId: peripheralDevices.find(
79+
(p) => p.studioAndConfigId?.configId === dev[1].parentDeviceName
80+
)?._id,
81+
options: dev[1].options,
82+
}),
83+
]
84+
}
85+
)
7386
)
87+
7488
const ingestDevices = Object.fromEntries(
75-
Object.entries<unknown>(result.ingestDevices ?? {}).map((dev) => [
76-
dev[0],
77-
literal<Complete<StudioIngestDevice>>({
78-
peripheralDeviceId: undefined,
79-
options: dev[1],
80-
}),
81-
])
89+
Object.entries<{ parentDeviceName?: string; options: unknown }>(result.ingestDevices ?? {}).map((dev) => {
90+
return [
91+
dev[0],
92+
literal<Complete<StudioIngestDevice>>({
93+
peripheralDeviceId: peripheralDevices.find(
94+
(p) => p.studioAndConfigId?.configId === dev[1].parentDeviceName
95+
)?._id,
96+
options: dev[1].options,
97+
}),
98+
]
99+
})
82100
)
101+
83102
const inputDevices = Object.fromEntries(
84-
Object.entries<unknown>(result.inputDevices ?? {}).map((dev) => [
85-
dev[0],
86-
literal<Complete<StudioInputDevice>>({
87-
peripheralDeviceId: undefined,
88-
options: dev[1],
89-
}),
90-
])
103+
Object.entries<{ parentDeviceName?: string; options: unknown }>(result.inputDevices ?? {}).map((dev) => {
104+
return [
105+
dev[0],
106+
literal<Complete<StudioInputDevice>>({
107+
peripheralDeviceId: peripheralDevices.find(
108+
(p) => p.studioAndConfigId?.configId === dev[1].parentDeviceName
109+
)?._id,
110+
options: dev[1].options,
111+
}),
112+
]
113+
})
91114
)
115+
92116
const routeSets = Object.fromEntries(
93117
Object.entries<Partial<StudioRouteSet>>(result.routeSets ?? {}).map((dev) => [
94118
dev[0],

0 commit comments

Comments
 (0)