Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Blueprint API): Expose Segments in blueprint contexts #1393

Open
wants to merge 2 commits into
base: release53
Choose a base branch
from
Open
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
Expand Up @@ -6,6 +6,7 @@ import {
IBlueprintPieceDB,
IBlueprintPieceInstance,
IBlueprintResolvedPieceInstance,
IBlueprintSegment,
IEventContext,
IShowStyleUserContext,
} from '..'
Expand Down Expand Up @@ -49,6 +50,8 @@ export interface IOnSetAsNextContext extends IShowStyleUserContext, IEventContex
getPartInstanceForPreviousPiece(piece: IBlueprintPieceInstance): Promise<IBlueprintPartInstance>
/** Gets the Part for a Piece retrieved from findLastScriptedPieceOnLayer. This primarily allows for accessing metadata of the Part */
getPartForPreviousPiece(piece: IBlueprintPieceDB): Promise<IBlueprintPart | undefined>
/** Gets the Segment. This primarily allows for accessing metadata */
getSegment(segment: 'current' | 'next'): Promise<IBlueprintSegment | undefined>

/**
* Creative actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IBlueprintPieceDB,
IBlueprintPieceInstance,
IBlueprintResolvedPieceInstance,
IBlueprintSegment,
Time,
} from '..'
import { BlueprintQuickLookInfo } from './quickLoopInfo'
Expand Down Expand Up @@ -44,6 +45,8 @@ export interface IPartAndPieceActionContext {
getPartInstanceForPreviousPiece(piece: IBlueprintPieceInstance): Promise<IBlueprintPartInstance>
/** Gets the Part for a Piece retrieved from findLastScriptedPieceOnLayer. This primarily allows for accessing metadata of the Part */
getPartForPreviousPiece(piece: IBlueprintPieceDB): Promise<IBlueprintPart | undefined>
/** Gets the Segment. This primarily allows for accessing metadata */
getSegment(segment: 'current' | 'next'): Promise<IBlueprintSegment | undefined>

/**
* Creative actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ describe('Test blueprint api context', () => {
expect(mockActionService.getResolvedPieceInstances).toHaveBeenCalledWith('current')
})

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

await context.getSegment('current')
expect(mockActionService.getSegment).toHaveBeenCalledTimes(1)
expect(mockActionService.getSegment).toHaveBeenCalledWith('current')
})

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ describe('Test blueprint api context', () => {
expect(mockActionService.getResolvedPieceInstances).toHaveBeenCalledWith('current')
})

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

await context.getSegment('current')
expect(mockActionService.getSegment).toHaveBeenCalledTimes(1)
expect(mockActionService.getSegment).toHaveBeenCalledWith('current')
})

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ describe('Test blueprint api context', () => {
expect(mockActionService.getResolvedPieceInstances).toHaveBeenCalledWith('current')
})

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

await context.getSegment('current')
expect(mockActionService.getSegment).toHaveBeenCalledTimes(1)
expect(mockActionService.getSegment).toHaveBeenCalledWith('current')
})

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
IBlueprintPieceDB,
IBlueprintPieceInstance,
IBlueprintResolvedPieceInstance,
IBlueprintSegment,
IEventContext,
IOnSetAsNextContext,
} from '@sofie-automation/blueprints-integration'
Expand Down Expand Up @@ -67,6 +68,10 @@ export class OnSetAsNextContext
return this.partAndPieceInstanceService.getResolvedPieceInstances(part)
}

async getSegment(segment: 'current' | 'next'): Promise<IBlueprintSegment | undefined> {
return this.partAndPieceInstanceService.getSegment(segment)
}

async findLastPieceOnLayer(
sourceLayerId0: string | string[],
options?: {
Expand Down
4 changes: 4 additions & 0 deletions packages/job-worker/src/blueprints/context/OnTakeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
TSR,
IBlueprintPlayoutDevice,
IOnTakeContext,
IBlueprintSegment,
} from '@sofie-automation/blueprints-integration'
import { PeripheralDeviceId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { ReadonlyDeep } from 'type-fest'
Expand Down Expand Up @@ -64,6 +65,9 @@ export class OnTakeContext extends ShowStyleUserContext implements IOnTakeContex
async getResolvedPieceInstances(part: 'current' | 'next'): Promise<IBlueprintResolvedPieceInstance[]> {
return this.partAndPieceInstanceService.getResolvedPieceInstances(part)
}
async getSegment(segment: 'current' | 'next'): Promise<IBlueprintSegment | undefined> {
return this.partAndPieceInstanceService.getSegment(segment)
}

async findLastPieceOnLayer(
sourceLayerId0: string | string[],
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 @@ -14,6 +14,7 @@ import {
TSR,
IBlueprintPlayoutDevice,
StudioRouteSet,
IBlueprintSegment,
} from '@sofie-automation/blueprints-integration'
import { PartInstanceId, PeripheralDeviceId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { ReadonlyDeep } from 'type-fest'
Expand Down Expand Up @@ -113,6 +114,10 @@ export class ActionExecutionContext extends ShowStyleUserContext implements IAct
return this.partAndPieceInstanceService.getResolvedPieceInstances(part)
}

async getSegment(segment: 'current' | 'next'): Promise<IBlueprintSegment | undefined> {
return this.partAndPieceInstanceService.getSegment(segment)
}

async findLastPieceOnLayer(
sourceLayerId0: string | string[],
options?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
IBlueprintPieceDB,
IBlueprintPieceInstance,
IBlueprintResolvedPieceInstance,
IBlueprintSegment,
OmitId,
SomeContent,
Time,
Expand All @@ -22,6 +23,7 @@
convertPieceInstanceToBlueprints,
convertPieceToBlueprints,
convertResolvedPieceInstanceToBlueprints,
convertSegmentToBlueprints,
createBlueprintQuickLoopInfo,
getMediaObjectDuration,
} from '../lib'
Expand Down Expand Up @@ -138,6 +140,14 @@
)
return resolvedInstances.map(convertResolvedPieceInstanceToBlueprints)
}
getSegment(segment: 'current' | 'next'): IBlueprintSegment | undefined {
const partInstance = this.#getPartInstance(segment)
if (!partInstance) return undefined

const segmentModel = this._playoutModel.findSegment(partInstance.partInstance.segmentId)

return segmentModel?.segment ? convertSegmentToBlueprints(segmentModel?.segment) : undefined
}

Check warning on line 150 in packages/job-worker/src/blueprints/context/services/PartAndPieceInstanceActionService.ts

View check run for this annotation

Codecov / codecov/patch

packages/job-worker/src/blueprints/context/services/PartAndPieceInstanceActionService.ts#L144-L150

Added lines #L144 - L150 were not covered by tests

async findLastPieceOnLayer(
sourceLayerId0: string | string[],
Expand Down
Loading