diff --git a/backend/collaboration-service/server.py b/backend/collaboration-service/server.py index e105882b50..9305e92d0c 100644 --- a/backend/collaboration-service/server.py +++ b/backend/collaboration-service/server.py @@ -206,7 +206,7 @@ async def disconnect(sid): if room_still_exists and not room.submitted: try: - await sio.emit(Events.USER_LEFT, user.details(), room=room.id) + await sio.emit(Events.USER_LEFT, {"sid": sid, "uid": user.user_id}, room=room.id) logging.debug(f"Emitted USER_LEFT to room {room.id}") except Exception as e: logging.error(f"Failed to emit USER_LEFT for room {room.id}: {e}") diff --git a/frontend/src/components/CodeContainer/CodeContainer.tsx b/frontend/src/components/CodeContainer/CodeContainer.tsx index 76fe1d95ff..a2577e7b8f 100644 --- a/frontend/src/components/CodeContainer/CodeContainer.tsx +++ b/frontend/src/components/CodeContainer/CodeContainer.tsx @@ -219,16 +219,6 @@ const CodeContainer: React.FC = ({ })); }); - // Handle user disconnection to remove their cursor - socket.on("user_disconnected", (sid: string) => { - console.log(`User disconnected: ${sid}`); - setOtherCursors((prev) => { - const newCursors = { ...prev }; - delete newCursors[sid]; - return newCursors; - }); - }); - // Handle other user submitting code and ending session socket.on("code_submitted", (sid: string) => { console.log(`Code submitted: ${sid}`); @@ -246,8 +236,14 @@ const CodeContainer: React.FC = ({ console.error("Socket error:", error); }); - socket.on("user_left", (uid: string) => { - if (user && uid !== user.id) { + socket.on("user_left", (data: any) => { + console.log("User left: ", data); + if (user && user.id !== data.user_id) { + setOtherCursors((prev) => { + const newCursors = { ...prev }; + delete newCursors[data.sid]; + return newCursors; + }); setConfirmationDialogTitle("Partner Disconnected"); setConfirmationDialogContent( "Your partner has left the coding session. Would you like to end the session and return to home page?",