refactor: use runtime metadate in runtimeState (#1653)

* change load to use metadata

* update roll to use metadata

* remove filterTimedEvents

* add comment

* atempth to refactor rollUtils

* refactor util functions
This commit is contained in:
Alex Christoffer Rasmussen
2025-06-22 10:32:48 +02:00
committed by GitHub
parent e090bde8bb
commit 14a99ce27b
7 changed files with 698 additions and 395 deletions
@@ -30,7 +30,6 @@ import { RestorePoint, restoreService } from '../RestoreService.js';
import { skippedOutOfEvent } from '../timerUtils.js';
import {
filterTimedEvents,
findNextPlayableId,
findNextPlayableWithCue,
findPreviousPlayableId,
@@ -190,17 +189,15 @@ class RuntimeService {
}
private isNewNext() {
const rundown = getCurrentRundown();
const { timedEventOrder } = getRundownMetadata();
const timedEvents = filterTimedEvents(rundown, timedEventOrder);
const state = runtimeState.getState();
const now = state.eventNow?.id;
const next = state.eventNext?.id;
// check whether the index of now and next are consecutive
const indexNow = timedEvents.findIndex((event) => event.id === now);
const indexNext = timedEvents.findIndex((event) => event.id === next);
const indexNow = timedEventOrder.findIndex((id) => id === now);
const indexNext = timedEventOrder.findIndex((id) => id === next);
return indexNext - indexNow !== 1;
}
@@ -241,8 +238,8 @@ class RuntimeService {
runtimeState.updateLoaded(eventNow);
} else {
const rundown = getCurrentRundown();
const { timedEventOrder } = getRundownMetadata();
runtimeState.updateAll(rundown, timedEventOrder);
const metadata = getRundownMetadata();
runtimeState.updateAll(rundown, metadata);
}
return;
}
@@ -252,9 +249,8 @@ class RuntimeService {
isNext = this.isNewNext();
if (isNext) {
const rundown = getCurrentRundown();
const { timedEventOrder } = getRundownMetadata();
const timedEvents = filterTimedEvents(rundown, timedEventOrder);
runtimeState.loadNext(timedEvents);
const metadata = getRundownMetadata();
runtimeState.loadNext(rundown, metadata);
}
}
@@ -273,8 +269,8 @@ class RuntimeService {
// we can ignore events which are not playable
const rundown = getCurrentRundown();
const rundownMetadata = getRundownMetadata();
const success = runtimeState.load(event, rundown, rundownMetadata.playableEventOrder, initialData);
const metadata = getRundownMetadata();
const success = runtimeState.load(event, rundown, metadata, initialData);
if (success) {
logger.info(LogOrigin.Playback, `Loaded event with ID ${event.id}`);
@@ -603,10 +599,10 @@ class RuntimeService {
*/
private rollLoaded(offset?: number) {
const rundown = getCurrentRundown();
const { timedEventOrder } = getRundownMetadata();
const metadata = getRundownMetadata();
try {
runtimeState.roll(rundown, timedEventOrder, offset);
runtimeState.roll(rundown, metadata, offset);
} catch (error) {
logger.error(LogOrigin.Server, `Roll: ${error}`);
}
@@ -627,8 +623,8 @@ class RuntimeService {
try {
const rundown = getCurrentRundown();
const rundownMetadata = getRundownMetadata();
const result = runtimeState.roll(rundown, rundownMetadata.playableEventOrder);
const metadata = getRundownMetadata();
const result = runtimeState.roll(rundown, metadata);
const newState = runtimeState.getState();
if (result.eventId !== previousState.eventNow?.id) {
@@ -681,8 +677,8 @@ class RuntimeService {
}
const rundown = getCurrentRundown();
const rundownMetadata = getRundownMetadata();
runtimeState.resume(restorePoint, event, rundown, rundownMetadata.playableEventOrder);
const metadata = getRundownMetadata();
runtimeState.resume(restorePoint, event, rundown, metadata);
logger.info(LogOrigin.Playback, 'Resuming playback');
}
@@ -120,10 +120,3 @@ export function getEventAtIndex(
return rundown.entries[eventId] as OntimeEvent | undefined;
}
/**
* TODO(v4): we dont need this function
*/
export function filterTimedEvents(rundown: Rundown, timedEventOrder: EntryId[]): OntimeEvent[] {
return timedEventOrder.map((id) => rundown.entries[id] as OntimeEvent);
}