From d7d8896e439b12dc57024bbb330200ad3ab2abf2 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 7 Jun 2024 21:38:09 -0700 Subject: [PATCH] fix: active users --- backend/apps/socket/main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/apps/socket/main.py b/backend/apps/socket/main.py index debbe22ea..e70812867 100644 --- a/backend/apps/socket/main.py +++ b/backend/apps/socket/main.py @@ -134,13 +134,17 @@ async def remove_after_timeout(sid, model_id): @sio.event async def disconnect(sid): - if sid in USER_POOL: - disconnected_user = SESSION_POOL.pop(sid) - USER_POOL[disconnected_user].remove(sid) - if len(USER_POOL[disconnected_user]) == 0: - del USER_POOL[disconnected_user] + if sid in SESSION_POOL: + user_id = SESSION_POOL[sid] + del SESSION_POOL[sid] - print(f"user {disconnected_user} disconnected with session ID {sid}") + USER_POOL[user_id].remove(sid) + + if len(USER_POOL[user_id]) == 0: + del USER_POOL[user_id] + + print(f"user {user_id} disconnected with session ID {sid}") + print(USER_POOL) await sio.emit("user-count", {"count": len(USER_POOL)}) else: