Skip to content

Comments

[fix/48-room-roulette-filter] - 실시간 동기화 안정화(필터 무한 루프 및 방 퇴장 로직 수정)#49

Merged
Parkchanyoung0710 merged 1 commit intodevelopfrom
fix/48-room-roulette-filter
Feb 12, 2026
Merged

[fix/48-room-roulette-filter] - 실시간 동기화 안정화(필터 무한 루프 및 방 퇴장 로직 수정)#49
Parkchanyoung0710 merged 1 commit intodevelopfrom
fix/48-room-roulette-filter

Conversation

@Parkchanyoung0710
Copy link
Contributor

@Parkchanyoung0710 Parkchanyoung0710 commented Feb 12, 2026

🛠 변경된 내용

  • 기존의 useEffect를 통한 상태 감지 방식에서 탈출하여 사용자의 클릭시점에만 소켓을 전송하도록 구조를 변경했습니다.
  • 서버에서 브로드캐스트된 데이터의 updatedBy와 현재 사용자의 id를 비교하여, 본인이 보낸 이벤트는 로컬 상태에 반영하지 않고 무시하도록 방어 로직을 추가
  • 서버 전송 데이터에 타임스탬프를 포함하고, 로컬의 최신 업데이트 시간보다 오래된 이벤트는 무시하도록 구현
  • 방 나가기 시스템 구현

🚀 결과

  • 무한 핑퐁 버그 완전 해결: 지연 시간이 긴 배포 환경에서도 소켓 이벤트가 무한 루프를 돌지 않고, 사용자가 클릭한 횟수만큼만 정확하게 통신
  • 방 나가기 시스템과 입장했습니다가 사용자가 나갔다 들어올 때 마다 노출

Summary by CodeRabbit

  • 새로운 기능

    • 방 퇴장 시 자동 호스트 재지정 및 상태 정리 기능 추가
    • 메시지 및 이벤트에 타임스탐프 추가로 시간 동기화 개선
  • 버그 수정

    • 중복된 방 입장 방지
    • 메시지 전송 시 발신자도 포함하여 브로드캐스트
  • 리팩토링

    • 오류 처리 로직 단순화 및 클라이언트 동기화 최적화

@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

워크스루

채팅 게이트웨이에서 방 입장(joinRoom) 로직을 강화하고 새로운 방 퇴장(leaveRoom) 핸들러를 추가했습니다. 중복 입장 방지, 역할 할당 이벤트 흐름, 방 상태 정리, 호스트 재할당 로직이 개선되었으며, 메시지 브로드캐스트 범위와 타임스탬프 처리도 업데이트되었습니다.

변경사항

코호트 / 파일(들) 요약
채팅 게이트웨이 핵심 로직
src/chat/gateways/chat.gateway.ts
joinRoom에서 중복 입장 방지, userJoined/systemMessage 이벤트 개선, roleAssigned 역할 할당 흐름 추가. leaveRoom 핸들러 신규 추가로 방 상태 정리, 호스트 재할당, 멤버 정리 기능 구현. sendMessage에서 메시지 브로드캐스트 범위 조정(발신자 포함). 타임스탬프 추가 및 에러 처리 단순화.

시퀀스 다이어그램

sequenceDiagram
    participant Client as 클라이언트
    participant Gateway as ChatGateway
    participant Room as 방 상태
    participant Others as 다른 멤버들

    rect rgba(100, 200, 150, 0.5)
    Note over Client,Others: 방 입장 흐름
    Client->>Gateway: joinRoom(roomCode)
    Gateway->>Room: 중복 입장 확인
    alt 이미 입장함
        Gateway-->>Client: 중복 입장 방지
    else 신규 입장
        Gateway->>Room: 방 상태 초기화 (필요시)
        Gateway->>Gateway: 호스트/게스트 역할 결정
        Gateway-->>Client: roleAssigned (역할, 메뉴)
        Gateway->>Others: systemMessage (입장 공지)
        Gateway->>Others: userJoined (사용자 정보)
    end
    end

    rect rgba(150, 150, 200, 0.5)
    Note over Client,Others: 방 퇴장 흐름
    Client->>Gateway: leaveRoom(roomCode)
    Gateway->>Room: 멤버십 검증
    Gateway->>Others: systemMessage (퇴장 공지)
    Gateway->>Others: userLeft (사용자 정보)
    Gateway->>Room: 클라이언트 방에서 제거
    alt 방이 비어있음
        Gateway->>Room: 방 상태 정리
    else 멤버 남아있음
        Gateway->>Room: 첫 남은 멤버를 호스트로 재할당
        Gateway->>Room: roleAssigned 알림
    end
    end
Loading

예상 코드 리뷰 노력

🎯 3 (보통) | ⏱️ ~25분

> 🐰 방 드나드는 길을 다듬었네,
> 중복은 막고 역할을 나누고,
> 손님이 떠날 때 방정리까지,
> 호스트가 바뀌면 알림 주고,
> 모두가 함께 노는 방이여 ✨

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Collaborator

@ramong26 ramong26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셔습니다!!

@Parkchanyoung0710 Parkchanyoung0710 merged commit 6f89148 into develop Feb 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[fix/48-room-roulette-filter] - 룰렛 필터 동기화 오류 수정

2 participants