Skip to content

feat(realtime): make WebRTC ICE candidates configurable#10231

Merged
mudler merged 1 commit into
masterfrom
feat/realtime-webrtc-ice
Jun 9, 2026
Merged

feat(realtime): make WebRTC ICE candidates configurable#10231
mudler merged 1 commit into
masterfrom
feat/realtime-webrtc-ice

Conversation

@localai-bot

Copy link
Copy Markdown
Collaborator

Summary

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) 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.goWebRTCNAT1To1IPs / WebRTCICEInterfaces fields + 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 configured SettingEngine.
  • core/http/endpoints/openai/realtime_webrtc_ice.gowebRTCSettingEngine + iceInterfaceFilter helpers.
  • 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

  • pion v4.2.11 APIs verified against the module source (SetNAT1To1IPs, SetInterfaceFilter, WithSettingEngine, ICECandidateTypeHost).
  • Ginkgo unit test for iceInterfaceFilter + webRTCSettingEngine.
  • Note: not built locally in this worktree (lacks generated pkg/grpc/proto + react-ui dist); CI / make protogen && make test-coverage-check is 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 201transport closed). Setting LOCALAI_WEBRTC_NAT_1TO1_IPS to the host LAN IP advertises only the routable candidate and keeps the session up.

🤖 Generated with Claude Code

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>
@mudler mudler merged commit b203b32 into master Jun 9, 2026
59 checks passed
@mudler mudler deleted the feat/realtime-webrtc-ice branch June 9, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants