feat(realtime): make WebRTC ICE candidates configurable#10231
Merged
Conversation
The /v1/realtime WebRTC handler created the peer connection with a bare webrtc.Configuration and no SettingEngine, so pion gathered a host ICE candidate for every local interface. Under Docker host networking that includes bridge addresses (docker0/veth, 172.x) a remote browser cannot route to; the call establishes on a good pair and then drops once ICE consent freshness checks fail on the unreachable candidates. Add two opt-in knobs, applied via a pion SettingEngine: - LOCALAI_WEBRTC_NAT_1TO1_IPS: advertise these IPs as the host candidates (e.g. the host LAN IP) - LOCALAI_WEBRTC_ICE_INTERFACES: restrict ICE gathering to these interfaces Defaults are unchanged (empty => current all-interface behavior). Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
/v1/realtimeWebRTC handler created the peer connection with a barewebrtc.Configuration{}and noSettingEngine, so pion gathered a host ICE candidate for every local interface. Under Docker host networking that includes bridge addresses (docker0/veth,172.x) that a remote browser cannot route to: the call establishes on a good candidate pair and then drops a few seconds later when ICE consent-freshness checks fail on the unreachable candidates.This adds two opt-in knobs, applied via a pion
SettingEngine:LOCALAI_WEBRTC_NAT_1TO1_IPS— advertise these IPs as the host ICE candidates (e.g. the host LAN IP) instead of every interface.LOCALAI_WEBRTC_ICE_INTERFACES— restrict ICE candidate gathering to named interfaces (e.g.eth0).Defaults are unchanged: empty → current all-interface behavior.
Changes
core/config/application_config.go—WebRTCNAT1To1IPs/WebRTCICEInterfacesfields +With…options.core/cli/run.go—--*/env flags wired into the app config.core/http/endpoints/openai/realtime_webrtc.go— build the peer connection with the configuredSettingEngine.core/http/endpoints/openai/realtime_webrtc_ice.go—webRTCSettingEngine+iceInterfaceFilterhelpers.core/http/endpoints/openai/realtime_webrtc_ice_test.go— Ginkgo specs for the filter / engine builder.docs/content/features/openai-realtime.md— "WebRTC behind Docker host networking or NAT" section.Testing
SetNAT1To1IPs,SetInterfaceFilter,WithSettingEngine,ICECandidateTypeHost).iceInterfaceFilter+webRTCSettingEngine.pkg/grpc/proto+ react-ui dist); CI /make protogen && make test-coverage-checkis the build gate.Motivation
Reproduced with a LAN browser → host-networked LocalAI: realtime transcription connected and produced transcripts, then WebRTC dropped ~12s in (
/v1/realtime/calls 201→transport closed). SettingLOCALAI_WEBRTC_NAT_1TO1_IPSto the host LAN IP advertises only the routable candidate and keeps the session up.🤖 Generated with Claude Code