Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ReadonlyDeep } from 'type-fest'
import {
IBlueprintMutatablePart,
IBlueprintPart,
Expand Down Expand Up @@ -48,6 +49,13 @@ export interface IPartAndPieceActionContext {
/** Gets the Segment. This primarily allows for accessing metadata */
getSegment(segment: 'current' | 'next'): Promise<IBlueprintSegment | undefined>

/** Get a list of the upcoming Parts in the Rundown, in the order that they will be Taken
*
* @param limit The max number of parts returned. Default is 5.
* @returns An array of Parts. If there is no next part, the array will be empty.
*/
getUpcomingParts(limit?: number): Promise<ReadonlyDeep<IBlueprintPart[]>>

/**
* Creative actions
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
/* eslint-disable @typescript-eslint/unbound-method */
import { IBlueprintMutatablePart, IBlueprintPiece } from '@sofie-automation/blueprints-integration'
import { PlayoutModel } from '../../playout/model/PlayoutModel.js'
import { WatchedPackagesHelper } from '../context/watchedPackages.js'
import { JobContext, ProcessedShowStyleCompound } from '../../jobs/index.js'
import { mock } from 'jest-mock-extended'
import { PartAndPieceInstanceActionService } from '../context/services/PartAndPieceInstanceActionService.js'
import { OnTakeContext } from '../context/index.js'
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
import { PlayoutModelImpl } from '../../playout/model/implementation/PlayoutModelImpl.js'

describe('Test blueprint api context', () => {
async function getTestee() {
const mockPlayoutModel = mock<PlayoutModelImpl>()
const mockActionService = mock<PartAndPieceInstanceActionService>()
const context = new OnTakeContext(
{
name: 'fakeContext',
identifier: 'action',
},
mock<JobContext>(),
mock<PlayoutModel>(),
mockPlayoutModel,
mock<ProcessedShowStyleCompound>(),
mock<WatchedPackagesHelper>(),
mockActionService
Expand All @@ -25,6 +27,7 @@ describe('Test blueprint api context', () => {
return {
context,
mockActionService,
mockPlayoutModel,
}
}

Expand Down Expand Up @@ -99,6 +102,20 @@ describe('Test blueprint api context', () => {
expect(mockActionService.getPartForPreviousPiece).toHaveBeenCalledWith({ _id: 'pieceId' })
})

test('getUpcomingParts', async () => {
const { context, mockPlayoutModel } = await getTestee()

mockPlayoutModel.getAllOrderedParts.mockReturnValue(
mock([
{ _id: 'part1', title: 'Part 1', invalid: false, floated: false } as unknown as DBPart,
{ _id: 'part2', title: 'Part 2', invalid: false, floated: false } as unknown as DBPart,
])
)

const parts = await context.getUpcomingParts()
expect(parts.map((i) => i.title)).toEqual(['Part 1', 'Part 2'])
})

test('insertPiece', async () => {
const { context, mockActionService } = await getTestee()

Expand Down
5 changes: 5 additions & 0 deletions packages/job-worker/src/blueprints/context/OnTakeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { JobContext, ProcessedShowStyleCompound } from '../../jobs/index.js'
import { executePeripheralDeviceAction, listPlayoutDevices } from '../../peripheralDevice.js'
import { ActionPartChange, PartAndPieceInstanceActionService } from './services/PartAndPieceInstanceActionService.js'
import { BlueprintQuickLookInfo } from '@sofie-automation/blueprints-integration/dist/context/quickLoopInfo'
import { getOrderedPartsAfterPlayhead } from '../../playout/lookahead/util.js'

export class OnTakeContext extends ShowStyleUserContext implements IOnTakeContext, IEventContext {
public isTakeAborted: boolean
Expand Down Expand Up @@ -52,6 +53,10 @@ export class OnTakeContext extends ShowStyleUserContext implements IOnTakeContex
this.isTakeAborted = false
}

async getUpcomingParts(limit: number = 5): Promise<ReadonlyDeep<IBlueprintPart[]>> {
return getOrderedPartsAfterPlayhead(this._context, this._playoutModel, limit)
}

abortTake(): void {
this.isTakeAborted = true
}
Expand Down
5 changes: 5 additions & 0 deletions packages/job-worker/src/blueprints/context/adlibActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { executePeripheralDeviceAction, listPlayoutDevices } from '../../periphe
import { ActionPartChange, PartAndPieceInstanceActionService } from './services/PartAndPieceInstanceActionService.js'
import { BlueprintQuickLookInfo } from '@sofie-automation/blueprints-integration/dist/context/quickLoopInfo'
import { setNextPartFromPart } from '../../playout/setNext.js'
import { getOrderedPartsAfterPlayhead } from '../../playout/lookahead/util.js'

export class DatastoreActionExecutionContext
extends ShowStyleUserContext
Expand Down Expand Up @@ -102,6 +103,10 @@ export class ActionExecutionContext extends ShowStyleUserContext implements IAct
super(contextInfo, _context, showStyle, watchedPackages)
}

async getUpcomingParts(limit: number = 5): Promise<ReadonlyDeep<IBlueprintPart[]>> {
return getOrderedPartsAfterPlayhead(this._context, this._playoutModel, limit)
}

async getPartInstance(part: 'current' | 'next'): Promise<IBlueprintPartInstance | undefined> {
return this.partAndPieceInstanceService.getPartInstance(part)
}
Expand Down
Loading