diff --git a/app.py b/app.py index 54b79d0..dbd0d14 100644 --- a/app.py +++ b/app.py @@ -542,7 +542,13 @@ def on_disconnect(): room = Room.query.filter_by(name=room_name).first() room.remove_user(username) leave_room(room_name) + # Broadcast to all clients in the room that a user has left the room. emit("active_users", {"users": room.get_active_users()}, room=room_name) + emit( + "chat_message", + {"id": None, "content": f"{username} has left the room."}, + room=room.name, + ) # Remove session data from the database db.session.delete(user_session) db.session.commit() diff --git a/templates/chat.html b/templates/chat.html index 7acbf6b..0c01b97 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -36,6 +36,7 @@ +