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:
Carlos Valente
2023-03-15 22:06:47 +01:00
committed by GitHub
parent 11648ee546
commit 76c8f8a4d5
86 changed files with 1876 additions and 1936 deletions
-23
View File
@@ -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();
},
};
+31
View File
@@ -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,
});
},
};