diff --git a/backend/src/server.ts b/backend/src/server.ts index a594b6a..60d77de 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -2,7 +2,7 @@ import express from 'express'; import cors from 'cors'; import { createServer } from 'node:http'; import { WebSocketServer } from 'ws'; -import { AccessToken } from 'livekit-server-sdk'; +import { AccessToken, RoomConfiguration } from 'livekit-server-sdk'; import { env } from './env.js'; import { createSyncPr } from './github/client.js'; import { recordOutcome, memoryStats } from './memory/store.js'; @@ -36,6 +36,9 @@ app.post('/api/token', async (req, res) => { metadata: JSON.stringify({ githubLogin: githubLogin ?? name }), }); at.addGrant({ roomJoin: true, room, canPublish: true, canSubscribe: true, canPublishData: true }); + // Auto-clean the room: close 60s after it empties, drop a participant 20s + // after they disconnect. Applied when LiveKit auto-creates the room. + at.roomConfig = new RoomConfiguration({ name: room, emptyTimeout: 60, departureTimeout: 20 }); res.json({ token: await at.toJwt(), url: env.LIVEKIT_URL }); }); diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index a7e2859..d5e3622 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -47,7 +47,9 @@ export default function App() { // Connect to a pod's LiveKit room and persist the session for refresh-resume. async function connectToPod(podId: string, who: string) { - const identity = `${who}-${Math.random().toString(36).slice(2, 7)}`; + // Stable identity per member so a refresh/rejoin replaces the existing + // session instead of leaving a ghost participant behind. + const identity = who; const result = await joinPod(podId, identity, who); setRoom(result.room); setDevMode(result.mode === 'dev');