Skip to content

Commit 39ff60d

Browse files
authored
feat: add ITTimersContext to IPartEventContext (Sofie-Automation#1705)
1 parent 446e86b commit 39ff60d

5 files changed

Lines changed: 61 additions & 35 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ export interface ShowStyleBlueprintManifest<
228228
playoutPersistentState: BlueprintPlayoutPersistentStore<TimelinePersistentState>
229229
) => Promise<void>
230230
/** Called after a Take action */
231-
onPostTake?: (context: IPartEventContext) => Promise<void>
231+
onPostTake?: (
232+
context: IPartEventContext,
233+
playoutPersistentState: BlueprintPlayoutPersistentStore<TimelinePersistentState>
234+
) => Promise<void>
232235

233236
/**
234237
* Called when a part is set as Next, including right after a Take.

packages/blueprints-integration/src/context/eventContext.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type { OnGenerateTimelineObj, TSR } from '../timeline.js'
22
import type { IBlueprintPartInstance, IBlueprintPieceInstance, IBlueprintSegmentDB } from '../documents/index.js'
33
import type { IRundownContext } from './rundownContext.js'
44
import type { IBlueprintExternalMessageQueueObj } from '../message.js'
5-
import { BlueprintQuickLookInfo } from './quickLoopInfo.js'
5+
import type { BlueprintQuickLookInfo } from './quickLoopInfo.js'
6+
import type { ITTimersContext } from './tTimersContext.js'
67

78
export interface IEventContext {
89
getCurrentTime(): number
@@ -33,7 +34,7 @@ export interface ITimelineEventContext extends IEventContext, IRundownContext {
3334
): string | undefined
3435
}
3536

36-
export interface IPartEventContext extends IEventContext, IRundownContext {
37+
export interface IPartEventContext extends IEventContext, IRundownContext, ITTimersContext {
3738
readonly part: Readonly<IBlueprintPartInstance>
3839
}
3940

packages/job-worker/src/blueprints/__tests__/context-events.test.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { ReadonlyDeep } from 'type-fest'
1414
import { convertPartInstanceToBlueprints } from '../context/lib.js'
1515
import { EmptyPieceTimelineObjectsBlob } from '@sofie-automation/corelib/dist/dataModel/Piece'
1616
import { ProcessedShowStyleCompound } from '../../jobs/index.js'
17+
import type { PlayoutModel } from '../../playout/model/PlayoutModel.js'
18+
import { mock } from 'jest-mock-extended'
1719

1820
describe('Test blueprint api context', () => {
1921
async function generateSparsePieceInstances(rundown: DBRundown) {
@@ -76,22 +78,25 @@ describe('Test blueprint api context', () => {
7678
)) as DBRundownPlaylist
7779
expect(playlist).toBeTruthy()
7880

79-
const showStyleConfig = jobContext.getShowStyleBlueprintConfig(showStyle)
81+
const playoutModel = mock<PlayoutModel>()
82+
const mockPlaylist = {
83+
tTimers: [
84+
{ index: 1, label: 'Timer 1', mode: null, state: null },
85+
{ index: 2, label: 'Timer 2', mode: null, state: null },
86+
{ index: 3, label: 'Timer 3', mode: null, state: null },
87+
],
88+
} as unknown as ReadonlyDeep<DBRundownPlaylist>
89+
Object.defineProperty(playoutModel, 'playlist', {
90+
get: () => mockPlaylist,
91+
configurable: true,
92+
})
8093

8194
const mockPart = {
8295
_id: protectString('not-a-real-part'),
8396
}
8497

8598
const tmpPart = wrapPartToTemporaryInstance(protectString('active'), mockPart as DBPart)
86-
const context = new PartEventContext(
87-
'fake',
88-
jobContext.studio,
89-
jobContext.getStudioBlueprintConfig(),
90-
showStyle,
91-
showStyleConfig,
92-
rundown,
93-
tmpPart
94-
)
99+
const context = new PartEventContext(jobContext, playoutModel, 'fake', showStyle, rundown, tmpPart)
95100
expect(context.studio).toBeTruthy()
96101

97102
expect(context.part).toEqual(convertPartInstanceToBlueprints(tmpPart))
Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
import { IBlueprintPartInstance, IPartEventContext } from '@sofie-automation/blueprints-integration'
2-
import { ReadonlyDeep } from 'type-fest'
3-
import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
4-
import { DBRundown } from '@sofie-automation/corelib/dist/dataModel/Rundown'
1+
import type { IBlueprintPartInstance, IPartEventContext } from '@sofie-automation/blueprints-integration'
2+
import type { ReadonlyDeep } from 'type-fest'
3+
import type { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
4+
import type { DBRundown } from '@sofie-automation/corelib/dist/dataModel/Rundown'
55
import { getCurrentTime } from '../../lib/index.js'
6-
import { ProcessedStudioConfig, ProcessedShowStyleConfig } from '../config.js'
7-
import { JobStudio, ProcessedShowStyleCompound } from '../../jobs/index.js'
6+
import type { JobContext, ProcessedShowStyleCompound } from '../../jobs/index.js'
87
import { convertPartInstanceToBlueprints } from './lib.js'
98
import { RundownContext } from './RundownContext.js'
9+
import { TTimersService } from './services/TTimersService.js'
10+
import type { PlayoutModel } from '../../playout/model/PlayoutModel.js'
11+
import type { IPlaylistTTimer } from '@sofie-automation/blueprints-integration/dist/context/tTimersContext'
12+
import type { RundownTTimerIndex } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
1013

1114
export class PartEventContext extends RundownContext implements IPartEventContext {
15+
readonly #tTimersService: TTimersService
16+
1217
readonly part: Readonly<IBlueprintPartInstance>
1318

1419
constructor(
20+
context: JobContext,
21+
playoutModel: PlayoutModel,
1522
eventName: string,
16-
studio: ReadonlyDeep<JobStudio>,
17-
studioBlueprintConfig: ProcessedStudioConfig,
1823
showStyleCompound: ReadonlyDeep<ProcessedShowStyleCompound>,
19-
showStyleBlueprintConfig: ProcessedShowStyleConfig,
2024
rundown: ReadonlyDeep<DBRundown>,
2125
partInstance: ReadonlyDeep<DBPartInstance>
2226
) {
@@ -25,17 +29,25 @@ export class PartEventContext extends RundownContext implements IPartEventContex
2529
name: `Event: ${eventName}`,
2630
identifier: `rundownId=${rundown._id},blueprintId=${showStyleCompound.blueprintId}`,
2731
},
28-
studio,
29-
studioBlueprintConfig,
32+
context.studio,
33+
context.getStudioBlueprintConfig(),
3034
showStyleCompound,
31-
showStyleBlueprintConfig,
35+
context.getShowStyleBlueprintConfig(showStyleCompound),
3236
rundown
3337
)
3438

39+
this.#tTimersService = TTimersService.withPlayoutModel(playoutModel, context)
3540
this.part = convertPartInstanceToBlueprints(partInstance)
3641
}
3742

3843
getCurrentTime(): number {
3944
return getCurrentTime()
4045
}
46+
47+
getTimer(index: RundownTTimerIndex): IPlaylistTTimer {
48+
return this.#tTimersService.getTimer(index)
49+
}
50+
clearAllTimers(): void {
51+
this.#tTimersService.clearAllTimers()
52+
}
4153
}

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,10 @@ export async function performTakeToNextedPart(
259259
try {
260260
await blueprint.blueprint.onPreTake(
261261
new PartEventContext(
262+
context,
263+
playoutModel,
262264
'onPreTake',
263-
context.studio,
264-
context.getStudioBlueprintConfig(),
265265
showStyle,
266-
context.getShowStyleBlueprintConfig(showStyle),
267266
takeRundown.rundown,
268267
takePartInstance.partInstance
269268
)
@@ -501,11 +500,10 @@ async function afterTakeUpdateTimingsAndEvents(
501500
try {
502501
await blueprint.blueprint.onRundownFirstTake(
503502
new PartEventContext(
503+
context,
504+
playoutModel,
504505
'onRundownFirstTake',
505-
context.studio,
506-
context.getStudioBlueprintConfig(),
507506
showStyle,
508-
context.getShowStyleBlueprintConfig(showStyle),
509507
takeRundown.rundown,
510508
takePartInstance.partInstance
511509
)
@@ -520,17 +518,24 @@ async function afterTakeUpdateTimingsAndEvents(
520518
if (blueprint.blueprint.onPostTake && takeRundown) {
521519
const span = context.startSpan('blueprint.onPostTake')
522520
try {
521+
const blueprintPersistentState = new PersistentPlayoutStateStore(
522+
playoutModel.playlist.privatePlayoutPersistentState,
523+
playoutModel.playlist.publicPlayoutPersistentState
524+
)
525+
523526
await blueprint.blueprint.onPostTake(
524527
new PartEventContext(
528+
context,
529+
playoutModel,
525530
'onPostTake',
526-
context.studio,
527-
context.getStudioBlueprintConfig(),
528531
showStyle,
529-
context.getShowStyleBlueprintConfig(showStyle),
530532
takeRundown.rundown,
531533
takePartInstance.partInstance
532-
)
534+
),
535+
blueprintPersistentState
533536
)
537+
538+
blueprintPersistentState.saveToModel(playoutModel)
534539
} catch (err) {
535540
logger.error(`Error in showStyleBlueprint.onPostTake: ${stringifyError(err)}`)
536541
}

0 commit comments

Comments
 (0)