Files
ontime/apps/server/src/services/integration-service/IntegrationService.ts
T
2024-04-29 22:40:39 +02:00

38 lines
1.0 KiB
TypeScript

import { LogOrigin } from 'ontime-types';
import IIntegration, { TimerLifeCycleKey } from './IIntegration.js';
import { eventStore } from '../../stores/EventStore.js';
import { logger } from '../../classes/Logger.js';
class IntegrationService {
private integrations: IIntegration<unknown, unknown>[];
constructor() {
this.integrations = [];
}
register(integrationService: IIntegration<unknown, unknown>) {
this.integrations.push(integrationService);
}
unregister(integrationService: IIntegration<unknown, unknown>) {
this.integrations = this.integrations.filter((int) => int !== integrationService);
}
dispatch(action: TimerLifeCycleKey) {
const state = eventStore.poll();
this.integrations.forEach((integration) => {
integration.dispatch(action, state);
});
}
shutdown() {
logger.info(LogOrigin.Tx, 'Shutdown Integrations');
this.integrations.forEach((integration) => {
integration.shutdown();
});
}
}
export const integrationService = new IntegrationService();