Skip to content

Commit a9fe401

Browse files
committed
fix: only run onPart/PiecePlaybackStarted/Stopped on current, next or previous parts
Since these are the only ones loaded into the PlayoutModel, we should not try to update any others
1 parent 70bb56c commit a9fe401

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

packages/job-worker/src/playout/timings/partPlayback.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ export async function onPartPlaybackStarted(
2626
startedPlayback: Time
2727
}
2828
): Promise<void> {
29+
if (
30+
// We only expect to be able to update the current, next, or previous part:
31+
data.partInstanceId !== playoutModel.playlist.currentPartInfo?.partInstanceId ||
32+
data.partInstanceId !== playoutModel.playlist.nextPartInfo?.partInstanceId ||
33+
data.partInstanceId !== playoutModel.playlist.previousPartInfo?.partInstanceId
34+
) {
35+
logger.debug(
36+
`onPartPlaybackStarted PartInstance "${data.partInstanceId}" is neither current, next nor previous (current: ${playoutModel.playlist.currentPartInfo?.partInstanceId}, next: ${playoutModel.playlist.nextPartInfo?.partInstanceId}, previous: ${playoutModel.playlist.previousPartInfo?.partInstanceId}, timestamp: ${data.startedPlayback}`
37+
)
38+
return
39+
}
40+
2941
const playingPartInstance = playoutModel.getPartInstance(data.partInstanceId)
3042
if (!playingPartInstance)
3143
throw new Error(
@@ -136,6 +148,18 @@ export function onPartPlaybackStopped(
136148
stoppedPlayback: Time
137149
}
138150
): void {
151+
if (
152+
// We only expect to be able to update the current, next, or previous part:
153+
data.partInstanceId !== playoutModel.playlist.currentPartInfo?.partInstanceId ||
154+
data.partInstanceId !== playoutModel.playlist.nextPartInfo?.partInstanceId ||
155+
data.partInstanceId !== playoutModel.playlist.previousPartInfo?.partInstanceId
156+
) {
157+
logger.debug(
158+
`onPartPlaybackStopped PartInstance "${data.partInstanceId}" is neither current, next nor previous (current: ${playoutModel.playlist.currentPartInfo?.partInstanceId}, next: ${playoutModel.playlist.nextPartInfo?.partInstanceId}, previous: ${playoutModel.playlist.previousPartInfo?.partInstanceId}, timestamp: ${data.stoppedPlayback}`
159+
)
160+
return
161+
}
162+
139163
const playlist = playoutModel.playlist
140164

141165
const partInstance = playoutModel.getPartInstance(data.partInstanceId)

packages/job-worker/src/playout/timings/piecePlayback.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ export function onPiecePlaybackStarted(
2323
): void {
2424
const playlist = playoutModel.playlist
2525

26+
if (
27+
// We only expect to be able to update the current, next, or previous part:
28+
data.partInstanceId !== playoutModel.playlist.currentPartInfo?.partInstanceId ||
29+
data.partInstanceId !== playoutModel.playlist.nextPartInfo?.partInstanceId ||
30+
data.partInstanceId !== playoutModel.playlist.previousPartInfo?.partInstanceId
31+
) {
32+
logger.debug(
33+
`onPiecePlaybackStarted PartInstance "${data.partInstanceId}" is neither current, next nor previous (current: ${playoutModel.playlist.currentPartInfo?.partInstanceId}, next: ${playoutModel.playlist.nextPartInfo?.partInstanceId}, previous: ${playoutModel.playlist.previousPartInfo?.partInstanceId}), timestamp: ${data.startedPlayback}`
34+
)
35+
return
36+
}
37+
2638
const partInstance = playoutModel.getPartInstance(data.partInstanceId)
2739
if (!partInstance) {
2840
if (!playlist.activationId) {
@@ -38,7 +50,10 @@ export function onPiecePlaybackStarted(
3850
if (!playlist.activationId) {
3951
logger.warn(`onPiecePlaybackStarted: Received for inactive RundownPlaylist "${playlist._id}"`)
4052
} else {
41-
throw new Error(`PieceInstance "${data.partInstanceId}" in RundownPlaylist "${playlist._id}" not found!`)
53+
const otherPieceInstanceIds = partInstance.pieceInstances.map((p) => p.pieceInstance._id)
54+
throw new Error(
55+
`PieceInstance "${data.pieceInstanceId}" in PartInstance "${partInstance.partInstance._id}" in RundownPlaylist "${playlist._id}" not found! (other pieceInstanceIds in PartInstance: ${otherPieceInstanceIds})`
56+
)
4257
}
4358
return
4459
}
@@ -75,6 +90,18 @@ export function onPiecePlaybackStopped(
7590
): void {
7691
const playlist = playoutModel.playlist
7792

93+
if (
94+
// We only expect to be able to update the current, next, or previous part:
95+
data.partInstanceId !== playoutModel.playlist.currentPartInfo?.partInstanceId ||
96+
data.partInstanceId !== playoutModel.playlist.nextPartInfo?.partInstanceId ||
97+
data.partInstanceId !== playoutModel.playlist.previousPartInfo?.partInstanceId
98+
) {
99+
logger.debug(
100+
`onPiecePlaybackStarted PartInstance "${data.partInstanceId}" is neither current, next nor previous (current: ${playoutModel.playlist.currentPartInfo?.partInstanceId}, next: ${playoutModel.playlist.nextPartInfo?.partInstanceId}, previous: ${playoutModel.playlist.previousPartInfo?.partInstanceId}), timestamp: ${data.stoppedPlayback}`
101+
)
102+
return
103+
}
104+
78105
const partInstance = playoutModel.getPartInstance(data.partInstanceId)
79106
if (!partInstance) {
80107
// PartInstance not found, so we can rely on the onPartPlaybackStopped callback erroring
@@ -86,7 +113,10 @@ export function onPiecePlaybackStopped(
86113
if (!playlist.activationId) {
87114
logger.warn(`onPiecePlaybackStopped: Received for inactive RundownPlaylist "${playlist._id}"`)
88115
} else {
89-
throw new Error(`PieceInstance "${data.partInstanceId}" in RundownPlaylist "${playlist._id}" not found!`)
116+
const otherPieceInstanceIds = partInstance.pieceInstances.map((p) => p.pieceInstance._id)
117+
throw new Error(
118+
`PieceInstance "${data.pieceInstanceId}" in PartInstance "${partInstance.partInstance._id}" in RundownPlaylist "${playlist._id}" not found! (other pieceInstanceIds in PartInstance: ${otherPieceInstanceIds})`
119+
)
90120
}
91121
return
92122
}

0 commit comments

Comments
 (0)