@@ -4,6 +4,7 @@ import React, { useEffect, useRef, useState } from 'react';
44import { getUserId } from '@/api/users' ;
55import { useChannelActionStore } from '@/stores/channelAction' ;
66import { tokenAxios } from '@/utils/axios' ;
7+ import { useUserInfoStore } from '@/stores/userInfo' ;
78
89const 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