Skip to content

Commit c6011e3

Browse files
committed
[FE] feat: WebRTC 사용시 필요한 userId를 전역 상태 값으로 사용 (#74)
1 parent 39f4f8f commit c6011e3

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

src/frontend/src/pages/ChannelPage/index.tsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, { useEffect, useRef, useState } from 'react';
44
import { getUserId } from '@/api/users';
55
import { useChannelActionStore } from '@/stores/channelAction';
66
import { tokenAxios } from '@/utils/axios';
7+
import { useUserInfoStore } from '@/stores/userInfo';
78

89
const SERVER_URL = import.meta.env.VITE_SIGNALING;
910

@@ -25,7 +26,6 @@ const WebRTC = () => {
2526
const localVideoRef = useRef<HTMLVideoElement | null>(null);
2627
const remoteVideoRef = useRef<HTMLVideoElement | null>(null);
2728
const peerConnection = useRef<RTCPeerConnection | null>(null);
28-
const [userId, setUserId] = useState('');
2929

3030
// 구독된 publisher id들을 저장
3131
const [subscribedPublishers, setSubscribedPublishers] = useState<string[]>([]);
@@ -52,24 +52,8 @@ const WebRTC = () => {
5252

5353
const token = localStorage.getItem('access_token');
5454

55-
useEffect(() => {
56-
const fetchUserId = async () => {
57-
const token = localStorage.getItem('access_token');
58-
if (!token) {
59-
return;
60-
}
61-
62-
try {
63-
const id = await getUserId();
64-
setUserId(id);
65-
console.log('사용자 ID 가져오기 성공:', id);
66-
} catch (error) {
67-
console.error('사용자 ID 가져오기 실패:', error);
68-
}
69-
};
70-
71-
fetchUserId();
72-
}, []);
55+
const { userInfo } = useUserInfoStore();
56+
const userId = userInfo?.userId || '';
7357

7458
// ✅ STOMP WebSocket 연결 함수
7559
const connectStomp = async () => {
@@ -304,6 +288,7 @@ const WebRTC = () => {
304288
console.log(user);
305289
await handlePublish(user.id);
306290
}
291+
setFirstEnter(false);
307292
}
308293
};
309294

0 commit comments

Comments
 (0)