From 1074eb48dcb41e6230b6a6ff312cd0062fef517c Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Sun, 7 Sep 2025 22:18:52 -0700 Subject: [PATCH] Fix WebRTC connection for receive-only bots (whisper bot) - Add receive-only transceivers for bots with no local media tracks - Resolves ICE gathering timeout issues for whisper bot - Enables proper SDP negotiation for audio/video reception - Whisper bot can now establish WebRTC connections successfully The whisper bot is receive-only (transcribes audio, doesn't send media) but WebRTC negotiation failed without proper transceivers. This fix automatically adds recvonly audio/video transceivers when a bot has no local tracks, allowing proper connection establishment. --- voicebot/webrtc_signaling.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/voicebot/webrtc_signaling.py b/voicebot/webrtc_signaling.py index e830c3d..0861ad2 100644 --- a/voicebot/webrtc_signaling.py +++ b/voicebot/webrtc_signaling.py @@ -812,8 +812,20 @@ class WebRTCSignalingClient: transceiver = pc.addTransceiver(track, direction="sendrecv") logger.debug(f"_handle_add_peer: Added transceiver for {track.kind}, mid: {transceiver.mid}") - # Create offer if needed + # For bots with no local tracks (like whisper), add receive-only transceivers + # to ensure proper SDP negotiation for incoming audio/video + if not self.local_tracks: + logger.info(f"_handle_add_peer: No local tracks for {peer_name}, adding receive-only transceivers") + # Add receive-only audio transceiver for bots that need to receive audio + audio_transceiver = pc.addTransceiver("audio", direction="recvonly") + logger.debug(f"_handle_add_peer: Added receive-only audio transceiver, mid: {audio_transceiver.mid}") + # Add receive-only video transceiver to handle any incoming video + video_transceiver = pc.addTransceiver("video", direction="recvonly") + logger.debug(f"_handle_add_peer: Added receive-only video transceiver, mid: {video_transceiver.mid}") + + # Create offer if instructed by server coordination if should_create_offer: + logger.info(f"Creating offer for {peer_name} as instructed by server") await self._create_and_send_offer(peer_id, peer_name, pc) if self.on_peer_added: