Feat/end action (#308)

* feat: end action

---------

Co-authored-by: Fabian Posenau <fabian@fphome.de>
Co-authored-by: cv <34649812+cpvalente@users.noreply.github.com>
Co-authored-by: Fabian Posenau <19673098+kellhogs@users.noreply.github.com>
This commit is contained in:
Fabian Posenau
2023-03-16 19:27:15 +01:00
committed by GitHub
parent 76c8f8a4d5
commit 73533600a0
13 changed files with 79 additions and 45 deletions
+16 -2
View File
@@ -1,4 +1,4 @@
import { Playback, TimerLifeCycle, TimerState } from 'ontime-types';
import { EndAction, Playback, TimerLifeCycle, TimerState } from 'ontime-types';
import { eventStore } from '../stores/EventStore.js';
import { PlaybackService } from './PlaybackService.js';
@@ -47,6 +47,7 @@ export class TimerService {
selectedEventId: null,
duration: null,
timerType: null,
endAction: null,
};
this.loadedTimerId = null;
this.pausedTime = 0;
@@ -78,6 +79,7 @@ export class TimerService {
// update relevant information and force update
this.timer.duration = timer.duration;
this.timer.timerType = timer.timerType;
this.timer.endAction = timer.endAction;
// this might not be ideal
this.timer.finishedAt = null;
@@ -117,6 +119,7 @@ export class TimerService {
this.timer.current = timer.duration;
this.playback = Playback.Armed;
this.timer.timerType = timer.timerType;
this.timer.endAction = timer.endAction;
this.pausedTime = 0;
this.pausedAt = 0;
@@ -210,7 +213,7 @@ export class TimerService {
* Delays running timer by given amount
* @param {number} amount
*/
delay(amount) {
delay(amount: number) {
if (!this.loadedTimerId) {
return;
}
@@ -289,6 +292,7 @@ export class TimerService {
this.pausedTime,
this.timer.clock,
);
this.timer.elapsed = getElapsed(this.timer.startedAt, this.timer.clock);
}
}
@@ -303,6 +307,16 @@ export class TimerService {
_onFinish() {
eventStore.set('timer', this.timer);
integrationService.dispatch(TimerLifeCycle.onFinish);
if (this.timer.endAction === EndAction.Stop) {
PlaybackService.stop();
} else if (this.timer.endAction === EndAction.LoadNext) {
// we need to delay here to put this action in the queue stack. otherwise it won't be executed properly
setTimeout(() => {
PlaybackService.loadNext();
}, 0);
} else if (this.timer.endAction === EndAction.PlayNext) {
PlaybackService.startNext();
}
}
roll(currentEvent, nextEvent, timers) {