mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 15:09:10 +00:00
chore: rename offset to offsetAbs and offsetRel (#1706)
This commit is contained in:
committed by
Carlos Valente
parent
df137402cf
commit
bcf80f9d77
@@ -175,7 +175,7 @@ export const useRuntimePlaybackOverview = createSelector((state: RuntimeStore) =
|
|||||||
|
|
||||||
numEvents: state.runtime.numEvents,
|
numEvents: state.runtime.numEvents,
|
||||||
selectedEventIndex: state.runtime.selectedEventIndex,
|
selectedEventIndex: state.runtime.selectedEventIndex,
|
||||||
offset: state.runtime.offsetMode === OffsetMode.Absolute ? state.runtime.offset : state.runtime.relativeOffset,
|
offset: state.runtime.offsetMode === OffsetMode.Absolute ? state.runtime.offsetAbs : state.runtime.offsetRel,
|
||||||
|
|
||||||
blockStartedAt: state.blockNow?.startedAt ?? null,
|
blockStartedAt: state.blockNow?.startedAt ?? null,
|
||||||
blockExpectedEnd: state.blockNow?.expectedEnd ?? null,
|
blockExpectedEnd: state.blockNow?.expectedEnd ?? null,
|
||||||
@@ -183,12 +183,12 @@ export const useRuntimePlaybackOverview = createSelector((state: RuntimeStore) =
|
|||||||
|
|
||||||
export const useTimelineStatus = createSelector((state: RuntimeStore) => ({
|
export const useTimelineStatus = createSelector((state: RuntimeStore) => ({
|
||||||
clock: state.clock,
|
clock: state.clock,
|
||||||
offset: state.runtime.offset,
|
offset: state.runtime.offsetAbs,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const useTimeUntilData = createSelector((state: RuntimeStore) => ({
|
export const useTimeUntilData = createSelector((state: RuntimeStore) => ({
|
||||||
clock: state.clock,
|
clock: state.clock,
|
||||||
offset: state.runtime.offsetMode === OffsetMode.Absolute ? state.runtime.offset : state.runtime.relativeOffset,
|
offset: state.runtime.offsetMode === OffsetMode.Absolute ? state.runtime.offsetAbs : state.runtime.offsetRel,
|
||||||
offsetMode: state.runtime.offsetMode,
|
offsetMode: state.runtime.offsetMode,
|
||||||
currentDay: state.eventNow?.dayOffset ?? 0,
|
currentDay: state.eventNow?.dayOffset ?? 0,
|
||||||
actualStart: state.runtime.actualStart,
|
actualStart: state.runtime.actualStart,
|
||||||
@@ -200,7 +200,7 @@ export const useCurrentDay = createSelector((state: RuntimeStore) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export const useRuntimeOffset = createSelector((state: RuntimeStore) => ({
|
export const useRuntimeOffset = createSelector((state: RuntimeStore) => ({
|
||||||
offset: state.runtime.offset,
|
offset: state.runtime.offsetAbs,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const usePing = createSelector((state: RuntimeStore) => ({
|
export const usePing = createSelector((state: RuntimeStore) => ({
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default function StudioTimers({
|
|||||||
time.phase === TimerPhase.Danger,
|
time.phase === TimerPhase.Danger,
|
||||||
);
|
);
|
||||||
|
|
||||||
const offsetState = getOffsetState(runtime.offset);
|
const offsetState = getOffsetState(runtime.offsetAbs);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='studio__timers'>
|
<div className='studio__timers'>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { formatTime } from '../../common/utils/time';
|
|||||||
|
|
||||||
const timeFormat = { format12: 'h:mm a', format24: 'HH:mm' };
|
const timeFormat = { format12: 'h:mm a', format24: 'HH:mm' };
|
||||||
export function getFormattedScheduleTimes(runtime: Runtime) {
|
export function getFormattedScheduleTimes(runtime: Runtime) {
|
||||||
const correctedOffset = runtime.offset !== null ? runtime.offset * -1 : null;
|
const correctedOffset = runtime.offsetAbs !== null ? runtime.offsetAbs * -1 : null;
|
||||||
return {
|
return {
|
||||||
actualStart: formatTime(runtime.actualStart, timeFormat),
|
actualStart: formatTime(runtime.actualStart, timeFormat),
|
||||||
expectedEnd: formatTime(runtime.expectedEnd, timeFormat),
|
expectedEnd: formatTime(runtime.expectedEnd, timeFormat),
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ export default function TimelinePage({ events, general, runtime, selectedId, set
|
|||||||
let followedByStatus: string | undefined;
|
let followedByStatus: string | undefined;
|
||||||
|
|
||||||
if (next !== null) {
|
if (next !== null) {
|
||||||
const timeToStart = getTimeToStart(time.clock, next.timeStart, next?.delay ?? 0, runtime.offset);
|
const timeToStart = getTimeToStart(time.clock, next.timeStart, next?.delay ?? 0, runtime.offsetAbs);
|
||||||
if (timeToStart < 0) {
|
if (timeToStart < 0) {
|
||||||
nextStatus = dueText;
|
nextStatus = dueText;
|
||||||
} else {
|
} else {
|
||||||
@@ -63,7 +63,7 @@ export default function TimelinePage({ events, general, runtime, selectedId, set
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (followedBy !== null) {
|
if (followedBy !== null) {
|
||||||
const timeToStart = getTimeToStart(time.clock, followedBy.timeStart, followedBy?.delay ?? 0, runtime.offset);
|
const timeToStart = getTimeToStart(time.clock, followedBy.timeStart, followedBy?.delay ?? 0, runtime.offsetAbs);
|
||||||
if (timeToStart < 0) {
|
if (timeToStart < 0) {
|
||||||
followedByStatus = dueText;
|
followedByStatus = dueText;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -741,8 +741,8 @@ describe('getRuntimeOffset()', () => {
|
|||||||
},
|
},
|
||||||
} as RuntimeState;
|
} as RuntimeState;
|
||||||
|
|
||||||
const { absoluteOffset } = getRuntimeOffset(state);
|
const { offsetAbs } = getRuntimeOffset(state);
|
||||||
expect(absoluteOffset).toBe(-50);
|
expect(offsetAbs).toBe(-50);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('added time subtracts time offset (positive offset)', () => {
|
it('added time subtracts time offset (positive offset)', () => {
|
||||||
@@ -765,8 +765,8 @@ describe('getRuntimeOffset()', () => {
|
|||||||
},
|
},
|
||||||
} as RuntimeState;
|
} as RuntimeState;
|
||||||
|
|
||||||
const { absoluteOffset } = getRuntimeOffset(state);
|
const { offsetAbs } = getRuntimeOffset(state);
|
||||||
expect(absoluteOffset).toBe(-60);
|
expect(offsetAbs).toBe(-60);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('considers running overtime (negative offset)', () => {
|
it('considers running overtime (negative offset)', () => {
|
||||||
@@ -790,8 +790,8 @@ describe('getRuntimeOffset()', () => {
|
|||||||
},
|
},
|
||||||
} as RuntimeState;
|
} as RuntimeState;
|
||||||
|
|
||||||
const { absoluteOffset } = getRuntimeOffset(state);
|
const { offsetAbs } = getRuntimeOffset(state);
|
||||||
expect(absoluteOffset).toBe(-10);
|
expect(offsetAbs).toBe(-10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('paused time is delayed time (negative offset)', () => {
|
it('paused time is delayed time (negative offset)', () => {
|
||||||
@@ -816,8 +816,8 @@ describe('getRuntimeOffset()', () => {
|
|||||||
},
|
},
|
||||||
} as RuntimeState;
|
} as RuntimeState;
|
||||||
|
|
||||||
const { absoluteOffset } = getRuntimeOffset(state);
|
const { offsetAbs } = getRuntimeOffset(state);
|
||||||
expect(absoluteOffset).toBe(-25);
|
expect(offsetAbs).toBe(-25);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('offset doesnt exist if we havent started', () => {
|
it('offset doesnt exist if we havent started', () => {
|
||||||
@@ -834,7 +834,7 @@ describe('getRuntimeOffset()', () => {
|
|||||||
runtime: {
|
runtime: {
|
||||||
selectedEventIndex: 0,
|
selectedEventIndex: 0,
|
||||||
numEvents: 2,
|
numEvents: 2,
|
||||||
offset: -77400000,
|
offsetAbs: -77400000,
|
||||||
plannedStart: 77400000,
|
plannedStart: 77400000,
|
||||||
plannedEnd: 84600000,
|
plannedEnd: 84600000,
|
||||||
actualStart: null,
|
actualStart: null,
|
||||||
@@ -854,8 +854,8 @@ describe('getRuntimeOffset()', () => {
|
|||||||
_timer: { pausedAt: null },
|
_timer: { pausedAt: null },
|
||||||
} as RuntimeState;
|
} as RuntimeState;
|
||||||
|
|
||||||
const { absoluteOffset } = getRuntimeOffset(state);
|
const { offsetAbs } = getRuntimeOffset(state);
|
||||||
expect(absoluteOffset).toBe(0);
|
expect(offsetAbs).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles loaded event', () => {
|
it('handles loaded event', () => {
|
||||||
@@ -875,7 +875,7 @@ describe('getRuntimeOffset()', () => {
|
|||||||
runtime: {
|
runtime: {
|
||||||
selectedEventIndex: 1,
|
selectedEventIndex: 1,
|
||||||
numEvents: 2,
|
numEvents: 2,
|
||||||
offset: -81000000,
|
offsetAbs: -81000000,
|
||||||
plannedStart: 77400000,
|
plannedStart: 77400000,
|
||||||
plannedEnd: 84600000,
|
plannedEnd: 84600000,
|
||||||
actualStart: 79443403,
|
actualStart: 79443403,
|
||||||
@@ -895,8 +895,8 @@ describe('getRuntimeOffset()', () => {
|
|||||||
_timer: { pausedAt: null },
|
_timer: { pausedAt: null },
|
||||||
} as RuntimeState;
|
} as RuntimeState;
|
||||||
|
|
||||||
const { absoluteOffset } = getRuntimeOffset(state);
|
const { offsetAbs } = getRuntimeOffset(state);
|
||||||
expect(absoluteOffset).toBe(81000000 - 79521653); // clock - timestart
|
expect(offsetAbs).toBe(81000000 - 79521653); // clock - timestart
|
||||||
});
|
});
|
||||||
|
|
||||||
it('with time-to-end, offsets dont exist if we are not in overtime', () => {
|
it('with time-to-end, offsets dont exist if we are not in overtime', () => {
|
||||||
@@ -927,7 +927,7 @@ describe('getRuntimeOffset()', () => {
|
|||||||
runtime: {
|
runtime: {
|
||||||
selectedEventIndex: 0,
|
selectedEventIndex: 0,
|
||||||
numEvents: 1,
|
numEvents: 1,
|
||||||
offset: 0,
|
offsetAbs: 0,
|
||||||
plannedStart: 77400000, // 21:30:00
|
plannedStart: 77400000, // 21:30:00
|
||||||
plannedEnd: 81000000, // 22:30:00
|
plannedEnd: 81000000, // 22:30:00
|
||||||
actualStart: 78000000, // 21:40:00
|
actualStart: 78000000, // 21:40:00
|
||||||
@@ -947,8 +947,8 @@ describe('getRuntimeOffset()', () => {
|
|||||||
_timer: { pausedAt: null },
|
_timer: { pausedAt: null },
|
||||||
} as RuntimeState;
|
} as RuntimeState;
|
||||||
|
|
||||||
const { absoluteOffset } = getRuntimeOffset(state);
|
const { offsetAbs } = getRuntimeOffset(state);
|
||||||
expect(absoluteOffset).toBe(0);
|
expect(offsetAbs).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('with time-to-end, offset is the overtime', () => {
|
it('with time-to-end, offset is the overtime', () => {
|
||||||
@@ -979,7 +979,7 @@ describe('getRuntimeOffset()', () => {
|
|||||||
runtime: {
|
runtime: {
|
||||||
selectedEventIndex: 0,
|
selectedEventIndex: 0,
|
||||||
numEvents: 1,
|
numEvents: 1,
|
||||||
offset: 0,
|
offsetAbs: 0,
|
||||||
plannedStart: 77400000, // 21:30:00
|
plannedStart: 77400000, // 21:30:00
|
||||||
plannedEnd: 81000000, // 22:30:00
|
plannedEnd: 81000000, // 22:30:00
|
||||||
actualStart: 78000000, // 21:40:00
|
actualStart: 78000000, // 21:40:00
|
||||||
@@ -999,8 +999,8 @@ describe('getRuntimeOffset()', () => {
|
|||||||
_timer: { pausedAt: null },
|
_timer: { pausedAt: null },
|
||||||
} as RuntimeState;
|
} as RuntimeState;
|
||||||
|
|
||||||
const { absoluteOffset } = getRuntimeOffset(state);
|
const { offsetAbs } = getRuntimeOffset(state);
|
||||||
expect(absoluteOffset).toBe(-400000); // <--- offset is always the overtime
|
expect(offsetAbs).toBe(-400000); // <--- offset is always the overtime
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles time-to-end started after the end time', () => {
|
it('handles time-to-end started after the end time', () => {
|
||||||
@@ -1020,7 +1020,7 @@ describe('getRuntimeOffset()', () => {
|
|||||||
runtime: {
|
runtime: {
|
||||||
selectedEventIndex: 0,
|
selectedEventIndex: 0,
|
||||||
numEvents: 1,
|
numEvents: 1,
|
||||||
offset: 0,
|
offsetAbs: 0,
|
||||||
plannedStart: 77400000, // 21:30:00
|
plannedStart: 77400000, // 21:30:00
|
||||||
plannedEnd: 81000000, // 22:30:00
|
plannedEnd: 81000000, // 22:30:00
|
||||||
actualStart: 82000000, // 22:46:40 <--- started now
|
actualStart: 82000000, // 22:46:40 <--- started now
|
||||||
@@ -1042,13 +1042,13 @@ describe('getRuntimeOffset()', () => {
|
|||||||
|
|
||||||
const updateCurrent = getCurrent(state);
|
const updateCurrent = getCurrent(state);
|
||||||
state.timer.current = updateCurrent;
|
state.timer.current = updateCurrent;
|
||||||
const { absoluteOffset } = getRuntimeOffset(state);
|
const { offsetAbs } = getRuntimeOffset(state);
|
||||||
expect(millisToString(absoluteOffset)).toBe('-00:16:40');
|
expect(millisToString(offsetAbs)).toBe('-00:16:40');
|
||||||
expect(absoluteOffset).toBe(81000000 - 82000000); // <-- planned end - now
|
expect(offsetAbs).toBe(81000000 - 82000000); // <-- planned end - now
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getRelativeOffset()', () => {
|
describe('getoffsetRel()', () => {
|
||||||
it('relative offset is 0 when starting at the planed time', () => {
|
it('relative offset is 0 when starting at the planed time', () => {
|
||||||
const state = {
|
const state = {
|
||||||
eventNow: {
|
eventNow: {
|
||||||
@@ -1069,9 +1069,9 @@ describe('getRelativeOffset()', () => {
|
|||||||
},
|
},
|
||||||
} as RuntimeState;
|
} as RuntimeState;
|
||||||
|
|
||||||
const { absoluteOffset, relativeOffset } = getRuntimeOffset(state);
|
const { offsetAbs, offsetRel } = getRuntimeOffset(state);
|
||||||
expect(absoluteOffset).toBe(0);
|
expect(offsetAbs).toBe(0);
|
||||||
expect(relativeOffset).toBe(0);
|
expect(offsetRel).toBe(0);
|
||||||
});
|
});
|
||||||
it('relative offset is 0 when starting after the planed time', () => {
|
it('relative offset is 0 when starting after the planed time', () => {
|
||||||
const state = {
|
const state = {
|
||||||
@@ -1093,9 +1093,9 @@ describe('getRelativeOffset()', () => {
|
|||||||
},
|
},
|
||||||
} as RuntimeState;
|
} as RuntimeState;
|
||||||
|
|
||||||
const { absoluteOffset, relativeOffset } = getRuntimeOffset(state);
|
const { offsetAbs, offsetRel } = getRuntimeOffset(state);
|
||||||
expect(absoluteOffset).toBe(-50);
|
expect(offsetAbs).toBe(-50);
|
||||||
expect(relativeOffset).toBe(0);
|
expect(offsetRel).toBe(0);
|
||||||
});
|
});
|
||||||
it('relative offset is 0 when starting before the planed time', () => {
|
it('relative offset is 0 when starting before the planed time', () => {
|
||||||
const state = {
|
const state = {
|
||||||
@@ -1117,9 +1117,9 @@ describe('getRelativeOffset()', () => {
|
|||||||
},
|
},
|
||||||
} as RuntimeState;
|
} as RuntimeState;
|
||||||
|
|
||||||
const { absoluteOffset, relativeOffset } = getRuntimeOffset(state);
|
const { offsetAbs, offsetRel } = getRuntimeOffset(state);
|
||||||
expect(absoluteOffset).toBe(50);
|
expect(offsetAbs).toBe(50);
|
||||||
expect(relativeOffset).toBe(0);
|
expect(offsetRel).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1224,7 +1224,7 @@ describe('getTimerPhase()', () => {
|
|||||||
runtime: {
|
runtime: {
|
||||||
selectedEventIndex: null,
|
selectedEventIndex: null,
|
||||||
numEvents: 1,
|
numEvents: 1,
|
||||||
offset: 0,
|
offsetAbs: 0,
|
||||||
plannedStart: 55860000,
|
plannedStart: 55860000,
|
||||||
plannedEnd: 55880000,
|
plannedEnd: 55880000,
|
||||||
actualStart: null,
|
actualStart: null,
|
||||||
@@ -1263,7 +1263,7 @@ describe('getTimerPhase()', () => {
|
|||||||
runtime: {
|
runtime: {
|
||||||
selectedEventIndex: null,
|
selectedEventIndex: null,
|
||||||
numEvents: 1,
|
numEvents: 1,
|
||||||
offset: 0,
|
offsetAbs: 0,
|
||||||
plannedStart: 55860000,
|
plannedStart: 55860000,
|
||||||
plannedEnd: 55880000,
|
plannedEnd: 55880000,
|
||||||
actualStart: null,
|
actualStart: null,
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ 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.runtime.offset;
|
const keepOffset = newState.runtime.offsetAbs;
|
||||||
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
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { isOntimeEvent, MaybeNumber, OntimeBlock, Rundown, TimerPhase } from 'ontime-types';
|
import { isOntimeEvent, MaybeNumber, OffsetMode, OntimeBlock, Rundown, TimerPhase } from 'ontime-types';
|
||||||
import { calculateTimeUntilStart, dayInMs, getLastEventNormal, isPlaybackActive } from 'ontime-utils';
|
import { calculateTimeUntilStart, dayInMs, getLastEventNormal, isPlaybackActive } from 'ontime-utils';
|
||||||
import type { RuntimeState } from '../stores/runtimeState.js';
|
import type { RuntimeState } from '../stores/runtimeState.js';
|
||||||
import { shouldCrashDev } from '../utils/development.js';
|
import { shouldCrashDev } from '../utils/development.js';
|
||||||
@@ -43,7 +43,7 @@ export function getExpectedBlockFinish(state: RuntimeState, rundown: Rundown): M
|
|||||||
const { lastEvent } = getLastEventNormal(rundown.entries, orderInBlock);
|
const { lastEvent } = getLastEventNormal(rundown.entries, orderInBlock);
|
||||||
if (!lastEvent) return null;
|
if (!lastEvent) return null;
|
||||||
|
|
||||||
const { offsetMode, offset, plannedStart, actualStart } = state.runtime;
|
const { offsetMode, offsetAbs, offsetRel, plannedStart, actualStart } = state.runtime;
|
||||||
|
|
||||||
const timeUntilLastEvent = calculateTimeUntilStart({
|
const timeUntilLastEvent = calculateTimeUntilStart({
|
||||||
timeStart: lastEvent.timeStart,
|
timeStart: lastEvent.timeStart,
|
||||||
@@ -54,7 +54,7 @@ export function getExpectedBlockFinish(state: RuntimeState, rundown: Rundown): M
|
|||||||
isLinkedToLoaded,
|
isLinkedToLoaded,
|
||||||
clock,
|
clock,
|
||||||
offsetMode,
|
offsetMode,
|
||||||
offset,
|
offset: offsetMode === OffsetMode.Absolute ? offsetAbs : offsetRel,
|
||||||
plannedStart,
|
plannedStart,
|
||||||
actualStart,
|
actualStart,
|
||||||
});
|
});
|
||||||
@@ -171,10 +171,10 @@ export function skippedOutOfEvent(state: RuntimeState, previousTime: number, ski
|
|||||||
* Positive offset is time ahead
|
* Positive offset is time ahead
|
||||||
* Negative offset is time delayed
|
* Negative offset is time delayed
|
||||||
*/
|
*/
|
||||||
export function getRuntimeOffset(state: RuntimeState): { absoluteOffset: number; relativeOffset: number } {
|
export function getRuntimeOffset(state: RuntimeState): { offsetAbs: number; offsetRel: number } {
|
||||||
// nothing to calculate if there are no loaded events or if we havent started
|
// nothing to calculate if there are no loaded events or if we havent started
|
||||||
if (state.eventNow === null || state.runtime.actualStart === null) {
|
if (state.eventNow === null || state.runtime.actualStart === null) {
|
||||||
return { absoluteOffset: 0, relativeOffset: 0 };
|
return { offsetAbs: 0, offsetRel: 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
const { clock } = state;
|
const { clock } = state;
|
||||||
@@ -192,7 +192,7 @@ export function getRuntimeOffset(state: RuntimeState): { absoluteOffset: number;
|
|||||||
// if we havent started, but the timer is armed
|
// if we havent started, but the timer is armed
|
||||||
// the offset is the difference to the schedule
|
// the offset is the difference to the schedule
|
||||||
if (startedAt === null) {
|
if (startedAt === null) {
|
||||||
return { absoluteOffset: timeStart - clock, relativeOffset: 0 };
|
return { offsetAbs: timeStart - clock, offsetRel: 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
const overtime = Math.min(current, 0);
|
const overtime = Math.min(current, 0);
|
||||||
@@ -211,14 +211,14 @@ export function getRuntimeOffset(state: RuntimeState): { absoluteOffset: number;
|
|||||||
const rundownStartOffset = actualStart - plannedStart;
|
const rundownStartOffset = actualStart - plannedStart;
|
||||||
|
|
||||||
// offset offset relative to the actual rundown start
|
// offset offset relative to the actual rundown start
|
||||||
const relativeOffset = offset + rundownStartOffset;
|
const offsetRel = offset + rundownStartOffset;
|
||||||
|
|
||||||
// in time-to-end, offset is overtime
|
// in time-to-end, offset is overtime
|
||||||
if (countToEnd) {
|
if (countToEnd) {
|
||||||
return { absoluteOffset: overtime, relativeOffset };
|
return { offsetAbs: overtime, offsetRel };
|
||||||
}
|
}
|
||||||
|
|
||||||
return { absoluteOffset: offset, relativeOffset };
|
return { offsetAbs: offset, offsetRel };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -229,7 +229,7 @@ export function getExpectedEnd(state: RuntimeState): MaybeNumber {
|
|||||||
if (state.runtime.actualStart === null || state.runtime.plannedEnd === null) {
|
if (state.runtime.actualStart === null || state.runtime.plannedEnd === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return state.runtime.plannedEnd - state.runtime.offset + state._rundown.totalDelay;
|
return state.runtime.plannedEnd - state.runtime.offsetAbs + state._rundown.totalDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ const baseState: RuntimeState = {
|
|||||||
runtime: {
|
runtime: {
|
||||||
selectedEventIndex: null,
|
selectedEventIndex: null,
|
||||||
numEvents: 0,
|
numEvents: 0,
|
||||||
offset: 0,
|
offsetAbs: 0,
|
||||||
relativeOffset: 0,
|
offsetRel: 0,
|
||||||
plannedStart: 0,
|
plannedStart: 0,
|
||||||
plannedEnd: 0,
|
plannedEnd: 0,
|
||||||
actualStart: null,
|
actualStart: null,
|
||||||
|
|||||||
@@ -185,26 +185,26 @@ describe('mutation on runtimeState', () => {
|
|||||||
expect(newState.runtime.plannedStart).toBe(0);
|
expect(newState.runtime.plannedStart).toBe(0);
|
||||||
expect(newState.runtime.plannedEnd).toBe(1500);
|
expect(newState.runtime.plannedEnd).toBe(1500);
|
||||||
expect(newState.blockNow).toBeNull();
|
expect(newState.blockNow).toBeNull();
|
||||||
expect(newState.runtime.offset).toBe(0);
|
expect(newState.runtime.offsetAbs).toBe(0);
|
||||||
|
|
||||||
// 2. Start event
|
// 2. Start event
|
||||||
start();
|
start();
|
||||||
newState = getState();
|
newState = getState();
|
||||||
const firstStart = newState.clock;
|
const firstStart = newState.clock;
|
||||||
if (newState.runtime.offset === null) {
|
if (newState.runtime.offsetAbs === null) {
|
||||||
throw new Error('Value cannot be null at this stage');
|
throw new Error('Value cannot be null at this stage');
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(newState.runtime.actualStart).toBe(newState.clock);
|
expect(newState.runtime.actualStart).toBe(newState.clock);
|
||||||
expect(newState.runtime.offset).toBe(entries.event1.timeStart - newState.clock);
|
expect(newState.runtime.offsetAbs).toBe(entries.event1.timeStart - newState.clock);
|
||||||
expect(newState.runtime.expectedEnd).toBe(entries.event2.timeEnd - newState.runtime.offset);
|
expect(newState.runtime.expectedEnd).toBe(entries.event2.timeEnd - newState.runtime.offsetAbs);
|
||||||
|
|
||||||
// 3. Next event
|
// 3. Next event
|
||||||
load(entries.event2, rundown, metadata);
|
load(entries.event2, rundown, metadata);
|
||||||
start();
|
start();
|
||||||
|
|
||||||
newState = getState();
|
newState = getState();
|
||||||
if (newState.runtime.actualStart === null || newState.runtime.offset === null) {
|
if (newState.runtime.actualStart === null || newState.runtime.offsetAbs === null) {
|
||||||
throw new Error('Value cannot be null at this stage');
|
throw new Error('Value cannot be null at this stage');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,26 +214,26 @@ describe('mutation on runtimeState', () => {
|
|||||||
expect(forgivingActualStart).toBeLessThanOrEqual(1);
|
expect(forgivingActualStart).toBeLessThanOrEqual(1);
|
||||||
// we are over-under, the difference between the schedule and the actual start
|
// we are over-under, the difference between the schedule and the actual start
|
||||||
const delayBefore = entries.event2.timeStart - newState.clock;
|
const delayBefore = entries.event2.timeStart - newState.clock;
|
||||||
expect(newState.runtime.offset).toBe(delayBefore);
|
expect(newState.runtime.offsetAbs).toBe(delayBefore);
|
||||||
// finish is the difference between the runtime and the schedule
|
// finish is the difference between the runtime and the schedule
|
||||||
expect(newState.runtime.expectedEnd).toBe(entries.event2.timeEnd - newState.runtime.offset);
|
expect(newState.runtime.expectedEnd).toBe(entries.event2.timeEnd - newState.runtime.offsetAbs);
|
||||||
expect(newState.blockNow).toBeNull();
|
expect(newState.blockNow).toBeNull();
|
||||||
|
|
||||||
// 4. Add time
|
// 4. Add time
|
||||||
addTime(10);
|
addTime(10);
|
||||||
newState = getState();
|
newState = getState();
|
||||||
if (newState.runtime.offset === null) {
|
if (newState.runtime.offsetAbs === null) {
|
||||||
throw new Error('Value cannot be null at this stage');
|
throw new Error('Value cannot be null at this stage');
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(newState.runtime.offset).toBe(delayBefore - 10);
|
expect(newState.runtime.offsetAbs).toBe(delayBefore - 10);
|
||||||
expect(newState.runtime.expectedEnd).toBe(entries.event2.timeEnd - newState.runtime.offset);
|
expect(newState.runtime.expectedEnd).toBe(entries.event2.timeEnd - newState.runtime.offsetAbs);
|
||||||
|
|
||||||
// 5. Stop event
|
// 5. Stop event
|
||||||
stop();
|
stop();
|
||||||
newState = getState();
|
newState = getState();
|
||||||
expect(newState.runtime.actualStart).toBeNull();
|
expect(newState.runtime.actualStart).toBeNull();
|
||||||
expect(newState.runtime.offset).toBe(0);
|
expect(newState.runtime.offsetAbs).toBe(0);
|
||||||
expect(newState.runtime.expectedEnd).toBeNull();
|
expect(newState.runtime.expectedEnd).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -325,7 +325,7 @@ describe('roll mode', () => {
|
|||||||
start();
|
start();
|
||||||
const result = roll(rundown, metadata);
|
const result = roll(rundown, metadata);
|
||||||
expect(result).toStrictEqual({ eventId: '1', didStart: false });
|
expect(result).toStrictEqual({ eventId: '1', didStart: false });
|
||||||
expect(getState().runtime.offset).toBe(1000);
|
expect(getState().runtime.offsetAbs).toBe(1000);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -349,21 +349,21 @@ describe('roll mode', () => {
|
|||||||
load(rundown.entries[1] as PlayableEvent, rundown, metadata);
|
load(rundown.entries[1] as PlayableEvent, rundown, metadata);
|
||||||
start();
|
start();
|
||||||
// the current offset after manual play
|
// the current offset after manual play
|
||||||
const currentOffset = getState().runtime.offset;
|
const currentOffset = getState().runtime.offsetAbs;
|
||||||
let result = roll(rundown, metadata, getState().runtime.offset);
|
let result = roll(rundown, metadata, getState().runtime.offsetAbs);
|
||||||
expect(result).toStrictEqual({ eventId: '1', didStart: false });
|
expect(result).toStrictEqual({ eventId: '1', didStart: false });
|
||||||
// the current offset should be maintain by roll mode whn taking over from play
|
// the current offset should be maintain by roll mode whn taking over from play
|
||||||
expect(getState().runtime.offset).toBe(currentOffset);
|
expect(getState().runtime.offsetAbs).toBe(currentOffset);
|
||||||
|
|
||||||
vi.setSystemTime('jan 1 00:00:01');
|
vi.setSystemTime('jan 1 00:00:01');
|
||||||
result = roll(rundown, metadata, getState().runtime.offset);
|
result = roll(rundown, metadata, getState().runtime.offsetAbs);
|
||||||
expect(result).toStrictEqual({ eventId: '2', didStart: true });
|
expect(result).toStrictEqual({ eventId: '2', didStart: true });
|
||||||
expect(getState().runtime.offset).toBe(1000);
|
expect(getState().runtime.offsetAbs).toBe(1000);
|
||||||
|
|
||||||
vi.setSystemTime('jan 1 00:00:02');
|
vi.setSystemTime('jan 1 00:00:02');
|
||||||
result = roll(rundown, metadata, getState().runtime.offset);
|
result = roll(rundown, metadata, getState().runtime.offsetAbs);
|
||||||
expect(result).toStrictEqual({ eventId: '3', didStart: true });
|
expect(result).toStrictEqual({ eventId: '3', didStart: true });
|
||||||
expect(getState().runtime.offset).toBe(1000);
|
expect(getState().runtime.offsetAbs).toBe(1000);
|
||||||
|
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ export function clearEventData() {
|
|||||||
runtimeState.eventNow = null;
|
runtimeState.eventNow = null;
|
||||||
runtimeState.eventNext = null;
|
runtimeState.eventNext = null;
|
||||||
|
|
||||||
runtimeState.runtime.offset = 0;
|
runtimeState.runtime.offsetAbs = 0;
|
||||||
runtimeState.runtime.relativeOffset = 0;
|
runtimeState.runtime.offsetRel = 0;
|
||||||
runtimeState.runtime.expectedEnd = null;
|
runtimeState.runtime.expectedEnd = null;
|
||||||
runtimeState.runtime.selectedEventIndex = null;
|
runtimeState.runtime.selectedEventIndex = null;
|
||||||
|
|
||||||
@@ -117,8 +117,8 @@ export function clearState() {
|
|||||||
runtimeState.blockNext = null;
|
runtimeState.blockNext = null;
|
||||||
runtimeState.nextFlag = null;
|
runtimeState.nextFlag = null;
|
||||||
|
|
||||||
runtimeState.runtime.offset = 0;
|
runtimeState.runtime.offsetAbs = 0;
|
||||||
runtimeState.runtime.relativeOffset = 0;
|
runtimeState.runtime.offsetRel = 0;
|
||||||
runtimeState.runtime.actualStart = null;
|
runtimeState.runtime.actualStart = null;
|
||||||
runtimeState.runtime.expectedEnd = null;
|
runtimeState.runtime.expectedEnd = null;
|
||||||
runtimeState.runtime.selectedEventIndex = null;
|
runtimeState.runtime.selectedEventIndex = null;
|
||||||
@@ -214,9 +214,9 @@ export function load(
|
|||||||
const firstStart = initialData?.firstStart;
|
const firstStart = initialData?.firstStart;
|
||||||
if (firstStart === null || typeof firstStart === 'number') {
|
if (firstStart === null || typeof firstStart === 'number') {
|
||||||
runtimeState.runtime.actualStart = firstStart;
|
runtimeState.runtime.actualStart = firstStart;
|
||||||
const { absoluteOffset, relativeOffset } = getRuntimeOffset(runtimeState);
|
const { offsetAbs, offsetRel } = getRuntimeOffset(runtimeState);
|
||||||
runtimeState.runtime.offset = absoluteOffset;
|
runtimeState.runtime.offsetAbs = offsetAbs;
|
||||||
runtimeState.runtime.relativeOffset = relativeOffset;
|
runtimeState.runtime.offsetRel = offsetRel;
|
||||||
runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState);
|
runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState);
|
||||||
}
|
}
|
||||||
if (typeof initialData.blockStartAt === 'number' && runtimeState.blockNow) {
|
if (typeof initialData.blockStartAt === 'number' && runtimeState.blockNow) {
|
||||||
@@ -298,7 +298,7 @@ export function updateLoaded(event?: PlayableEvent): string | undefined {
|
|||||||
|
|
||||||
// handle edge cases with roll
|
// handle edge cases with roll
|
||||||
if (runtimeState.timer.playback === Playback.Roll) {
|
if (runtimeState.timer.playback === Playback.Roll) {
|
||||||
const offsetClock = runtimeState.clock + runtimeState.runtime.offset;
|
const offsetClock = runtimeState.clock + runtimeState.runtime.offsetAbs;
|
||||||
// if waiting to roll, we update the targets and potentially start the timer
|
// if waiting to roll, we update the targets and potentially start the timer
|
||||||
if (runtimeState._timer.secondaryTarget !== null) {
|
if (runtimeState._timer.secondaryTarget !== null) {
|
||||||
if (runtimeState.eventNow.timeStart < offsetClock && offsetClock < runtimeState.eventNow.timeEnd) {
|
if (runtimeState.eventNow.timeStart < offsetClock && offsetClock < runtimeState.eventNow.timeEnd) {
|
||||||
@@ -385,9 +385,9 @@ export function start(state: RuntimeState = runtimeState): boolean {
|
|||||||
runtimeState.timer.phase = getTimerPhase(runtimeState);
|
runtimeState.timer.phase = getTimerPhase(runtimeState);
|
||||||
|
|
||||||
// update offset
|
// update offset
|
||||||
const { absoluteOffset, relativeOffset } = getRuntimeOffset(runtimeState);
|
const { offsetAbs, offsetRel } = getRuntimeOffset(runtimeState);
|
||||||
runtimeState.runtime.offset = absoluteOffset;
|
runtimeState.runtime.offsetAbs = offsetAbs;
|
||||||
runtimeState.runtime.relativeOffset = relativeOffset;
|
runtimeState.runtime.offsetRel = offsetRel;
|
||||||
|
|
||||||
// as long as there is a timer, we need an planned end
|
// as long as there is a timer, we need an planned end
|
||||||
// eslint-disable-next-line no-unused-labels -- dev code path
|
// eslint-disable-next-line no-unused-labels -- dev code path
|
||||||
@@ -397,7 +397,7 @@ export function start(state: RuntimeState = runtimeState): boolean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state.runtime.expectedEnd = state.runtime.plannedEnd - state.runtime.offset;
|
state.runtime.expectedEnd = state.runtime.plannedEnd - state.runtime.offsetAbs;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,9 +457,9 @@ export function addTime(amount: number) {
|
|||||||
runtimeState.timer.current += amount;
|
runtimeState.timer.current += amount;
|
||||||
|
|
||||||
// update runtime delays: over - under
|
// update runtime delays: over - under
|
||||||
const { absoluteOffset, relativeOffset } = getRuntimeOffset(runtimeState);
|
const { offsetAbs, offsetRel } = getRuntimeOffset(runtimeState);
|
||||||
runtimeState.runtime.offset = absoluteOffset;
|
runtimeState.runtime.offsetAbs = offsetAbs;
|
||||||
runtimeState.runtime.relativeOffset = relativeOffset;
|
runtimeState.runtime.offsetRel = offsetRel;
|
||||||
runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState);
|
runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -504,9 +504,9 @@ export function update(): UpdateResult {
|
|||||||
runtimeState.timer.elapsed = runtimeState.timer.duration - runtimeState.timer.current;
|
runtimeState.timer.elapsed = runtimeState.timer.duration - runtimeState.timer.current;
|
||||||
|
|
||||||
// update runtime, needs up-to-date timer state
|
// update runtime, needs up-to-date timer state
|
||||||
const { absoluteOffset, relativeOffset } = getRuntimeOffset(runtimeState);
|
const { offsetAbs, offsetRel } = getRuntimeOffset(runtimeState);
|
||||||
runtimeState.runtime.offset = absoluteOffset;
|
runtimeState.runtime.offsetAbs = offsetAbs;
|
||||||
runtimeState.runtime.relativeOffset = relativeOffset;
|
runtimeState.runtime.offsetRel = offsetRel;
|
||||||
runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState);
|
runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState);
|
||||||
|
|
||||||
const finishedNow =
|
const finishedNow =
|
||||||
@@ -541,7 +541,7 @@ export function update(): UpdateResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// account for offset
|
// account for offset
|
||||||
const offsetClock = runtimeState.clock + runtimeState.runtime.offset;
|
const offsetClock = runtimeState.clock + runtimeState.runtime.offsetAbs;
|
||||||
runtimeState.timer.phase = TimerPhase.Pending;
|
runtimeState.timer.phase = TimerPhase.Pending;
|
||||||
|
|
||||||
if (hasCrossedMidnight) {
|
if (hasCrossedMidnight) {
|
||||||
@@ -575,7 +575,7 @@ export function roll(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runtimeState.runtime.offset = offset;
|
runtimeState.runtime.offsetAbs = 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
|
||||||
@@ -586,7 +586,7 @@ export function roll(
|
|||||||
runtimeState.timer.expectedFinish = normalisedEndTime;
|
runtimeState.timer.expectedFinish = normalisedEndTime;
|
||||||
|
|
||||||
//account for offset
|
//account for offset
|
||||||
const offsetClock = runtimeState.clock + runtimeState.runtime.offset;
|
const offsetClock = runtimeState.clock + runtimeState.runtime.offsetAbs;
|
||||||
|
|
||||||
// state catch up
|
// state catch up
|
||||||
runtimeState.timer.duration = calculateDuration(runtimeState.eventNow.timeStart, normalisedEndTime);
|
runtimeState.timer.duration = calculateDuration(runtimeState.eventNow.timeStart, normalisedEndTime);
|
||||||
@@ -624,8 +624,8 @@ 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.runtime.offset = offset;
|
runtimeState.runtime.offsetAbs = offset;
|
||||||
const offsetClock = runtimeState.clock + runtimeState.runtime.offset;
|
const offsetClock = runtimeState.clock + runtimeState.runtime.offsetAbs;
|
||||||
|
|
||||||
const { index, isPending } = loadRoll(rundown, metadata, offsetClock);
|
const { index, isPending } = loadRoll(rundown, metadata, offsetClock);
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ export enum OffsetMode {
|
|||||||
export type Runtime = {
|
export type Runtime = {
|
||||||
selectedEventIndex: MaybeNumber;
|
selectedEventIndex: MaybeNumber;
|
||||||
numEvents: number;
|
numEvents: number;
|
||||||
offset: number;
|
offsetAbs: number;
|
||||||
relativeOffset: number;
|
offsetRel: number;
|
||||||
plannedStart: MaybeNumber;
|
plannedStart: MaybeNumber;
|
||||||
actualStart: MaybeNumber;
|
actualStart: MaybeNumber;
|
||||||
plannedEnd: MaybeNumber;
|
plannedEnd: MaybeNumber;
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ export const runtimeStorePlaceholder: Readonly<RuntimeStore> = {
|
|||||||
runtime: {
|
runtime: {
|
||||||
selectedEventIndex: null, // changes if rundown changes or we load a new event
|
selectedEventIndex: null, // changes if rundown changes or we load a new event
|
||||||
numEvents: 0, // change initiated by user
|
numEvents: 0, // change initiated by user
|
||||||
offset: 0, // changes at runtime
|
offsetAbs: 0, // changes at runtime
|
||||||
relativeOffset: 0, // changes at runtime
|
offsetRel: 0, // changes at runtime
|
||||||
plannedStart: 0, // only changes if event changes
|
plannedStart: 0, // only changes if event changes
|
||||||
plannedEnd: 0, // only changes if event changes, overflows over dayInMs
|
plannedEnd: 0, // only changes if event changes, overflows over dayInMs
|
||||||
actualStart: null, // set once we start the timer
|
actualStart: null, // set once we start the timer
|
||||||
|
|||||||
Reference in New Issue
Block a user