refactor: simplify messages

This commit is contained in:
Carlos Valente
2025-08-11 05:50:09 +02:00
committed by Carlos Valente
parent ae061cb69a
commit 54f07c4330
5 changed files with 8 additions and 19 deletions
+2 -10
View File
@@ -142,16 +142,8 @@ export const connectSocket = () => {
break; break;
} }
case MessageTag.RuntimeData: { case MessageTag.RuntimeData: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- removing the key from the payload patchRuntime(payload);
const { ping, ...serverPayload } = payload; updateDevTools(payload);
patchRuntime(serverPayload);
updateDevTools(serverPayload);
break;
}
case MessageTag.RuntimePatch: {
const patch = payload;
patchRuntime(patch);
updateDevTools(patch);
break; break;
} }
case MessageTag.Refetch: { case MessageTag.Refetch: {
+1 -1
View File
@@ -208,7 +208,7 @@ export const startServer = async (): Promise<{ message: string; serverPort: numb
playback: SimplePlayback.Stop, playback: SimplePlayback.Stop,
direction: SimpleDirection.CountDown, direction: SimpleDirection.CountDown,
}, },
ping: -1, ping: 1,
}); });
// initialise rundown service // initialise rundown service
+2 -2
View File
@@ -23,7 +23,7 @@ export const eventStore = {
}, },
set<T extends keyof RuntimeStore>(key: T, value: RuntimeStore[T]) { set<T extends keyof RuntimeStore>(key: T, value: RuntimeStore[T]) {
store[key] = value; store[key] = value;
socket.sendAsJson(MessageTag.RuntimePatch, { [key]: value }); socket.sendAsJson(MessageTag.RuntimeData, { [key]: value });
}, },
createBatch() { createBatch() {
const patch: Partial<RuntimeStore> = {}; const patch: Partial<RuntimeStore> = {};
@@ -34,7 +34,7 @@ export const eventStore = {
send() { send() {
if (isEmptyObject(patch)) return; if (isEmptyObject(patch)) return;
store = { ...store, ...patch }; store = { ...store, ...patch };
socket.sendAsJson(MessageTag.RuntimePatch, patch); socket.sendAsJson(MessageTag.RuntimeData, patch);
}, },
}; };
}, },
@@ -16,11 +16,10 @@ export enum MessageTag {
Dialog = 'dialog', Dialog = 'dialog',
Log = 'log', Log = 'log',
RuntimeData = 'runtime-data', RuntimeData = 'runtime-data',
RuntimePatch = 'runtime-patch',
Refetch = 'refetch', Refetch = 'refetch',
} }
//CLIENT TO SERVER // CLIENT TO SERVER
type PingPacket = { tag: MessageTag.Ping; payload: Date }; type PingPacket = { tag: MessageTag.Ping; payload: Date };
type SetClientPacket = { tag: MessageTag.ClientSetPath; payload: string }; type SetClientPacket = { tag: MessageTag.ClientSetPath; payload: string };
type SetClientPathPacket = { tag: MessageTag.ClientSet; payload: Partial<Client> }; type SetClientPathPacket = { tag: MessageTag.ClientSet; payload: Partial<Client> };
@@ -35,8 +34,7 @@ type ListClientPacket = {
tag: MessageTag.ClientList; tag: MessageTag.ClientList;
payload: Record<string, Client>; payload: Record<string, Client>;
}; };
type RuntimePacket = { tag: MessageTag.RuntimeData; payload: RuntimeStore }; type RuntimePacket = { tag: MessageTag.RuntimeData; payload: Partial<RuntimeStore> };
type RuntimePatchPacket = { tag: MessageTag.RuntimePatch; payload: Partial<RuntimeStore> };
type RefetchPacket = { type RefetchPacket = {
tag: MessageTag.Refetch; tag: MessageTag.Refetch;
@@ -59,5 +57,4 @@ export type WsPacketToClient =
| LogPacket | LogPacket
| ListClientPacket | ListClientPacket
| RuntimePacket | RuntimePacket
| RuntimePatchPacket
| RefetchPacket; | RefetchPacket;
@@ -64,5 +64,5 @@ export const runtimeStorePlaceholder: Readonly<RuntimeStore> = {
duration: 0, duration: 0,
playback: SimplePlayback.Stop, playback: SimplePlayback.Stop,
}, },
ping: -1, ping: 1,
}; };