Skip to content
Merged
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
115 changes: 115 additions & 0 deletions meteor/server/api/integration/rundownContentStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { Meteor } from 'meteor/meteor'
import { check } from '../../lib/check'
import { MethodContext } from '../methodContext'
import { checkAccessAndGetPeripheralDevice } from '../../security/check'
import { PeripheralDeviceId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { PieceStatusCode } from '@sofie-automation/corelib/dist/dataModel/Piece'
import {
RundownContentStatusResponse,
RundownPieceContentStatus,
} from '@sofie-automation/shared-lib/dist/peripheralDevice/rundownContentStatus'
import { Blueprints, Parts, Pieces, Rundowns, ShowStyleBases } from '../../collections'
import { fetchStudio } from '../../publications/pieceContentStatusUI/common'
import {
checkPieceContentStatusAndDependencies,
PieceContentStatusPiece,
} from '../../publications/pieceContentStatusUI/checkPieceContentStatus'
import { PieceContentStatusMessageFactory } from '../../publications/pieceContentStatusUI/messageFactory'
import { interpollateTranslation, translateMessage } from '@sofie-automation/corelib/dist/TranslatableMessage'

function formatStatusReason(
status: Awaited<ReturnType<typeof checkPieceContentStatusAndDependencies>>[0]
): string | undefined {
if (status.status === PieceStatusCode.OK) {
return undefined
}

const firstMessage = status.messages[0]
if (!firstMessage) {
return undefined
}

return translateMessage(firstMessage, interpollateTranslation)
}

export namespace RundownContentStatusIntegration {
export async function getContentStatusForRundown(
context: MethodContext,
deviceId: PeripheralDeviceId,
deviceToken: string,
rundownExternalId: string
): Promise<RundownContentStatusResponse> {
check(rundownExternalId, String)

const peripheralDevice = await checkAccessAndGetPeripheralDevice(deviceId, deviceToken, context)
if (!peripheralDevice.studioAndConfigId) {
throw new Meteor.Error(400, 'Device "' + peripheralDevice._id + '" has no studio')
}

const studioId = peripheralDevice.studioAndConfigId.studioId
const studio = await fetchStudio(studioId)
if (!studio) {
throw new Meteor.Error(404, `Studio "${studioId}" not found`)
}

const rundown = await Rundowns.findOneAsync({
studioId,
externalId: rundownExternalId,
})
if (!rundown) {
return {
rundownExternalId,
pieces: [],
}
}

const showStyleBase = await ShowStyleBases.findOneAsync(rundown.showStyleBaseId)
const blueprint = showStyleBase ? await Blueprints.findOneAsync(showStyleBase.blueprintId) : undefined
const messageFactory = new PieceContentStatusMessageFactory(blueprint)

const parts = await Parts.findFetchAsync({ rundownId: rundown._id })
const partExternalIds = new Map(parts.map((part) => [part._id, part.externalId]))

const pieceDocs = await Pieces.findFetchAsync({
startRundownId: rundown._id,
invalid: { $ne: true },
})

const pieces: RundownPieceContentStatus[] = []

for (const pieceDoc of pieceDocs) {
const sourceLayer = showStyleBase?.sourceLayers?.[pieceDoc.sourceLayerId]
if (!sourceLayer) {
continue
}

const statusPiece: PieceContentStatusPiece = {
_id: pieceDoc._id,
content: pieceDoc.content,
expectedPackages: pieceDoc.expectedPackages,
name: pieceDoc.name,
}

const [status] = await checkPieceContentStatusAndDependencies(
studio,
rundown._id,
messageFactory,
statusPiece,
sourceLayer
)

pieces.push({
pieceExternalId: pieceDoc.externalId,
partExternalId: pieceDoc.startPartId ? partExternalIds.get(pieceDoc.startPartId) : undefined,
statusCode: status.status,
ready: status.status === PieceStatusCode.OK,
reason: formatStatusReason(status),
})
}

return {
rundownExternalId,
pieces,
}
}
}
13 changes: 13 additions & 0 deletions meteor/server/api/peripheralDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { triggerWriteAccess, triggerWriteAccessBecauseNoCheckNecessary } from '.
import { checkAccessAndGetPeripheralDevice } from '../security/check'
import { UserActionsLogItem } from '@sofie-automation/meteor-lib/dist/collections/UserActionsLog'
import { PackageManagerIntegration } from './integration/expectedPackages'
import { RundownContentStatusIntegration } from './integration/rundownContentStatus'
import { profiler } from './profiler'
import { QueueStudioJob, QueueOrUpdateStudioJob } from '../worker/worker'
import { StudioJobs } from '@sofie-automation/corelib/dist/worker/studio'
Expand Down Expand Up @@ -1434,6 +1435,18 @@ class ServerPeripheralDeviceAPIClass extends MethodContextAPI implements NewPeri
) {
await PackageManagerIntegration.removePackageInfo(this, deviceId, deviceToken, type, packageId, removeDelay)
}
async getContentStatusForRundown(
deviceId: PeripheralDeviceId,
deviceToken: string,
rundownExternalId: string
) {
return RundownContentStatusIntegration.getContentStatusForRundown(
this,
deviceId,
deviceToken,
rundownExternalId
)
}
// --- Triggers ---
/**
* This receives an arbitrary input from an Input-handling Peripheral Device. See
Expand Down
9 changes: 9 additions & 0 deletions packages/shared-lib/src/peripheralDevice/methodsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
} from './peripheralDeviceAPI.js'
import type { PeripheralDeviceExternalEvent } from './externalEvents.js'
import type { MediaObject } from '../core/model/MediaObjects.js'
import type { RundownContentStatusResponse } from './rundownContentStatus.js'

export type UpdateExpectedPackageWorkStatusesChanges =
| {
Expand Down Expand Up @@ -323,6 +324,13 @@ export interface NewPeripheralDeviceAPI {
removeDelay?: number
): Promise<void>

/** Read-only piece content status for a rundown (by ingest external id). */
getContentStatusForRundown(
deviceId: PeripheralDeviceId,
deviceToken: string,
rundownExternalId: string
): Promise<RundownContentStatusResponse>

/**
* This method is being called by a Peripheral Device handling external triggers when it receives an external
* trigger event or an external input changes it's state (a knob changes it's rotation, a joystick is moved, etc.)
Expand Down Expand Up @@ -432,6 +440,7 @@ export enum PeripheralDeviceAPIMethods {
'fetchPackageInfoMetadata' = 'peripheralDevice.packageManager.fetchPackageInfoMetadata',
'updatePackageInfo' = 'peripheralDevice.packageManager.updatePackageInfo',
'removePackageInfo' = 'peripheralDevice.packageManager.removePackageInfo',
'getContentStatusForRundown' = 'peripheralDevice.packageManager.getContentStatusForRundown',

'requestUserAuthToken' = 'peripheralDevice.spreadsheet.requestUserAuthToken',
'storeAccessToken' = 'peripheralDevice.spreadsheet.storeAccessToken',
Expand Down
21 changes: 21 additions & 0 deletions packages/shared-lib/src/peripheralDevice/rundownContentStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Minimal per-piece content status returned to peripheral devices (e.g. Rundown Editor)
* that need READY/NOT READY badges without subscribing to the WebUI publication.
*/
export interface RundownPieceContentStatus {
/** Piece `externalId` as stored in Core (matches RE piece id when synced). */
pieceExternalId: string
/** Part `externalId` the piece belongs to, when known. */
partExternalId?: string
/** Numeric {@link PieceStatusCode} value from corelib. */
statusCode: number
/** True when `statusCode` is OK (0). */
ready: boolean
/** Human-readable summary for tooltips; omitted when ready. */
reason?: string
}

export interface RundownContentStatusResponse {
rundownExternalId: string
pieces: RundownPieceContentStatus[]
}
Loading