refactor: type session event protocol

This commit is contained in:
Federico Jaramillo Martinez
2026-05-07 23:51:26 +02:00
parent a77012ba83
commit 91957b0fe0
6 changed files with 24 additions and 16 deletions
+3 -2
View File
@@ -1,3 +1,4 @@
import type { GlobalSessionEvent, SessionUiEvent } from "../../shared/apiTypes.js";
import type { WebSocket } from "ws";
export class SessionEventHub {
@@ -21,14 +22,14 @@ export class SessionEventHub {
socket.on("close", () => this.globalSockets.delete(socket));
}
publish(sessionId: string, event: unknown): void {
publish(sessionId: string, event: SessionUiEvent): void {
const payload = JSON.stringify(event);
for (const socket of this.socketsBySession.get(sessionId) ?? []) {
if (socket.readyState === socket.OPEN) socket.send(payload);
}
}
publishGlobal(event: unknown): void {
publishGlobal(event: GlobalSessionEvent): void {
const payload = JSON.stringify(event);
for (const socket of this.globalSockets) {
if (socket.readyState === socket.OPEN) socket.send(payload);