File tree Expand file tree Collapse file tree 3 files changed +17
-5
lines changed
Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -730,7 +730,7 @@ export default function ChatPage() {
730730 )
731731 if ( ! rtcTokenResponse . ok )
732732 throw new Error ( "Could not initiate voice session." )
733- const { rtc_token } = await rtcTokenResponse . json ( )
733+ const { rtc_token, ice_servers } = await rtcTokenResponse . json ( )
734734
735735 // Step 3: Create and connect WebRTCClient directly
736736 if ( webrtcClientRef . current ) {
@@ -753,7 +753,8 @@ export default function ChatPage() {
753753 }
754754 } ,
755755 onAudioLevel : handleAudioLevel ,
756- onEvent : handleVoiceEvent
756+ onEvent : handleVoiceEvent ,
757+ iceServers : ice_servers . iceServers
757758 } )
758759 webrtcClientRef . current = client
759760
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export class WebRTCClient {
1010 this . animationFrameId = null
1111 this . serverUrl =
1212 process . env . NEXT_PUBLIC_APP_SERVER_URL || "http://localhost:5000"
13+ this . iceServers = options . iceServers || [ ] // Store iceServers from options
1314
1415 // --- MODIFICATION: Add a queue for ICE candidates ---
1516 this . iceCandidateQueue = [ ]
@@ -33,7 +34,13 @@ export class WebRTCClient {
3334 this . iceCandidateQueue = [ ]
3435
3536 try {
36- this . peerConnection = new RTCPeerConnection ( )
37+ this . peerConnection = new RTCPeerConnection ( {
38+ iceServers : this . iceServers
39+ } )
40+ console . log ( "Created RTCPeerConnection with config:" , {
41+ iceServers : this . iceServers
42+ } )
43+
3744 console . log ( "Created RTCPeerConnection:" , this . peerConnection )
3845
3946 // --- MODIFICATION: Queue ICE candidates instead of sending immediately ---
Original file line number Diff line number Diff line change @@ -30,7 +30,8 @@ async def initiate_voice_session(
3030 user_id : str = Depends (PermissionChecker (required_permissions = ["read:chat" ]))
3131):
3232 """
33- Generates a short-lived, single-use token for authenticating a WebRTC/WebSocket voice stream.
33+ Generates a short-lived, single-use token for authenticating a WebRTC/WebSocket voice stream
34+ and provides the necessary ICE server configuration.
3435 """
3536 # Clean up expired tokens to prevent the cache from growing indefinitely
3637 now = time .time ()
@@ -43,8 +44,11 @@ async def initiate_voice_session(
4344 expires_at = now + TOKEN_EXPIRATION_SECONDS
4445 rtc_token_cache [rtc_token ] = {"user_id" : user_id , "expires_at" : expires_at }
4546
47+ # Get TURN credentials to send to the client
48+ ice_servers_config = get_credentials ()
49+
4650 logger .info (f"Initiated voice session for user { user_id } with token { rtc_token } " )
47- return {"rtc_token" : rtc_token }
51+ return {"rtc_token" : rtc_token , "ice_servers" : ice_servers_config }
4852
4953
5054class MyVoiceChatHandler (ReplyOnPause ):
You can’t perform that action at this time.
0 commit comments