mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 15:09:10 +00:00
fix: maintain offset on roll takeover
This commit is contained in:
committed by
Alex Christoffer Rasmussen
parent
25030debe4
commit
a02cdf71c0
@@ -4,6 +4,7 @@ import {
|
|||||||
isOntimeEvent,
|
isOntimeEvent,
|
||||||
isPlayableEvent,
|
isPlayableEvent,
|
||||||
LogOrigin,
|
LogOrigin,
|
||||||
|
Offset,
|
||||||
OffsetMode,
|
OffsetMode,
|
||||||
OntimeEvent,
|
OntimeEvent,
|
||||||
Playback,
|
Playback,
|
||||||
@@ -88,18 +89,17 @@ class RuntimeService {
|
|||||||
// 2. handle edge cases related to roll
|
// 2. handle edge cases related to roll
|
||||||
if (newState.timer.playback === Playback.Roll) {
|
if (newState.timer.playback === Playback.Roll) {
|
||||||
// check if we need to call any side effects
|
// check if we need to call any side effects
|
||||||
const keepOffset = newState.offset.absolute;
|
|
||||||
if (hasSecondaryTimerFinished) {
|
if (hasSecondaryTimerFinished) {
|
||||||
// if the secondary timer has finished, we need to call roll
|
// if the secondary timer has finished, we need to call roll
|
||||||
// since event is already loaded
|
// since event is already loaded
|
||||||
this.rollLoaded(keepOffset);
|
this.rollLoaded(newState.offset);
|
||||||
} else if (hasTimerFinished) {
|
} else if (hasTimerFinished) {
|
||||||
// if the timer has finished, we need to load next and keep rolling
|
// if the timer has finished, we need to load next and keep rolling
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
triggerAutomations(TimerLifeCycle.onFinish, newState);
|
triggerAutomations(TimerLifeCycle.onFinish, newState);
|
||||||
});
|
});
|
||||||
this.handleLoadNext();
|
this.handleLoadNext();
|
||||||
this.rollLoaded(keepOffset);
|
this.rollLoaded(newState.offset);
|
||||||
} else if (
|
} else if (
|
||||||
// if there is no previous clock, we could not have skipped
|
// if there is no previous clock, we could not have skipped
|
||||||
RuntimeService.previousState?.clock &&
|
RuntimeService.previousState?.clock &&
|
||||||
@@ -541,7 +541,7 @@ class RuntimeService {
|
|||||||
/**
|
/**
|
||||||
* Handles special case to call roll on a loaded event which we do not want to discard
|
* Handles special case to call roll on a loaded event which we do not want to discard
|
||||||
*/
|
*/
|
||||||
private rollLoaded(offset?: number) {
|
private rollLoaded(offset: Offset) {
|
||||||
const rundown = getCurrentRundown();
|
const rundown = getCurrentRundown();
|
||||||
const metadata = getRundownMetadata();
|
const metadata = getRundownMetadata();
|
||||||
|
|
||||||
|
|||||||
@@ -357,18 +357,18 @@ describe('roll mode', () => {
|
|||||||
start();
|
start();
|
||||||
// the current offset after manual play
|
// the current offset after manual play
|
||||||
const currentOffset = getState().offset.absolute;
|
const currentOffset = getState().offset.absolute;
|
||||||
let result = roll(rundown, metadata, getState().offset.absolute);
|
let result = roll(rundown, metadata, getState().offset);
|
||||||
expect(result).toStrictEqual({ eventId: '1', didStart: false });
|
expect(result).toStrictEqual({ eventId: '1', didStart: false });
|
||||||
// the current offset should be maintain by roll mode when taking over from play
|
// the current offset should be maintain by roll mode when taking over from play
|
||||||
expect(getState().offset.absolute).toBe(currentOffset);
|
expect(getState().offset.absolute).toBe(currentOffset);
|
||||||
|
|
||||||
vi.setSystemTime('jan 1 00:00:01');
|
vi.setSystemTime('jan 1 00:00:01');
|
||||||
result = roll(rundown, metadata, getState().offset.absolute);
|
result = roll(rundown, metadata, getState().offset);
|
||||||
expect(result).toStrictEqual({ eventId: '2', didStart: true });
|
expect(result).toStrictEqual({ eventId: '2', didStart: true });
|
||||||
expect(getState().offset.absolute).toBe(-1000);
|
expect(getState().offset.absolute).toBe(-1000);
|
||||||
|
|
||||||
vi.setSystemTime('jan 1 00:00:02');
|
vi.setSystemTime('jan 1 00:00:02');
|
||||||
result = roll(rundown, metadata, getState().offset.absolute);
|
result = roll(rundown, metadata, getState().offset);
|
||||||
expect(result).toStrictEqual({ eventId: '3', didStart: true });
|
expect(result).toStrictEqual({ eventId: '3', didStart: true });
|
||||||
expect(getState().offset.absolute).toBe(-1000);
|
expect(getState().offset.absolute).toBe(-1000);
|
||||||
|
|
||||||
|
|||||||
@@ -595,7 +595,7 @@ export function update(): UpdateResult {
|
|||||||
export function roll(
|
export function roll(
|
||||||
rundown: Rundown,
|
rundown: Rundown,
|
||||||
metadata: RundownMetadata,
|
metadata: RundownMetadata,
|
||||||
offset = 0,
|
offset?: Offset,
|
||||||
): { eventId: MaybeString; didStart: boolean } {
|
): { eventId: MaybeString; didStart: boolean } {
|
||||||
// 1. if an event is running, we simply take over the playback
|
// 1. if an event is running, we simply take over the playback
|
||||||
if (runtimeState.timer.playback === Playback.Play && runtimeState.rundown.selectedEventIndex !== null) {
|
if (runtimeState.timer.playback === Playback.Play && runtimeState.rundown.selectedEventIndex !== null) {
|
||||||
@@ -616,7 +616,9 @@ export function roll(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runtimeState.offset.absolute = offset;
|
if (offset) {
|
||||||
|
runtimeState.offset = { ...offset };
|
||||||
|
}
|
||||||
runtimeState.timer.playback = Playback.Roll;
|
runtimeState.timer.playback = Playback.Roll;
|
||||||
|
|
||||||
// account for event that finishes the day after
|
// account for event that finishes the day after
|
||||||
@@ -673,7 +675,9 @@ export function roll(
|
|||||||
clearEventData();
|
clearEventData();
|
||||||
|
|
||||||
// account for offset but we only keep it if passed to us
|
// account for offset but we only keep it if passed to us
|
||||||
runtimeState.offset.absolute = offset;
|
if (offset) {
|
||||||
|
runtimeState.offset = { ...offset };
|
||||||
|
}
|
||||||
const offsetClock = runtimeState.clock - runtimeState.offset.absolute;
|
const offsetClock = runtimeState.clock - runtimeState.offset.absolute;
|
||||||
|
|
||||||
const { index, isPending } = loadRoll(rundown, metadata, offsetClock);
|
const { index, isPending } = loadRoll(rundown, metadata, offsetClock);
|
||||||
|
|||||||
Reference in New Issue
Block a user