fix(sse): buffer session events for late subscribers + clear on close

The Pi process produces events immediately after session creation, but
the browser's SSE connection may not be open yet (React re-render delay,
navigation). The hub discarded events with no subscribers, so the user
saw a blank session.

- Ring-buffer up to 200 events per session; replay on subscribe
- hub.clear(id) on POST /sessions/:id/close frees memory
This commit is contained in:
User
2026-07-13 00:01:11 +02:00
parent 0d8a8eb59f
commit dfe2774a1a
2 changed files with 38 additions and 1 deletions
+3 -1
View File
@@ -62,7 +62,9 @@ export function sessionRoutes(
return reply.code(200).send({ id });
});
app.post("/sessions/:id/close", async (req) => {
d.mgr.teardown((req.params as any).id);
const id = (req.params as { id: string }).id;
d.mgr.teardown(id);
d.hub.clear(id);
return { closed: true };
});
app.get("/sessions/:id/events", (req, reply) => {