add warning and danger transitions as timer life cycle events (#1071)

* setup detection of TImerPhase changes

* add integration event for transition to warning

* add integration event for transition to danger

---------

Co-authored-by: Carlos Valente <34649812+cpvalente@users.noreply.github.com>
This commit is contained in:
2024-06-15 02:54:29 -05:00
committed by GitHub
parent 1044dfac01
commit 70e8fbf327
5 changed files with 39 additions and 1 deletions
@@ -1,4 +1,13 @@
import { EndAction, LogOrigin, MaybeNumber, OntimeEvent, Playback, RuntimeStore, TimerLifeCycle } from 'ontime-types';
import {
EndAction,
LogOrigin,
MaybeNumber,
OntimeEvent,
Playback,
RuntimeStore,
TimerLifeCycle,
TimerPhase,
} from 'ontime-types';
import { millisToString, validatePlayback } from 'ontime-utils';
import { deepEqual } from 'fast-equals';
@@ -93,6 +102,25 @@ class RuntimeService {
const rundown = getPlayableEvents();
this.eventTimer.roll(rundown);
}
const timerPhaseChanged = RuntimeService.previousState.timer?.phase !== newState.timer.phase;
if (timerPhaseChanged) {
switch (newState.timer.phase) {
case TimerPhase.Warning:
process.nextTick(() => {
integrationService.dispatch(TimerLifeCycle.onWarning);
});
break;
case TimerPhase.Danger:
process.nextTick(() => {
integrationService.dispatch(TimerLifeCycle.onDanger);
});
break;
default:
break;
}
}
}
/** delay initialisation until we have a restore point */