Skip to content

Gather ICE candidates continually by default - #1299

Open
evgeniy-gera-it wants to merge 1 commit into
livekit:mainfrom
evgeniy-gera-it:continual-gathering-policy
Open

evgeniy-gera-it wants to merge 1 commit into
livekit:mainfrom
evgeniy-gera-it:continual-gathering-policy

Conversation

@evgeniy-gera-it

Copy link
Copy Markdown

What

  • Adds RTCConfiguration.continualGatheringPolicy (RTCContinualGatheringPolicy.gatherOnce / gatherContinually), with copyWith and toMap ('gather_once' / 'gather_continually', the values flutter_webrtc reads).
  • Engine._buildRtcConfiguration sets gatherContinually when the app leaves the field unset. An explicit value from the app is kept.

Why

The other LiveKit SDKs create peer connections with continual gathering:

The Flutter SDK never sends the key, so flutter_webrtc keeps the libwebrtc default, GATHER_ONCE (api/peer_connection_interface.h#L515, Android PeerConnection.java#L621). With gather-once, the port allocator session is stopped after the first gathering (p2p_transport_channel.cc#L2011-L2015), and a stopped session does not allocate ports for a new network (basic_port_allocator.cc#L883-L890). On a Wi-Fi to cellular switch, a mobile client then gets no candidates on the new network until the engine does an ICE restart. flutter_webrtc 1.6.3 already maps the key on iOS/macOS (FlutterWebRTCPlugin.m:2336) and Android (MethodCallHandlerImpl.java:1525).

libwebrtc refuses to change the policy once gathering has started (p2p_transport_channel.cc#L545-L553). The resume path re-applies the same configuration, so the value never changes on a live transport.

Web and Windows/Linux ignore the key (the JS SDK already sets it on web).

Test

  • test/core/continual_gathering_policy_test.dart: toMap/copyWith; both transports are created with gather_continually by default, with an explicit gatherOnce, and together with iceTransportPolicy: relay.
  • test/core/leave_action_test.dart: the configuration re-applied on resume keeps the policy.
  • flutter test, flutter analyze, dart analyze web/, dart format, import_sorter, check_version pass locally.

Changeset: .changes/continual-gathering-policy (minor, added).

Closes #1298

@CLAassistant

CLAassistant commented Nov 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@hiroshihorie

Copy link
Copy Markdown
Member

Thanks for the PR! Looks good overall. Could you sign the CLA so we can move forward?

Add RTCConfiguration.continualGatheringPolicy and default it to
gather_continually in the engine, as the Swift, Android and JS SDKs do.
libwebrtc gathers once by default, so after a network change new
candidates only arrived with an ICE restart. An explicit value from the
app is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SXscSZpJKcfcD8fbpAsCtB
@evgeniy-gera-it
evgeniy-gera-it force-pushed the continual-gathering-policy branch from 5ec527a to 137efc2 Compare November 20, 2026 17:11

This branch has not been deployed

No deployments
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.

RTCConfiguration has no continualGatheringPolicy; Flutter peer connections gather ICE candidates only once

3 participants