diff --git a/apps/client/src/features/app-settings/panel/integrations-panel/integrationUtils.ts b/apps/client/src/features/app-settings/panel/integrations-panel/integrationUtils.ts index 5a8c2388d..1f0456cfa 100644 --- a/apps/client/src/features/app-settings/panel/integrations-panel/integrationUtils.ts +++ b/apps/client/src/features/app-settings/panel/integrations-panel/integrationUtils.ts @@ -14,4 +14,6 @@ export const cycles: CycleLabel[] = [ { id: 5, label: 'Every second', value: 'onClock' }, { id: 5, label: 'On Timer Update', value: 'onUpdate' }, { id: 6, label: 'On Finish', value: 'onFinish' }, + { id: 7, label: 'On Warning', value: 'onWarning' }, + { id: 8, label: 'On Danger', value: 'onDanger' }, ]; diff --git a/apps/server/src/services/runtime-service/RuntimeService.ts b/apps/server/src/services/runtime-service/RuntimeService.ts index bea2b4663..65d5f24ef 100644 --- a/apps/server/src/services/runtime-service/RuntimeService.ts +++ b/apps/server/src/services/runtime-service/RuntimeService.ts @@ -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 */ diff --git a/apps/server/src/utils/__tests__/parser.test.ts b/apps/server/src/utils/__tests__/parser.test.ts index 84d5d57f0..e459c4619 100644 --- a/apps/server/src/utils/__tests__/parser.test.ts +++ b/apps/server/src/utils/__tests__/parser.test.ts @@ -645,6 +645,8 @@ describe('test import of v2 datamodel', () => { onStop: [], onUpdate: [], onFinish: [], + onWarning: [], + onDanger: [], }, }, http: { diff --git a/apps/server/src/utils/__tests__/parserFunctions.test.ts b/apps/server/src/utils/__tests__/parserFunctions.test.ts index 0d38aa920..d270a95e9 100644 --- a/apps/server/src/utils/__tests__/parserFunctions.test.ts +++ b/apps/server/src/utils/__tests__/parserFunctions.test.ts @@ -33,6 +33,8 @@ describe('sanitiseOscSubscriptions()', () => { { id: '4', cycle: 'onStop', address: '/test', payload: 'test', enabled: false }, { id: '5', cycle: 'onUpdate', address: '/test', payload: 'test', enabled: true }, { id: '6', cycle: 'onFinish', address: '/test', payload: 'test', enabled: false }, + { id: '7', cycle: 'onWarning', address: '/test', payload: 'test', enabled: false }, + { id: '8', cycle: 'onDanger', address: '/test', payload: 'test', enabled: false }, ]; const sanitationResult = sanitiseOscSubscriptions(oscSubscriptions); expect(sanitationResult).toStrictEqual(oscSubscriptions); @@ -69,6 +71,8 @@ describe('sanitiseHttpSubscriptions()', () => { { id: '4', cycle: 'onStop', message: 'http://test', enabled: false }, { id: '5', cycle: 'onUpdate', message: 'http://test', enabled: true }, { id: '6', cycle: 'onFinish', message: 'http://test', enabled: false }, + { id: '7', cycle: 'onWarning', message: 'http://test', enabled: false }, + { id: '8', cycle: 'onDanger', message: 'http://test', enabled: false }, ]; const sanitationResult = sanitiseHttpSubscriptions(httpSubscription); expect(sanitationResult).toStrictEqual(httpSubscription); diff --git a/packages/types/src/definitions/core/TimerLifecycle.type.ts b/packages/types/src/definitions/core/TimerLifecycle.type.ts index d7ab012db..0d48e0243 100644 --- a/packages/types/src/definitions/core/TimerLifecycle.type.ts +++ b/packages/types/src/definitions/core/TimerLifecycle.type.ts @@ -6,6 +6,8 @@ export enum TimerLifeCycle { onClock = 'onClock', onUpdate = 'onUpdate', onFinish = 'onFinish', + onWarning = 'onWarning', + onDanger = 'onDanger', } export type TimerLifeCycleKey = keyof typeof TimerLifeCycle;