mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-02 04:49:05 +00:00
extract isPlaybackActive to a global util function (#1393)
This commit is contained in:
committed by
GitHub
parent
df1cf7a96b
commit
cfcf6a5684
@@ -1,5 +1,5 @@
|
|||||||
import { MaybeNumber, Playback, TimerPhase } from 'ontime-types';
|
import { MaybeNumber, TimerPhase } from 'ontime-types';
|
||||||
import { dayInMs } from 'ontime-utils';
|
import { dayInMs, isPlaybackActive } from 'ontime-utils';
|
||||||
import { RuntimeState } from '../stores/runtimeState.js';
|
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;
|
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
|
* Checks running timer to see which phase it currently is in
|
||||||
* @param state
|
* @param state
|
||||||
*/
|
*/
|
||||||
export function getTimerPhase(state: RuntimeState): TimerPhase {
|
export function getTimerPhase(state: RuntimeState): TimerPhase {
|
||||||
if (!isPlaybackActive(state)) {
|
if (!isPlaybackActive(state.timer.playback)) {
|
||||||
return TimerPhase.None;
|
return TimerPhase.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ 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.currentBlock.block).toBeNull();
|
expect(newState.currentBlock.block).toBeNull();
|
||||||
|
expect(newState.runtime.offset).toBe(0);
|
||||||
|
|
||||||
// 2. Start event
|
// 2. Start event
|
||||||
start();
|
start();
|
||||||
|
|||||||
@@ -11,7 +11,14 @@ import {
|
|||||||
TimerPhase,
|
TimerPhase,
|
||||||
TimerState,
|
TimerState,
|
||||||
} from 'ontime-types';
|
} 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 { clock } from '../services/Clock.js';
|
||||||
import { RestorePoint } from '../services/RestoreService.js';
|
import { RestorePoint } from '../services/RestoreService.js';
|
||||||
@@ -21,7 +28,6 @@ import {
|
|||||||
getExpectedFinish,
|
getExpectedFinish,
|
||||||
getRuntimeOffset,
|
getRuntimeOffset,
|
||||||
getTimerPhase,
|
getTimerPhase,
|
||||||
isPlaybackActive,
|
|
||||||
} from '../services/timerUtils.js';
|
} from '../services/timerUtils.js';
|
||||||
import { timerConfig } from '../config/config.js';
|
import { timerConfig } from '../config/config.js';
|
||||||
import { loadRoll, normaliseRollStart } from '../services/rollUtils.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
|
runtimeState.clock = clock.timeNow(); // we update the clock on every update call
|
||||||
|
|
||||||
// 1. is playback idle?
|
// 1. is playback idle?
|
||||||
if (!isPlaybackActive(runtimeState)) {
|
if (!isPlaybackActive(runtimeState.timer.playback)) {
|
||||||
return updateIfIdle();
|
return updateIfIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,3 +89,5 @@ export {
|
|||||||
defaultImportMap,
|
defaultImportMap,
|
||||||
isImportMap,
|
isImportMap,
|
||||||
} from './src/feature/spreadsheet-import/spreadsheetImport.js';
|
} 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user