@@ -110,24 +110,34 @@ export function getPieceStatusClassName(status: PieceStatusCode | undefined): st
110110 * It simulates the operations done by the playout operations in core and playout-gateway
111111 * and produces a list of Pieces across Parts timed relatively.
112112 *
113- * This method is primarily used by the GUI to visualize segments, but other functions
113+ * This method is primarily used by the GUI and the LSG to visualize/resolve segments, but other functions
114114 * utilize it as well when information about timing & time placement is needed.
115115 *
116116 * @export
117- * @param {ShowStyleBase } showStyleBase
118- * @param {UIStudio } studio
117+ * @param {DBShowStyleBase | UIShowStyleBase } showStyleBase
118+ * @param {UIStudio | undefined } studio
119119 * @param {DBRundownPlaylist } playlist
120+ * @param {Pick<Rundown, '_id' | 'showStyleBaseId'> } rundown
120121 * @param {DBSegment } segment
121122 * @param {Set<SegmentId> } segmentsToReceiveOnRundownEndFromSet
123+ * @param {RundownId[] } rundownsToReceiveOnShowStyleEndFrom
124+ * @param {ReadonlyMap<RundownId, ShowStyleBaseId> } rundownsToShowStyles
122125 * @param {PartId[] } orderedAllPartIds
123- * @param {PartInstance | undefined } currentPartInstance
124- * @param {PartInstance | undefined } nextPartInstance
125- * @param {boolean } [pieceInstanceSimulation=false] Can be used client-side to simulate the contents of a
126- * PartInstance, whose contents are being streamed in. When ran in a reactive context, the computation will
127- * be eventually invalidated so that the actual data can be streamed in (to show that the part is actually empty)
126+ * @param {PartInstance | undefined } nextPartInstance
127+ * @param {SegmentsFindOne } segmentsFindOne
128+ * @param {GetSegmentsAndPartsSync } getSegmentsAndPartsSync
129+ * @param {GetActivePartInstances } getActivePartInstances
130+ * @param {PiecesFind } piecesFind
131+ * @param {PieceInstancesFind } pieceInstancesFind
132+ * @param {GetCurrentTime } getCurrentTime
133+ * @param {((timeoutMs: number) => void) | undefined } [invalidateAfter] Optional callback triggered if the function returns simulated PieceInstances (fallback).
134+ * If provided, it will be executed with a timeout (ms) indicating when the simulation should be considered stale and the data should be re-evaluated.
135+ * Used to handle the data-sync gap during "Take" or "Next" operations.
128136 * @param {boolean } [includeDisabledPieces=false] In some uses (like when previewing a Segment in the GUI) it's needed
129137 * to consider disabled Piecess as where they are, instead of stripping them out. When enabled, the method will
130138 * keep them in the result set.
139+ * @param {boolean } [showHiddenSourceLayers=false]
140+ * @param {number } [defaultDisplayDuration=0]
131141 * @return {* } {({
132142 */
133143export function getResolvedSegment (
@@ -138,18 +148,17 @@ export function getResolvedSegment(
138148 segment : DBSegment ,
139149 segmentsToReceiveOnRundownEndFromSet : Set < SegmentId > ,
140150 rundownsToReceiveOnShowStyleEndFrom : RundownId [ ] ,
141- rundownsToShowstyles : ReadonlyMap < RundownId , ShowStyleBaseId > ,
151+ rundownsToShowStyles : ReadonlyMap < RundownId , ShowStyleBaseId > ,
142152 orderedAllPartIds : PartId [ ] ,
143153 currentPartInstance : PartInstance | undefined ,
144154 nextPartInstance : PartInstance | undefined ,
145- // TODO: Add new parameters to JSDOC
146155 segmentsFindOne : SegmentsFindOne ,
147156 getSegmentsAndPartsSync : GetSegmentsAndPartsSync ,
148157 getActivePartInstances : GetActivePartInstances ,
149158 piecesFind : PiecesFind ,
150159 pieceInstancesFind : PieceInstancesFind ,
151160 getCurrentTime : GetCurrentTime = ( ) => Date . now ( ) ,
152- pieceInstanceSimulation : boolean = false ,
161+ invalidateAfter : ( ( timeoutMs : number ) => void ) | undefined ,
153162 includeDisabledPieces : boolean = false ,
154163 showHiddenSourceLayers : boolean = false ,
155164 defaultDisplayDuration : number = 0 // I think 0 here is reasonable, and should be overridden by an actual value when used in a UI.
@@ -339,7 +348,7 @@ export function getResolvedSegment(
339348 new Set ( partIds . slice ( 0 , itIndex ) ) ,
340349 segmentsToReceiveOnRundownEndFromSet ,
341350 rundownsToReceiveOnShowStyleEndFrom ,
342- rundownsToShowstyles ,
351+ rundownsToShowStyles ,
343352 orderedAllPartIds ,
344353 nextPartIsAfterCurrentPart ,
345354 currentPartInstance ,
@@ -365,7 +374,7 @@ export function getResolvedSegment(
365374 getCurrentTime ,
366375 undefined ,
367376 pieceInstanceFieldOptions ,
368- pieceInstanceSimulation
377+ invalidateAfter
369378 )
370379
371380 const partTimes = createPartCurrentTimes ( getCurrentTime ( ) , partE . instance . timings ?. plannedStartedPlayback )
@@ -598,7 +607,6 @@ export function getResolvedSegment(
598607 // get the part immediately after the last segment
599608}
600609
601- // TODO: this can stay here
602610export function isAdlibActionContent (
603611 display : IBlueprintActionManifestDisplay | IBlueprintActionManifestDisplayContent
604612) : display is IBlueprintActionManifestDisplayContent {
@@ -626,6 +634,8 @@ export function deduplicatePartInstancesForQuickLoop<T extends Pick<PartInstance
626634 * @export
627635 * @param {DBRundownPlaylist } playlist
628636 * @param {(MongoQuery<DBSegment>) } [segmentsQuery]
637+ * @param {GetSegmentsAndPartsSync } [getSegmentsAndPartsSync]
638+ * @param {GetActivePartInstances } [getActivePartInstances]
629639 * @param {(MongoQuery<DBPart>) } [partsQuery]
630640 * @param {MongoQuery<PartInstance> } [partInstancesQuery]
631641 * @param {FindOptions<DBSegment> } [segmentsOptions]
@@ -635,10 +645,8 @@ export function deduplicatePartInstancesForQuickLoop<T extends Pick<PartInstance
635645 */
636646export function getSegmentsWithPartInstances (
637647 playlist : DBRundownPlaylist ,
638- // TODO: Add these to the JSDOC
639648 getSegmentsAndPartsSync : GetSegmentsAndPartsSync ,
640649 getActivePartInstances : GetActivePartInstances ,
641- // Old optional parameters continue below:
642650 segmentsQuery ?: MongoQuery < DBSegment > ,
643651 partsQuery ?: MongoQuery < DBPart > ,
644652 partInstancesQuery ?: MongoQuery < PartInstance > ,
@@ -750,10 +758,14 @@ const SIMULATION_INVALIDATION = 3000
750758 * @param {(PartInstance | undefined) } currentPartInstance
751759 * @param {(PieceInstance[] | undefined) } currentPartInstancePieceInstances
752760 * @param {boolean } allowTestingAdlibsToPersist Studio config parameter to allow infinite adlibs from adlib testing to persist in the rundown
761+ * @param {PiecesFind } [piecesFind]
762+ * @param {PieceInstancesFind } [pieceInstancesFind]
763+ * @param {GetCurrentTime } [getCurrentTime]
764+ * @param {Map<PartId | null, Piece[]> } [allPiecesCache]
753765 * @param {FindOptions<PieceInstance> } [options]
754- * @param {boolean } [pieceInstanceSimulation] If there are no PieceInstances in the PartInstance, create temporary
755- * PieceInstances based on the Pieces collection and register a reactive dependency to recalculate the current
756- * computation after some time to return the actual PieceInstances for the PartInstance .
766+ * @param {((timeoutMs: number) => void) } [invalidateAfter] Optional callback triggered if the function returns simulated PieceInstances (fallback).
767+ * If provided, it will be executed with a timeout (ms) indicating when the simulation should be considered stale and the data should be re-evaluated.
768+ * Used to handle the data-sync gap during "Take" or "Next" operations .
757769 * @return {* }
758770 */
759771export function getPieceInstancesForPartInstance (
@@ -771,14 +783,12 @@ export function getPieceInstancesForPartInstance(
771783 currentSegment : Pick < DBSegment , '_id' | 'orphaned' > | undefined ,
772784 currentPartInstancePieceInstances : PieceInstance [ ] | undefined ,
773785 allowTestingAdlibsToPersist : boolean ,
774- // TODO: Add JSDOC for new parameters:
775786 piecesFind : PiecesFind ,
776787 pieceInstancesFind : PieceInstancesFind ,
777788 getCurrentTime : GetCurrentTime = ( ) => Date . now ( ) ,
778- /** Map of Pieces on Parts, passed through for performance */
779789 allPiecesCache ?: Map < PartId | null , Piece [ ] > ,
780790 options ?: FindOptions < PieceInstance > ,
781- pieceInstanceSimulation ?: boolean
791+ invalidateAfter ?: ( timeoutMs : number ) => void
782792) : PieceInstance [ ] {
783793 if ( segment . orphaned === SegmentOrphanedReason . ADLIB_TESTING ) {
784794 // When in the AdlibTesting segment, don't allow searching other segments/rundowns for infinites to continue
@@ -821,21 +831,19 @@ export function getPieceInstancesForPartInstance(
821831 ? currentPartInstancePieceInstances
822832 : pieceInstancesFind ( { partInstanceId : partInstance . _id } , options )
823833 // check if we can return the results immediately
824- if ( results . length > 0 || ! pieceInstanceSimulation ) return results
834+ if ( results . length > 0 || ! invalidateAfter ) return results
825835
826836 // if a simulation has been requested and less than SIMULATION_INVALIDATION time has passed
827837 // since the PartInstance has been nexted or taken, simulate the PieceInstances using the Piece collection.
828838 const now = getCurrentTime ( )
829839 if (
830- pieceInstanceSimulation &&
831840 results . length === 0 &&
832841 ( ! partInstance . timings ||
833842 ( partInstance . timings . setAsNext || 0 ) > now - SIMULATION_INVALIDATION ||
834843 ( partInstance . timings . take || 0 ) > now - SIMULATION_INVALIDATION )
835844 ) {
836- // TODO: figure out invalidation here
837845 // make sure to invalidate the current computation after SIMULATION_INVALIDATION has passed
838- // invalidateAfter(SIMULATION_INVALIDATION)
846+ invalidateAfter ( SIMULATION_INVALIDATION )
839847
840848 return getPieceInstancesForPart (
841849 playlistActivationId || protectString ( '' ) ,
0 commit comments