Files
ontime/apps/server/src/stores/EventStore.ts
T
Carlos Valente 76c8f8a4d5 V2 ws store (#310)
* Update TimerService.ts

* refactor: message service publishes to store

* refactor: several type improvements

* V2 ws store wss (#309)

* refactor: shared logging types

* refactor: simplify message service consumption

* refactor: create discrete logging system

* refactor: move socket.io > websocket
2023-03-15 22:06:47 +01:00

32 lines
706 B
TypeScript

import { RuntimeStore } from 'ontime-types';
import { socket } from '../adapters/WebsocketAdapter.js';
const store: Partial<RuntimeStore> = {};
/**
* A runtime store that broadcasts its payload
*/
export const eventStore = {
get<T extends keyof RuntimeStore>(key: T) {
return store[key];
},
set<T extends keyof RuntimeStore>(key: T, value: RuntimeStore[T]) {
store[key] = value;
// TODO: Partial updates seems to cause issues on the client
// socket.send({
// type: `ontime-${key}`,
// payload: value,
// });
this.broadcast();
},
poll() {
return store;
},
broadcast() {
socket.send({
type: 'ontime',
payload: store,
});
},
};