Skip to content

Commit 8cfe0d3

Browse files
committed
feat(EAV-211): add current segment parts to LSG
1 parent 058610d commit 8cfe0d3

File tree

4 files changed

+107
-2
lines changed

4 files changed

+107
-2
lines changed

packages/live-status-gateway/api/schemas/activePlaylist.yaml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,32 @@ $defs:
124124
- $ref: '#/$defs/piece/examples/0'
125125
publicData:
126126
partType: 'intro'
127+
currentSegmentPart:
128+
type: object
129+
properties:
130+
id:
131+
description: Unique id of the part
132+
type: string
133+
name:
134+
description: User-presentable name of the part
135+
type: string
136+
autoNext:
137+
description: If this part will progress to the next automatically
138+
type: boolean
139+
default: false
140+
timing:
141+
type: object
142+
properties:
143+
expectedDurationMs:
144+
description: Expected duration of the part
145+
type: number
146+
required: [id, name, timing]
147+
additionalProperties: false
148+
examples:
149+
- id: 'H5CBGYjThrMSmaYvRaa5FVKJIzk_'
150+
name: 'Intro'
151+
timing:
152+
expectedDurationMs: 15000
127153
part:
128154
oneOf:
129155
- $ref: '#/$defs/partBase'
@@ -196,7 +222,11 @@ $defs:
196222
- part_expected_duration
197223
- segment_budget_duration
198224
required: [expectedDurationMs, projectedEndTime]
199-
required: [id, timing]
225+
parts:
226+
type: array
227+
items:
228+
$ref: '#/$defs/currentSegmentPart'
229+
required: [id, timing, parts]
200230
additionalProperties: false
201231
examples:
202232
- id: 'H5CBGYjThrMSmaYvRaa5FVKJIzk_'
@@ -205,6 +235,8 @@ $defs:
205235
budgetDurationMs: 20000
206236
projectedEndTime: 1600000075000
207237
countdownType: segment_budget_duration
238+
parts:
239+
- $ref: '#/$defs/currentSegmentPart/examples/0'
208240
piece:
209241
type: object
210242
properties:

packages/live-status-gateway/src/topics/__tests__/activePlaylist.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ describe('ActivePlaylistTopic', () => {
135135
expectedDurationMs: 10000,
136136
projectedEndTime: 1600000070000,
137137
},
138+
parts: [
139+
{
140+
id: 'PART_1',
141+
name: 'Test Part',
142+
timing: {
143+
expectedDurationMs: 10000,
144+
},
145+
autoNext: undefined,
146+
},
147+
],
138148
},
139149
rundownIds: unprotectStringArray(playlist.rundownIdsInOrder),
140150
publicData: { a: 'b' },
@@ -230,6 +240,16 @@ describe('ActivePlaylistTopic', () => {
230240
projectedEndTime: 1600000072300,
231241
countdownType: 'segment_budget_duration',
232242
},
243+
parts: [
244+
{
245+
id: 'PART_1',
246+
name: 'Test Part',
247+
timing: {
248+
expectedDurationMs: 10000,
249+
},
250+
autoNext: undefined,
251+
},
252+
],
233253
},
234254
rundownIds: unprotectStringArray(playlist.rundownIdsInOrder),
235255
publicData: { a: 'b' },

packages/live-status-gateway/src/topics/activePlaylistTopic.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { CurrentSegmentTiming, calculateCurrentSegmentTiming } from './helpers/s
1515
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
1616
import _ = require('underscore')
1717
import { PartTiming, calculateCurrentPartTiming } from './helpers/partTiming'
18+
import { CurrentSegmentPart, getCurrentSegmentParts } from './helpers/segmentParts'
1819
import { SelectedPieceInstances, PieceInstanceMin } from '../collections/pieceInstancesHandler'
1920
import { PieceStatus, toPieceStatus } from './helpers/pieceStatus'
2021
import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
@@ -42,6 +43,7 @@ interface CurrentPartStatus extends PartStatus {
4243
interface CurrentSegmentStatus {
4344
id: string
4445
timing: CurrentSegmentTiming
46+
parts: CurrentSegmentPart[]
4547
}
4648

4749
interface ActivePlaylistQuickLoopMarker {
@@ -135,6 +137,8 @@ export class ActivePlaylistTopic extends WebSocketTopicBase implements WebSocket
135137

136138
const currentPart = this._currentPartInstance ? this._currentPartInstance.part : null
137139
const nextPart = this._nextPartInstance ? this._nextPartInstance.part : null
140+
const currentSegmentParts =
141+
(currentPart && this._partsBySegmentId[unprotectString(currentPart.segmentId)]) ?? []
138142

139143
const message = this._activePlaylist
140144
? literal<ActivePlaylistStatus>({
@@ -169,7 +173,11 @@ export class ActivePlaylistTopic extends WebSocketTopicBase implements WebSocket
169173
this._currentPartInstance,
170174
this._firstInstanceInSegmentPlayout,
171175
this._partInstancesInCurrentSegment,
172-
this._partsBySegmentId[unprotectString(currentPart.segmentId)] ?? []
176+
currentSegmentParts
177+
),
178+
parts: getCurrentSegmentParts(
179+
this._partInstancesInCurrentSegment,
180+
currentSegmentParts
173181
),
174182
})
175183
: null,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { PartInstanceId } from '@sofie-automation/corelib/dist/dataModel/Ids'
2+
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
3+
import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
4+
import { unprotectString } from '@sofie-automation/server-core-integration'
5+
import _ = require('underscore')
6+
7+
export interface CurrentSegmentPart {
8+
id: string
9+
name: string
10+
autoNext: boolean | undefined
11+
timing: {
12+
expectedDurationMs?: number
13+
}
14+
}
15+
16+
export function getCurrentSegmentParts(
17+
segmentPartInstances: DBPartInstance[],
18+
segmentParts: DBPart[]
19+
): CurrentSegmentPart[] {
20+
const partInstancesByPartId: Record<string, { _id: string | PartInstanceId; part: DBPart }> = _.indexBy(
21+
segmentPartInstances,
22+
(partInstance) => unprotectString(partInstance.part._id)
23+
)
24+
segmentParts.forEach((part) => {
25+
const partId = unprotectString(part._id)
26+
if (partInstancesByPartId[partId]) return
27+
const partInstance = {
28+
_id: partId,
29+
part,
30+
}
31+
partInstancesByPartId[partId] = partInstance
32+
})
33+
return Object.values<{ _id: string | PartInstanceId; part: DBPart }>(partInstancesByPartId)
34+
.sort((a, b) => a.part._rank - b.part._rank)
35+
.map(
36+
(partInstance): CurrentSegmentPart => ({
37+
id: unprotectString(partInstance.part._id),
38+
name: partInstance.part.title,
39+
autoNext: partInstance.part.autoNext,
40+
timing: {
41+
expectedDurationMs: partInstance.part.expectedDuration,
42+
},
43+
})
44+
)
45+
}

0 commit comments

Comments
 (0)