| |
| |
| rooms = {} |
|
|
|
|
| def add_user_to_room(room_id: str, socket_id: str): |
| """Add a socket_id to the given room.""" |
| if room_id not in rooms: |
| rooms[room_id] = [] |
| if socket_id not in rooms[room_id]: |
| rooms[room_id].append(socket_id) |
|
|
|
|
| def remove_user_from_room(socket_id: str): |
| """Remove a socket_id from ALL rooms it belongs to.""" |
| for room_id in list(rooms.keys()): |
| if socket_id in rooms[room_id]: |
| rooms[room_id].remove(socket_id) |
| |
| if not rooms[room_id]: |
| del rooms[room_id] |
|
|
|
|
| def get_room_members(room_id: str) -> list: |
| """Return list of socket IDs in a room.""" |
| return rooms.get(room_id, []) |
|
|