1- import { PartId , PeripheralDeviceId , RundownId , RundownPlaylistId } from '@sofie-automation/corelib/dist/dataModel/Ids'
1+ import { PeripheralDeviceId , RundownId , RundownPlaylistId } from '@sofie-automation/corelib/dist/dataModel/Ids'
22import { ReadonlyDeep } from 'type-fest'
33import {
44 CustomPublishCollection ,
88 TriggerUpdate ,
99} from '../../lib/customPublication'
1010import { logger } from '../../logging'
11- import { ContentCache , createReactiveContentCache , PartInstanceFields } from './reactiveContentCache'
11+ import { ContentCache , createReactiveContentCache } from './reactiveContentCache'
1212import { RundownsObserver } from '../lib/rundownsObserver'
1313import { RundownContentObserver } from './rundownContentObserver'
1414import {
@@ -17,12 +17,10 @@ import {
1717} from '@sofie-automation/shared-lib/dist/pubsub/peripheralDevice'
1818import { checkAccessAndGetPeripheralDevice } from '../../security/check'
1919import { check } from '../../lib/check'
20- import { IngestPartPlaybackStatus , IngestRundownStatus } from '@sofie-automation/shared-lib/dist/ingest/rundownStatus'
20+ import { IngestRundownStatus } from '@sofie-automation/shared-lib/dist/ingest/rundownStatus'
2121import { protectString } from '@sofie-automation/corelib/dist/protectedString'
2222import { DBRundown } from '@sofie-automation/corelib/dist/dataModel/Rundown'
23- import { NrcsIngestCacheType } from '@sofie-automation/corelib/dist/dataModel/NrcsIngestDataCache'
24- import _ from 'underscore'
25- import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
23+ import { createIngestRundownStatus } from './createIngestRundownStatus'
2624
2725interface IngestRundownStatusArgs {
2826 readonly deviceId : PeripheralDeviceId
@@ -137,7 +135,7 @@ async function manipulateIngestRundownStatusPublicationData(
137135 const knownRundownIds = new Set ( state . contentCache . RundownIds )
138136
139137 for ( const rundownId of knownRundownIds ) {
140- const newDoc = regenerateForRundown ( state . contentCache , rundownId )
138+ const newDoc = createIngestRundownStatus ( state . contentCache , rundownId )
141139 if ( newDoc ) collection . replace ( newDoc )
142140 }
143141 } else {
@@ -162,7 +160,7 @@ async function manipulateIngestRundownStatusPublicationData(
162160 }
163161
164162 for ( const rundownId of regenerateForRundownIds ) {
165- const newDoc = regenerateForRundown ( state . contentCache , rundownId )
163+ const newDoc = createIngestRundownStatus ( state . contentCache , rundownId )
166164 if ( newDoc ) {
167165 collection . replace ( newDoc )
168166 } else {
@@ -172,99 +170,6 @@ async function manipulateIngestRundownStatusPublicationData(
172170 }
173171}
174172
175- function regenerateForRundown ( cache : ReadonlyDeep < ContentCache > , rundownId : RundownId ) : IngestRundownStatus | null {
176- const rundown = cache . Rundowns . findOne ( rundownId )
177- if ( ! rundown ) return null
178-
179- const newDoc : IngestRundownStatus = {
180- _id : rundownId ,
181- externalId : rundown . externalId ,
182-
183- active : 'inactive' ,
184-
185- segments : [ ] ,
186- }
187-
188- const playlist = cache . Playlists . findOne ( {
189- _id : rundown . playlistId ,
190- activationId : { $exists : true } ,
191- } )
192-
193- if ( playlist ) {
194- newDoc . active = playlist . rehearsal ? 'rehearsal' : 'active'
195- }
196-
197- // Find the most important part instance for each part
198- const partInstanceMap = new Map < PartId , Pick < DBPartInstance , PartInstanceFields > > ( )
199- if ( playlist ) {
200- for ( const partInstance of cache . PartInstances . find ( { } ) . fetch ( ) ) {
201- if ( partInstance . rundownId !== rundownId ) continue
202- // Ignore the next partinstance
203- if ( partInstance . _id === playlist . nextPartInfo ?. partInstanceId ) continue
204-
205- // The current part instance is the most important
206- if ( partInstance . _id === playlist . currentPartInfo ?. partInstanceId ) {
207- partInstanceMap . set ( partInstance . part . _id , partInstance )
208- continue
209- }
210-
211- // Take the part with the highest takeCount
212- const existingEntry = partInstanceMap . get ( partInstance . part . _id )
213- if ( ! existingEntry || existingEntry . takeCount < partInstance . takeCount ) {
214- partInstanceMap . set ( partInstance . part . _id , partInstance )
215- }
216- }
217- }
218-
219- const nrcsSegments = cache . NrcsIngestData . find ( { rundownId, type : NrcsIngestCacheType . SEGMENT } ) . fetch ( )
220- for ( const nrcsSegment of nrcsSegments ) {
221- const nrcsParts = cache . NrcsIngestData . find ( {
222- rundownId,
223- segmentId : nrcsSegment . segmentId ,
224- type : NrcsIngestCacheType . PART ,
225- } ) . fetch ( )
226-
227- newDoc . segments . push ( {
228- externalId : nrcsSegment . data . externalId ,
229- parts : _ . compact (
230- nrcsParts . map ( ( nrcsPart ) => {
231- if ( ! nrcsPart . partId || ! nrcsPart . segmentId ) return null
232-
233- const part = cache . Parts . findOne ( { _id : nrcsPart . partId , rundownId } )
234- const partInstance = partInstanceMap . get ( nrcsPart . partId )
235-
236- // Determine the playback status from the PartInstance
237- let playbackStatus = IngestPartPlaybackStatus . UNKNOWN
238- if ( playlist && partInstance && partInstance . part . shouldNotifyCurrentPlayingPart ) {
239- const isCurrentPartInstance = playlist . currentPartInfo ?. partInstanceId === partInstance . _id
240-
241- if ( isCurrentPartInstance ) {
242- // If the current, it is playing
243- playbackStatus = IngestPartPlaybackStatus . PLAY
244- } else {
245- // If not the current, but has been played, it is stopped
246- playbackStatus = IngestPartPlaybackStatus . STOP
247- }
248- }
249-
250- // Determine the ready status from the PartInstance or Part
251- const isReady = partInstance ? partInstance . part . ingestNotifyPartReady : part ?. ingestNotifyPartReady
252-
253- return {
254- externalId : nrcsPart . data . externalId ,
255-
256- isReady : isReady ?? null ,
257-
258- playbackStatus,
259- }
260- } )
261- ) ,
262- } )
263- }
264-
265- return newDoc
266- }
267-
268173meteorCustomPublish (
269174 PeripheralDevicePubSub . ingestDeviceRundownStatus ,
270175 PeripheralDevicePubSubCollectionsNames . ingestRundownStatus ,
0 commit comments