1- import {
2- NotifyCurrentlyPlayingPartProps ,
3- PartInstanceTimingsProps ,
4- RundownDataChangedProps ,
5- } from '@sofie-automation/corelib/dist/worker/events'
1+ import { PartInstanceTimingsProps , RundownDataChangedProps } from '@sofie-automation/corelib/dist/worker/events'
62import { getCurrentTime } from '../lib'
73import { JobContext } from '../jobs'
84import { logger } from '../logging'
@@ -17,16 +13,7 @@ import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyE
1713import { ExternalMessageQueueObj } from '@sofie-automation/corelib/dist/dataModel/ExternalMessageQueue'
1814import { ICollection , MongoModifier } from '../db'
1915import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
20- import { ExternalMessageQueueObjId , PeripheralDeviceId } from '@sofie-automation/corelib/dist/dataModel/Ids'
21- import { runWithRundownLock } from '../ingest/lock'
22- import {
23- PeripheralDevice ,
24- PeripheralDeviceCategory ,
25- PeripheralDeviceType ,
26- } from '@sofie-automation/corelib/dist/dataModel/PeripheralDevice'
27- import { MOS } from '@sofie-automation/corelib'
28- import { executePeripheralDeviceFunction } from '../peripheralDevice'
29- import { DEFAULT_MOS_TIMEOUT_TIME } from '@sofie-automation/shared-lib/dist/core/constants'
16+ import { ExternalMessageQueueObjId } from '@sofie-automation/corelib/dist/dataModel/Ids'
3017
3118async function getBlueprintAndDependencies ( context : JobContext , rundown : ReadonlyDeep < DBRundown > ) {
3219 const pShowStyle = context . getShowStyleCompound ( rundown . showStyleVariantId , rundown . showStyleBaseId )
@@ -226,121 +213,3 @@ export async function handleRundownDataHasChanged(context: JobContext, data: Run
226213 logger . error ( `Error in showStyleBlueprint.onRundownDataChangedEvent: ${ stringifyError ( err ) } ` )
227214 }
228215}
229-
230- export async function handleNotifyCurrentlyPlayingPart (
231- context : JobContext ,
232- data : NotifyCurrentlyPlayingPartProps
233- ) : Promise < void > {
234- const rundown = await context . directCollections . Rundowns . findOne ( data . rundownId )
235- if ( ! rundown ) {
236- logger . warn ( `Rundown "${ data . rundownId } is missing. Skipping notifyCurrentPlayingPart` )
237- return
238- }
239-
240- if ( rundown . source . type !== 'nrcs' ) {
241- logger . warn ( `Rundown "${ rundown . _id } has no peripheralDevice. Skipping notifyCurrentPlayingPart` )
242- return
243- }
244-
245- const device = await context . directCollections . PeripheralDevices . findOne ( {
246- _id : rundown . source . peripheralDeviceId ,
247- // Future: we really should be constraining this to the studio, but that is often only defined on the parent of this device
248- // studioId: context.studioId,
249- parentDeviceId : { $exists : true } ,
250- } )
251- if ( ! device || ! device . parentDeviceId ) {
252- logger . warn (
253- `PeripheralDevice "${ rundown . source . peripheralDeviceId } " for Rundown "${ rundown . _id } not found. Skipping notifyCurrentPlayingPart`
254- )
255- return
256- }
257- const parentDevice = await context . directCollections . PeripheralDevices . findOne ( {
258- _id : device . parentDeviceId ,
259- studioId : context . studioId ,
260- parentDeviceId : { $exists : false } ,
261- } )
262- if ( ! parentDevice ) {
263- logger . warn (
264- `PeripheralDevice "${ rundown . source . peripheralDeviceId } " for Rundown "${ rundown . _id } not found. Skipping notifyCurrentPlayingPart`
265- )
266- return
267- }
268-
269- const previousPlayingPartExternalId : string | null = rundown . notifiedCurrentPlayingPartExternalId || null
270- const currentPlayingPartExternalId : string | null = data . isRehearsal ? null : data . partExternalId
271-
272- // Lock the rundown so that we are allowed to write to it
273- // This is technically a bit of a race condition, but is really low risk and low impact if it does
274- await runWithRundownLock ( context , rundown . _id , async ( rundown0 ) => {
275- if ( ! rundown0 ) return
276-
277- await context . directCollections . Rundowns . update (
278- rundown . _id ,
279- currentPlayingPartExternalId
280- ? {
281- $set : {
282- notifiedCurrentPlayingPartExternalId : currentPlayingPartExternalId ,
283- } ,
284- }
285- : {
286- $unset : {
287- notifiedCurrentPlayingPartExternalId : 1 ,
288- } ,
289- }
290- )
291- } )
292-
293- // TODO: refactor this to be non-mos centric
294- if ( device . category === PeripheralDeviceCategory . INGEST && device . type === PeripheralDeviceType . MOS ) {
295- // Note: rundown may not be up to date anymore
296- await notifyCurrentPlayingPartMOS (
297- context ,
298- device ,
299- rundown . externalId ,
300- previousPlayingPartExternalId ,
301- currentPlayingPartExternalId
302- )
303- }
304- }
305-
306- async function notifyCurrentPlayingPartMOS (
307- context : JobContext ,
308- peripheralDevice : PeripheralDevice ,
309- rundownExternalId : string ,
310- oldPlayingPartExternalId : string | null ,
311- newPlayingPartExternalId : string | null
312- ) : Promise < void > {
313- if ( oldPlayingPartExternalId !== newPlayingPartExternalId ) {
314- // New implementation 2022 only sends PLAY, never stop, after getting advice from AP
315- // Reason 1: NRK ENPS "sendt tid" (elapsed time) stopped working in ENPS 8/9 when doing STOP prior to PLAY
316- // Reason 2: there's a delay between the STOP (yellow line disappears) and PLAY (yellow line re-appears), which annoys the users
317- if ( newPlayingPartExternalId ) {
318- try {
319- await setStoryStatusMOS (
320- context ,
321- peripheralDevice . _id ,
322- rundownExternalId ,
323- newPlayingPartExternalId ,
324- MOS . IMOSObjectStatus . PLAY
325- )
326- } catch ( error ) {
327- logger . error ( `Error in setStoryStatus PLAY: ${ stringifyError ( error ) } ` )
328- }
329- }
330- }
331- }
332-
333- async function setStoryStatusMOS (
334- context : JobContext ,
335- deviceId : PeripheralDeviceId ,
336- rundownExternalId : string ,
337- storyId : string ,
338- status : MOS . IMOSObjectStatus
339- ) : Promise < void > {
340- logger . debug ( 'setStoryStatus' , { deviceId, externalId : rundownExternalId , storyId, status } )
341- return executePeripheralDeviceFunction ( context , deviceId , DEFAULT_MOS_TIMEOUT_TIME + 1000 , 'setStoryStatus' , [
342- rundownExternalId ,
343- storyId ,
344- status ,
345- ] )
346- }
0 commit comments