Clean up session participants on socket disconnect
All checks were successful
Build & Push Container Image / build (push) Successful in 5s
All checks were successful
Build & Push Container Image / build (push) Successful in 5s
When a user closes their browser or navigates away, the socket disconnects without emitting poker:leave. The participant stayed in the NATS session data indefinitely. Now the disconnect handler iterates the socket's poker rooms and calls leaveSession for each, then broadcasts the updated state to remaining participants. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5b83dd7ed0
commit
a7aac985d2
1 changed files with 17 additions and 1 deletions
|
|
@ -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 }) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue