extract isPlaybackActive to a global util function (#1393)

This commit is contained in:
Alex Christoffer Rasmussen
2024-12-18 12:44:48 +01:00
committed by GitHub
parent df1cf7a96b
commit cfcf6a5684
5 changed files with 25 additions and 19 deletions
+3 -16
View File
@@ -1,5 +1,5 @@
import { MaybeNumber, Playback, TimerPhase } from 'ontime-types';
import { dayInMs } from 'ontime-utils';
import { MaybeNumber, TimerPhase } from 'ontime-types';
import { dayInMs, isPlaybackActive } from 'ontime-utils';
import { RuntimeState } from '../stores/runtimeState.js';
/**
@@ -187,25 +187,12 @@ export function getExpectedEnd(state: RuntimeState): MaybeNumber {
return state.runtime.plannedEnd - state.runtime.offset + state._timer.totalDelay;
}
/**
* Utility checks whether the playback is considered to be active
* @param state
* @returns
*/
export function isPlaybackActive(state: RuntimeState): boolean {
return (
state.timer.playback === Playback.Play ||
state.timer.playback === Playback.Pause ||
state.timer.playback === Playback.Roll
);
}
/**
* Checks running timer to see which phase it currently is in
* @param state
*/
export function getTimerPhase(state: RuntimeState): TimerPhase {
if (!isPlaybackActive(state)) {
if (!isPlaybackActive(state.timer.playback)) {
return TimerPhase.None;
}
@@ -175,6 +175,7 @@ describe('mutation on runtimeState', () => {
expect(newState.runtime.plannedStart).toBe(0);
expect(newState.runtime.plannedEnd).toBe(1500);
expect(newState.currentBlock.block).toBeNull();
expect(newState.runtime.offset).toBe(0);
// 2. Start event
start();
+9 -3
View File
@@ -11,7 +11,14 @@ import {
TimerPhase,
TimerState,
} from 'ontime-types';
import { calculateDuration, checkIsNow, dayInMs, filterTimedEvents, getPreviousBlock } from 'ontime-utils';
import {
calculateDuration,
checkIsNow,
dayInMs,
filterTimedEvents,
getPreviousBlock,
isPlaybackActive,
} from 'ontime-utils';
import { clock } from '../services/Clock.js';
import { RestorePoint } from '../services/RestoreService.js';
@@ -21,7 +28,6 @@ import {
getExpectedFinish,
getRuntimeOffset,
getTimerPhase,
isPlaybackActive,
} from '../services/timerUtils.js';
import { timerConfig } from '../config/config.js';
import { loadRoll, normaliseRollStart } from '../services/rollUtils.js';
@@ -485,7 +491,7 @@ export function update(): UpdateResult {
runtimeState.clock = clock.timeNow(); // we update the clock on every update call
// 1. is playback idle?
if (!isPlaybackActive(runtimeState)) {
if (!isPlaybackActive(runtimeState.timer.playback)) {
return updateIfIdle();
}
+2
View File
@@ -89,3 +89,5 @@ export {
defaultImportMap,
isImportMap,
} from './src/feature/spreadsheet-import/spreadsheetImport.js';
export { isPlaybackActive } from './src/playback-utils/playbackstate.js';
@@ -0,0 +1,10 @@
import { Playback } from 'ontime-types';
/**
* Utility checks whether the playback is considered to be active
* @param state
* @returns
*/
export function isPlaybackActive(state: Playback): boolean {
return state === Playback.Play || state === Playback.Pause || state === Playback.Roll;
}