mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 10:53:51 +00:00
refactor: roll handover (#451)
* style: tweak active colour * refactor: create shared playback validation * feat: allow handover from and to roll
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { OntimeEvent, Playback } from 'ontime-types';
|
||||
import { OntimeEvent } from 'ontime-types';
|
||||
import { validatePlayback } from 'ontime-utils';
|
||||
|
||||
import { eventLoader, EventLoader } from '../classes/event-loader/EventLoader.js';
|
||||
import { eventStore } from '../stores/EventStore.js';
|
||||
@@ -133,7 +134,7 @@ export class PlaybackService {
|
||||
* Starts playback on selected event
|
||||
*/
|
||||
static start() {
|
||||
if (eventTimer.playback === Playback.Armed || eventTimer.playback === Playback.Pause) {
|
||||
if (validatePlayback(eventTimer.playback).start) {
|
||||
eventTimer.start();
|
||||
const newState = eventTimer.playback;
|
||||
logger.info('PLAYBACK', `Play Mode ${newState.toUpperCase()}`);
|
||||
@@ -155,7 +156,7 @@ export class PlaybackService {
|
||||
* Pauses playback on selected event
|
||||
*/
|
||||
static pause() {
|
||||
if (eventTimer.playback === Playback.Play) {
|
||||
if (validatePlayback(eventTimer.playback).pause) {
|
||||
eventTimer.pause();
|
||||
const newState = eventTimer.playback;
|
||||
logger.info('PLAYBACK', `Play Mode ${newState.toUpperCase()}`);
|
||||
@@ -166,7 +167,7 @@ export class PlaybackService {
|
||||
* Stops timer and unloads any events
|
||||
*/
|
||||
static stop() {
|
||||
if (eventTimer.playback !== Playback.Stop) {
|
||||
if (validatePlayback(eventTimer.playback).stop) {
|
||||
eventLoader.reset();
|
||||
eventTimer.stop();
|
||||
const newState = eventTimer.playback;
|
||||
|
||||
@@ -7,6 +7,13 @@ import { DAY_TO_MS } from '../utils/time.js';
|
||||
import { integrationService } from './integration-service/IntegrationService.js';
|
||||
import { getCurrent, getElapsed, getExpectedFinish } from './timerUtils.js';
|
||||
import { clock } from './Clock.js';
|
||||
import { logger } from '../classes/Logger.js';
|
||||
|
||||
type initialLoadingData = {
|
||||
startedAt?: number | null;
|
||||
expectedFinish?: number | null;
|
||||
current?: number | null;
|
||||
};
|
||||
|
||||
export class TimerService {
|
||||
private readonly _interval: NodeJS.Timer;
|
||||
@@ -113,7 +120,7 @@ export class TimerService {
|
||||
* @param {string} timer.timerType
|
||||
* @param {boolean} timer.skip
|
||||
*/
|
||||
load(timer) {
|
||||
load(timer, initialData?: initialLoadingData) {
|
||||
if (timer.skip) {
|
||||
throw new Error('Refuse load of skipped event');
|
||||
}
|
||||
@@ -129,6 +136,10 @@ export class TimerService {
|
||||
this.pausedTime = 0;
|
||||
this.pausedAt = 0;
|
||||
|
||||
if (typeof initialData !== 'undefined') {
|
||||
this.timer = { ...this.timer, ...initialData };
|
||||
}
|
||||
|
||||
this._onLoad();
|
||||
}
|
||||
|
||||
@@ -146,6 +157,9 @@ export class TimerService {
|
||||
|
||||
start() {
|
||||
if (!this.loadedTimerId) {
|
||||
if (this.playback === Playback.Roll) {
|
||||
logger.error('PLAYBACK', 'Cannot start while waiting for event');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -155,12 +169,12 @@ export class TimerService {
|
||||
|
||||
this.timer.clock = clock.timeNow();
|
||||
|
||||
// add paused time
|
||||
// add paused time if it exists
|
||||
if (this.pausedTime) {
|
||||
this.timer.addedTime += this.pausedTime;
|
||||
this.pausedAt = null;
|
||||
this.pausedTime = 0;
|
||||
} else {
|
||||
} else if (this.timer.startedAt === null) {
|
||||
this.timer.startedAt = this.timer.clock;
|
||||
}
|
||||
|
||||
@@ -188,10 +202,6 @@ export class TimerService {
|
||||
}
|
||||
|
||||
pause() {
|
||||
if (this.playback !== Playback.Play) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.playback = Playback.Pause;
|
||||
this.timer.clock = clock.timeNow();
|
||||
this.pausedAt = this.timer.clock;
|
||||
@@ -370,9 +380,11 @@ export class TimerService {
|
||||
|
||||
// when we load a timer in roll, we do the same things as before
|
||||
// but also pre-populate some data as to the running state
|
||||
this.load(currentEvent);
|
||||
this.timer.startedAt = currentEvent.timeStart;
|
||||
this.timer.expectedFinish = currentEvent.timeEnd;
|
||||
this.load(currentEvent, {
|
||||
startedAt: currentEvent.timeStart,
|
||||
expectedFinish: currentEvent.timeEnd,
|
||||
current: currentEvent.timeEnd - this.timer.clock,
|
||||
});
|
||||
} else if (nextEvent) {
|
||||
// account for day after
|
||||
const nextStart = nextEvent.timeStart < this.timer.clock ? nextEvent.timeStart + DAY_TO_MS : nextEvent.timeStart;
|
||||
|
||||
Reference in New Issue
Block a user