Skip to content

Commit dee84cc

Browse files
committed
✨ feat: (FE) - 방 나갔을때 cleanup 로직 추가
1 parent 95034e5 commit dee84cc

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

frontend/src/components/BottomBar/BottomBar.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { socketEmit } from '@api/socket.api';
3030
import { SOCKET_EVENT_TYPE } from '@constants/socket.constant';
3131
import useSafeNavigate from '@hooks/useSafeNavigate';
3232
import { PAGE_TYPE } from '@constants/page.constant';
33+
import useCleanupRoom from '@hooks/useCleanupRoom';
3334

3435
interface Props {
3536
mainController?: React.ReactNode;
@@ -43,6 +44,7 @@ enum DRAWER_TYPE {
4344

4445
const BottomBar = ({ mainController }: Props) => {
4546
const { safeNavigate } = useSafeNavigate();
47+
const cleanupRoom = useCleanupRoom();
4648
const [isMicOn, setIsMicOn] = useState(true);
4749
const [isCameraOn, setIsCameraOn] = useState(true);
4850

@@ -78,6 +80,7 @@ const BottomBar = ({ mainController }: Props) => {
7880

7981
const handleLeaveRoom = () => {
8082
socketEmit(SOCKET_EVENT_TYPE.LEAVE_ROOM);
83+
cleanupRoom();
8184
safeNavigate(PAGE_TYPE.LANDING_PAGE);
8285
};
8386

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { meInRoomState, othersInRoomState, roomUUIDState } from '@store/room.store';
2+
import { webRTCUserMapState } from '@store/webRTC.store';
3+
import { useCallback } from 'react';
4+
import { useResetRecoilState } from 'recoil';
5+
import useCleanupInterview from './useCleanupInterview';
6+
7+
const useCleanupRoom = () => {
8+
const cleanupInterview = useCleanupInterview();
9+
const roomUUIDRefresher = useResetRecoilState(roomUUIDState);
10+
const ohtersRefresher = useResetRecoilState(othersInRoomState);
11+
const meRefresher = useResetRecoilState(meInRoomState);
12+
const webRTCUserMapRefresher = useResetRecoilState(webRTCUserMapState);
13+
14+
const cleanupRoom = useCallback(() => {
15+
console.log('cleanup room');
16+
roomUUIDRefresher();
17+
ohtersRefresher();
18+
meRefresher();
19+
webRTCUserMapRefresher();
20+
21+
cleanupInterview();
22+
}, []);
23+
24+
return cleanupRoom;
25+
};
26+
27+
export default useCleanupRoom;

frontend/src/pages/Lobby/Lobby.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ interface joinInterviewResponseType {
2525
}
2626

2727
const Lobby = () => {
28+
usePreventLeave();
2829
const { safeNavigate } = useSafeNavigate();
2930
const [me, setMe] = useRecoilState<UserType>(meInRoomState);
3031
const [others, setOthers] = useRecoilState<UserType[]>(othersInRoomState);
31-
32-
usePreventLeave();
33-
3432
const [webRTCUserList, setWebRTCUserList] = useRecoilState(webRTCUserMapState);
3533
const { startConnection } = useWebRTCSignaling(webRTCUserList, setWebRTCUserList);
36-
3734
const streamList = useRecoilValue(webRTCStreamSelector);
3835

3936
useEffect(() => {

frontend/src/service/socket.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { io } from 'socket.io-client';
22

3-
export const socket = io('/socket');
3+
export const socket = io('/socket');

0 commit comments

Comments
 (0)