diff --git a/apps/server/src/services/integration-service/IntegrationService.ts b/apps/server/src/services/integration-service/IntegrationService.ts index 4c8e59086..40ac2b0da 100644 --- a/apps/server/src/services/integration-service/IntegrationService.ts +++ b/apps/server/src/services/integration-service/IntegrationService.ts @@ -1,7 +1,7 @@ import { LogOrigin } from 'ontime-types'; import IIntegration, { TimerLifeCycleKey } from './IIntegration.js'; -import { eventStore } from '../../stores/EventStore.js'; +import { getState } from '../../stores/runtimeState.js'; import { logger } from '../../classes/Logger.js'; class IntegrationService { @@ -20,7 +20,14 @@ class IntegrationService { } dispatch(action: TimerLifeCycleKey) { - const state = eventStore.poll(); + /** + * We currently get the state from the runtimeState store + * This solves an issue where the state is not updated until after the integrations have ran + * The workaround solves the issue with the tradeoff of + * - we do not have access to data outside runtimeState (eg: messages or auxtimers) + * - we couple the integrationService to runtimeState + */ + const state = getState(); this.integrations.forEach((integration) => { integration.dispatch(action, state); }); diff --git a/apps/server/src/services/runtime-service/RuntimeService.ts b/apps/server/src/services/runtime-service/RuntimeService.ts index 12e258975..fc2e28850 100644 --- a/apps/server/src/services/runtime-service/RuntimeService.ts +++ b/apps/server/src/services/runtime-service/RuntimeService.ts @@ -196,6 +196,8 @@ class RuntimeService { const success = runtimeState.load(event, timedEvents); if (success) { + // TODO: dispatch should happen after store update + // currently store update is handled in TimerService only integrationService.dispatch(TimerLifeCycle.onLoad); logger.info(LogOrigin.Playback, `Loaded event with ID ${event.id}`); }