Skip to content

Commit

Permalink
feat: add quickloop info to lsg
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Oct 10, 2024
1 parent ded7641 commit b9d4301
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 2 deletions.
38 changes: 38 additions & 0 deletions packages/live-status-gateway/api/schemas/activePlaylist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ $defs:
$ref: '#/$defs/part'
publicData:
description: Optional arbitrary data
quickLoop:
description: Information about the current quickLoop, if any
type: object
properties:
locked:
description: Whether the user is allowed to make alterations to the Start/End markers
type: boolean
running:
description: Whether the loop has two valid markers and is currently running
type: boolean
start:
description: The start of the loop
$ref: '#/$defs/quickLoopMarker'
end:
description: The end of the loop
$ref: '#/$defs/quickLoopMarker'
required: [locked, running]
required: [event, id, name, rundownIds, currentPart, currentSegment, nextPart]
additionalProperties: false
examples:
Expand Down Expand Up @@ -191,3 +208,24 @@ $defs:
tags: ['camera']
publicData:
switcherSource: 1
quickLoopMarker:
type: object
properties:
markerType:
description: The type of entity the marker is locked to
type: string
enum:
- playlist
- rundown
- segment
- part
rundownId:
description: The rundown that this marker references. This will be set for rundown, segment and part markers
type: string
segmentId:
description: The segment that this marker references. This will be set for segment and part markers
type: string
partId:
description: The part that this marker references. This will be set for only part markers
type: string
required: [markerType]
1 change: 1 addition & 0 deletions packages/live-status-gateway/src/liveStatusServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class LiveStatusServer {
await partsHandler.subscribe(activePlaylistTopic)
await pieceInstancesHandler.subscribe(activePlaylistTopic)
await segmentHandler.subscribe(activePlaylistTopic)
await segmentsHandler.subscribe(activePlaylistTopic)

await playlistHandler.subscribe(activePiecesTopic)
await showStyleBaseHandler.subscribe(activePiecesTopic)
Expand Down
97 changes: 95 additions & 2 deletions packages/live-status-gateway/src/topics/activePlaylistTopic.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Logger } from 'winston'
import { WebSocket } from 'ws'
import { unprotectString } from '@sofie-automation/shared-lib/dist/lib/protectedString'
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
import {
DBRundownPlaylist,
QuickLoopMarker,
QuickLoopMarkerType,
} from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
import { literal } from '@sofie-automation/shared-lib/dist/lib/lib'
import { assertNever, literal } from '@sofie-automation/shared-lib/dist/lib/lib'
import { WebSocketTopicBase, WebSocketTopic, CollectionObserver } from '../wsHandler'
import { SelectedPartInstances, PartInstancesHandler } from '../collections/partInstancesHandler'
import { PlaylistHandler } from '../collections/playlistHandler'
Expand All @@ -17,6 +21,8 @@ import { SelectedPieceInstances, PieceInstancesHandler, PieceInstanceMin } from
import { PieceStatus, toPieceStatus } from './helpers/pieceStatus'
import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
import { SegmentHandler } from '../collections/segmentHandler'
import { SegmentsHandler } from '../collections/segmentsHandler'
import { normalizeArray } from '@sofie-automation/corelib/dist/lib'

const THROTTLE_PERIOD_MS = 100

Expand All @@ -38,6 +44,20 @@ interface CurrentSegmentStatus {
timing: CurrentSegmentTiming
}

interface ActivePlaylistQuickLoopMarker {
type: 'playlist' | 'rundown' | 'segment' | 'part'
rundownId: string | undefined
segmentId: string | undefined
partId: string | undefined
}

interface ActivePlaylistQuickLoopStatus {
locked: boolean
running: boolean
start: ActivePlaylistQuickLoopMarker | undefined
end: ActivePlaylistQuickLoopMarker | undefined
}

export interface ActivePlaylistStatus {
event: string
id: string | null
Expand All @@ -46,6 +66,7 @@ export interface ActivePlaylistStatus {
currentPart: CurrentPartStatus | null
currentSegment: CurrentSegmentStatus | null
nextPart: PartStatus | null
quickLoop: ActivePlaylistQuickLoopStatus | undefined
publicData: unknown
}

Expand All @@ -67,6 +88,8 @@ export class ActivePlaylistTopic
private _firstInstanceInSegmentPlayout: DBPartInstance | undefined
private _partInstancesInCurrentSegment: DBPartInstance[] = []
private _partsBySegmentId: Record<string, DBPart[]> = {}
private _partsById: Record<string, DBPart | undefined> = {}
private _segmentsById: Record<string, DBSegment | undefined> = {}
private _pieceInstancesInCurrentPartInstance: PieceInstanceMin[] | undefined
private _pieceInstancesInNextPartInstance: PieceInstanceMin[] | undefined
private _showStyleBaseExt: ShowStyleBaseExt | undefined
Expand Down Expand Up @@ -145,6 +168,7 @@ export class ActivePlaylistTopic
publicData: nextPart.publicData,
})
: null,
quickLoop: this.transformQuickLoopStatus(),
publicData: this._activePlaylist.publicData,
})
: literal<ActivePlaylistStatus>({
Expand All @@ -155,12 +179,73 @@ export class ActivePlaylistTopic
currentPart: null,
currentSegment: null,
nextPart: null,
quickLoop: undefined,
publicData: undefined,
})

this.sendMessage(subscribers, message)
}

private transformQuickLoopStatus(): ActivePlaylistQuickLoopStatus | undefined {
if (!this._activePlaylist) return

const quickLoopProps = this._activePlaylist.quickLoop
if (!quickLoopProps) return undefined

return {
locked: quickLoopProps.locked,
running: quickLoopProps.running,
start: this.transformQuickLoopMarkerStatus(quickLoopProps.start),
end: this.transformQuickLoopMarkerStatus(quickLoopProps.end),
}
}

private transformQuickLoopMarkerStatus(
marker: QuickLoopMarker | undefined
): ActivePlaylistQuickLoopMarker | undefined {
if (!marker) return undefined

switch (marker.type) {
case QuickLoopMarkerType.PLAYLIST:
return {
type: 'playlist',
rundownId: undefined,
segmentId: undefined,
partId: undefined,
}
case QuickLoopMarkerType.RUNDOWN:
return {
type: 'rundown',
rundownId: unprotectString(marker.id),
segmentId: undefined,
partId: undefined,
}
case QuickLoopMarkerType.SEGMENT: {
const segment = this._segmentsById[unprotectString(marker.id)]

return {
type: 'segment',
rundownId: unprotectString(segment?.rundownId),
segmentId: unprotectString(marker.id),
partId: undefined,
}
}
case QuickLoopMarkerType.PART: {
const part = this._partsById[unprotectString(marker.id)]

return {
type: 'part',
rundownId: unprotectString(part?.rundownId),
segmentId: unprotectString(part?.segmentId),
partId: unprotectString(marker.id),
}
}
default:
assertNever(marker)
return undefined
}
}

private isDataInconsistent() {
return (
this._currentPartInstance?._id !== this._activePlaylist?.currentPartInfo?.partInstanceId ||
Expand All @@ -182,6 +267,7 @@ export class ActivePlaylistTopic
| DBPart[]
| SelectedPieceInstances
| DBSegment
| DBSegment[]
| undefined
): Promise<void> {
let hasAnythingChanged = false
Expand Down Expand Up @@ -219,6 +305,7 @@ export class ActivePlaylistTopic
break
}
case PartsHandler.name: {
this._partsById = normalizeArray(data as DBPart[], '_id')
this._partsBySegmentId = _.groupBy(data as DBPart[], 'segmentId')
this.logUpdateReceived('parts', source)
hasAnythingChanged = true // TODO: can this be smarter?
Expand All @@ -243,6 +330,12 @@ export class ActivePlaylistTopic
hasAnythingChanged = true
break
}
case SegmentsHandler.name: {
this._segmentsById = normalizeArray(data as DBSegment[], '_id')
this.logUpdateReceived('segments', source)
hasAnythingChanged = true // TODO: can this be smarter?
break
}
default:
throw new Error(`${this._name} received unsupported update from ${source}}`)
}
Expand Down

0 comments on commit b9d4301

Please sign in to comment.