Add pi web POC

This commit is contained in:
Federico Jaramillo Martinez
2026-05-07 11:12:23 +02:00
parent c9d82667df
commit adf9087e84
17 changed files with 6618 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
import type { WebSocket } from "ws";
export class SessionEventHub {
private readonly socketsBySession = new Map<string, Set<WebSocket>>();
add(sessionId: string, socket: WebSocket): void {
let sockets = this.socketsBySession.get(sessionId);
if (!sockets) {
sockets = new Set();
this.socketsBySession.set(sessionId, sockets);
}
sockets.add(socket);
socket.on("close", () => sockets?.delete(socket));
}
publish(sessionId: string, event: unknown): void {
const payload = JSON.stringify(event);
for (const socket of this.socketsBySession.get(sessionId) ?? []) {
if (socket.readyState === socket.OPEN) socket.send(payload);
}
}
}