mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-07 00:13:53 +00:00
76c8f8a4d5
* 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
32 lines
706 B
TypeScript
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,
|
|
});
|
|
},
|
|
};
|