@@ -106,24 +106,10 @@ export function useWebRtcStream({ token }: UseWebRtcStreamOptions) {
106106 } ) . catch ( console . error )
107107 }
108108
109- // Send input PC offer to server immediately
110- const sendInputOffer = async ( ) => {
111- const offer = await inputPc . createOffer ( )
112- await inputPc . setLocalDescription ( offer )
113- await fetch ( "/api/webrtc/input-offer" , {
114- method : "POST" ,
115- headers : {
116- "Content-Type" : "application/json" ,
117- ...( token ? { Authorization : `Bearer ${ token } ` } : { } ) ,
118- } ,
119- body : JSON . stringify ( { sessionId : activeSessionId , sdp : offer . sdp } ) ,
120- } )
121- }
122-
123- sendInputOffer ( ) . catch ( console . error )
124-
125109 // ── SSE bridge: handles both video offer and input-answer ────────────
126- const sseUrl = `/api/webrtc/events?sessionId=${ activeSessionId } ${ token ? `&token=${ token } ` : "" } `
110+ const sseParams = new URLSearchParams ( { sessionId : activeSessionId } )
111+ if ( token ) sseParams . set ( "token" , token )
112+ const sseUrl = `/api/webrtc/events?${ sseParams . toString ( ) } `
127113 const sse = new EventSource ( sseUrl )
128114 sseSourceRef . current = sse
129115
@@ -226,6 +212,20 @@ export function useWebRtcStream({ token }: UseWebRtcStreamOptions) {
226212 inputIceQueue . push ( candidateInit )
227213 }
228214 } )
215+ const sendInputOffer = async ( ) => {
216+ const offer = await inputPc . createOffer ( )
217+ await inputPc . setLocalDescription ( offer )
218+ await fetch ( "/api/webrtc/input-offer" , {
219+ method : "POST" ,
220+ headers : {
221+ "Content-Type" : "application/json" ,
222+ ...( token ? { Authorization : `Bearer ${ token } ` } : { } ) ,
223+ } ,
224+ body : JSON . stringify ( { sessionId : activeSessionId , sdp : offer . sdp } ) ,
225+ } )
226+ }
227+
228+ sendInputOffer ( ) . catch ( console . error )
229229
230230 return ( ) => {
231231 sse . close ( )
0 commit comments