Skip to content

Commit 2ce8776

Browse files
committed
fix(meteor): resolve action messages for child devices via parent studio
- Fall back to parent device studioAndConfigId when the target device has none - Matches the existing setStatus lookup pattern for subdevices like casparcg0
1 parent fbabd9c commit 2ce8776

2 files changed

Lines changed: 50 additions & 4 deletions

File tree

meteor/server/api/__tests__/peripheralDevice.resolveActionResult.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,41 @@ describe('resolveActionResult', () => {
158158
expect(resolved).toBe(result)
159159
})
160160

161+
it('resolves messages for child devices via the parent studio', async () => {
162+
const parentDeviceId = protectString<PeripheralDeviceId>('parent0')
163+
jest.spyOn(PeripheralDevices, 'findOneAsync').mockImplementation(async (id) => {
164+
if (id === deviceId) {
165+
return {
166+
name: 'casparcg0',
167+
parentDeviceId,
168+
} as any
169+
}
170+
if (id === parentDeviceId) {
171+
return {
172+
studioAndConfigId: { studioId, configId: 'config0' },
173+
} as any
174+
}
175+
return undefined
176+
})
177+
jest.spyOn(Studios, 'findOneAsync').mockResolvedValue({ blueprintId: 'blueprint0' } as any)
178+
jest.spyOn(Blueprints, 'findOneAsync').mockResolvedValue({
179+
_id: 'blueprint0',
180+
name: 'test',
181+
code: '',
182+
} as any)
183+
mockEvalBlueprint.mockReturnValue({
184+
deviceActionMessages: {
185+
[ACTION_ERROR_CODE]: 'Failed to trigger graphics at {{url}}: {{errorMessage}}',
186+
},
187+
} as any)
188+
189+
const resolved = await resolveActionResult(deviceId, makeErrorResult())
190+
191+
expect(resolved.response).toEqual({
192+
key: 'Failed to trigger graphics at http://graphics/api: connection refused',
193+
})
194+
})
195+
161196
it('returns the original result when the device has no studio', async () => {
162197
jest.spyOn(PeripheralDevices, 'findOneAsync').mockResolvedValue({
163198
name: 'Playout Gateway',

meteor/server/api/peripheralDevice.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,23 @@ export async function resolveActionResult(
220220

221221
try {
222222
const device = (await PeripheralDevices.findOneAsync(deviceId, {
223-
projection: { name: 1, studioAndConfigId: 1 },
224-
})) as Pick<PeripheralDevice, 'name' | 'studioAndConfigId'> | undefined
223+
projection: { name: 1, studioAndConfigId: 1, parentDeviceId: 1 },
224+
})) as Pick<PeripheralDevice, 'name' | 'studioAndConfigId' | 'parentDeviceId'> | undefined
225225

226-
if (!device?.studioAndConfigId?.studioId) return result
226+
if (!device) return result
227227

228-
const studioBlueprint = await getStudioBlueprintManifest(device.studioAndConfigId.studioId)
228+
// Child devices (like casparcg0) don't have studioAndConfigId directly - get it from parent
229+
let studioId = device.studioAndConfigId?.studioId
230+
if (!studioId && device.parentDeviceId) {
231+
const parentDevice = await PeripheralDevices.findOneAsync(device.parentDeviceId, {
232+
projection: { studioAndConfigId: 1 },
233+
})
234+
studioId = parentDevice?.studioAndConfigId?.studioId
235+
}
236+
237+
if (!studioId) return result
238+
239+
const studioBlueprint = await getStudioBlueprintManifest(studioId)
229240
if (!studioBlueprint) return result
230241

231242
const { blueprint, manifest: blueprintManifest } = studioBlueprint

0 commit comments

Comments
 (0)