Skip to content

Commit

Permalink
Fix extra cursor issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Singa-pirate committed Nov 13, 2024
1 parent 8144b3d commit 838c2b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backend/collaboration-service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
20 changes: 8 additions & 12 deletions frontend/src/components/CodeContainer/CodeContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,6 @@ const CodeContainer: React.FC<CodeContainerProps> = ({
}));
});

// 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}`);
Expand All @@ -246,8 +236,14 @@ const CodeContainer: React.FC<CodeContainerProps> = ({
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?",
Expand Down

0 comments on commit 838c2b7

Please sign in to comment.