diff --git a/backend/src/index.js b/backend/src/index.js index e92ee7c..3736d98 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -194,7 +194,23 @@ io.on('connection', (socket) => { websocketConnections.inc(); trackUniqueUser(user.jiraAccountId); trackUniqueTenant(user.jiraCloudId); - socket.on('disconnect', () => { websocketConnections.dec(); }); + socket.on('disconnect', async () => { + websocketConnections.dec(); + for (const room of socket.rooms) { + if (!room.startsWith('poker:')) continue; + const sessionId = room.slice(6); + try { + await leaveSession({ + sessionId, + tenantCloudId: socket.user.jiraCloudId, + userKey: socket.user.jiraAccountId + }); + await emitSessionState(sessionId, socket.user.jiraCloudId); + } catch { + // best-effort cleanup + } + } + }); const throttled = socketThrottle(socket); throttled('poker:join', async ({ sessionId }) => {