mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 11:23:50 +00:00
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
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
import { socketProvider } from '../classes/socket/SocketController.js';
|
||||
|
||||
const store = {};
|
||||
|
||||
/**
|
||||
* A runtime store that broadcasts its payload
|
||||
*/
|
||||
export const eventStore = {
|
||||
get(key) {
|
||||
return store[key];
|
||||
},
|
||||
set(key, value) {
|
||||
store[key] = value;
|
||||
socketProvider.send(key, value);
|
||||
},
|
||||
poll() {
|
||||
return store;
|
||||
},
|
||||
broadcast() {
|
||||
socketProvider.send(store);
|
||||
socketProvider.broadcastState();
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
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,
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user