@@ -124,14 +124,18 @@ const VideoTest = () => {
124124 if ( user . sdpAnswer ) {
125125 setStatusMessage ( '응답을 받았습니다. 연결 중...' ) ;
126126
127+ console . log ( answers ?. message ) ;
128+
127129 try {
128130 if ( pcRef . current ) {
131+ console . log ( '원격 설명 설정 시도' ) ;
129132 await pcRef . current . setRemoteDescription (
130133 new RTCSessionDescription ( {
131134 type : 'answer' ,
132135 sdp : answers ?. message ,
133136 } ) ,
134137 ) ;
138+ console . log ( '원격 설명 설정 완료' ) ;
135139 }
136140
137141 if ( pendingCandidates . current . length > 0 ) {
@@ -200,6 +204,10 @@ const VideoTest = () => {
200204
201205 console . log ( '[pc] PeerConnection 구성됨:' , pcRef . current ) ;
202206
207+ pcRef . current . onsignalingstatechange = ( ) => {
208+ console . log ( '[pc] Signaling 상태 변경:' , pcRef . current ?. signalingState ) ;
209+ } ;
210+
203211 // ICE 후보 수집 상태 모니터링
204212 pcRef . current . onicegatheringstatechange = ( ) => {
205213 console . log ( '[pc] ICE 수집 상태:' , pcRef . current ?. iceGatheringState ) ;
@@ -231,16 +239,27 @@ const VideoTest = () => {
231239 if ( event . candidate && token && client ) {
232240 console . log ( '[pc] 생성된 ICE Candidate:' , event . candidate . candidate ) ;
233241
234- client . publish ( {
235- destination : '/candidate' ,
236- body : JSON . stringify ( {
237- type : MessageType . CANDIDATE ,
238- data : {
239- room_id : roomId ,
240- candidate : event . candidate . candidate ,
241- } ,
242- } ) ,
243- } ) ;
242+ pendingCandidates . current . push ( event . candidate ) ;
243+
244+ if ( client && client . connected ) {
245+ try {
246+ client . publish ( {
247+ destination : '/candidate' ,
248+ body : JSON . stringify ( {
249+ type : MessageType . CANDIDATE ,
250+ data : {
251+ room_id : roomId ,
252+ candidate : event . candidate . candidate ,
253+ } ,
254+ } ) ,
255+ } ) ;
256+ console . log ( 'ICE candidate 전송 성공' ) ;
257+ } catch ( err ) {
258+ console . error ( 'ICE candidate 전송 오류:' , err ) ;
259+ }
260+ } else {
261+ console . log ( 'STOMP 연결이 없어 candidate를 큐에 저장합니다' ) ;
262+ }
244263 } else {
245264 console . log ( '[pc] ICE Candidate 수집 완료' ) ;
246265 }
@@ -397,6 +416,11 @@ const VideoTest = () => {
397416 } ;
398417
399418 const joinRoom = async ( ) => {
419+ if ( ! roomId . trim ( ) ) {
420+ setStatusMessage ( '방 ID를 입력하세요' ) ;
421+ return ;
422+ }
423+
400424 setStatusMessage ( '방 참여 중...' ) ;
401425
402426 if ( token && isConnected && client ) {
@@ -426,6 +450,7 @@ const VideoTest = () => {
426450 } ) ;
427451
428452 await pcRef . current ! . setLocalDescription ( offer ) ;
453+ console . log ( '로컬 설명 설정됨:' , pcRef . current ! . localDescription ) ;
429454
430455 setTimeout ( ( ) => {
431456 if ( token && pcRef . current ?. localDescription ) {
@@ -664,6 +689,34 @@ const VideoTest = () => {
664689 }
665690 } , [ isSharingScreen ] ) ;
666691
692+ // STOMP 연결 상태 변경 감지
693+ useEffect ( ( ) => {
694+ if ( isConnected && client && pendingCandidates . current . length > 0 && roomId ) {
695+ console . log ( `연결 복구 - ${ pendingCandidates . current . length } 개의 대기 중인 ICE candidate 전송 시도` ) ;
696+
697+ // 대기 중인 모든 후보 전송 시도
698+ for ( const candidate of pendingCandidates . current ) {
699+ try {
700+ client . publish ( {
701+ destination : '/candidate' ,
702+ body : JSON . stringify ( {
703+ type : MessageType . CANDIDATE ,
704+ data : {
705+ room_id : roomId ,
706+ candidate : candidate . candidate ,
707+ } ,
708+ } ) ,
709+ } ) ;
710+ console . log ( '대기 중인 ICE candidate 전송 성공' ) ;
711+ } catch ( err ) {
712+ console . error ( '대기 중인 ICE candidate 전송 오류:' , err ) ;
713+ }
714+ }
715+
716+ pendingCandidates . current = [ ] ;
717+ }
718+ } , [ isConnected , client , roomId ] ) ;
719+
667720 return (
668721 < div style = { { padding : '1rem' } } onClick = { playAllVideos } >
669722 < h2 > 테스트 페이지</ h2 >
0 commit comments