Skip to content

feat: add WithSettingEngineFunc ConnectOption to customize the SettingEngine#935

Open
UbiShipDev1 wants to merge 1 commit into
livekit:mainfrom
UbiShipDev1:feat/setting-engine-func
Open

feat: add WithSettingEngineFunc ConnectOption to customize the SettingEngine#935
UbiShipDev1 wants to merge 1 commit into
livekit:mainfrom
UbiShipDev1:feat/setting-engine-func

Conversation

@UbiShipDev1

Copy link
Copy Markdown

Motivation

NewPCTransport builds its webrtc.SettingEngine internally with no extension point, so callers cannot influence ICE behavior beyond WithICETransportPolicy / WithDisableTURN.

We run a server-side agent co-located with the SFU on a host that has many interfaces (docker bridges, veth*, IPv6). pion gathers ICE host candidates from all of them and sometimes selects an unreachable one, silently breaking the subscriber media path (the agent goes "deaf"). The remedy is SettingEngine.SetInterfaceFilter / SetIPFilter, which the SDK doesn't expose.

Change

Adds a single, opt-in ConnectOption:

// WithSettingEngineFunc customizes the pion SettingEngine before the WebRTC
// API is constructed. Invoked for every PeerConnection (publisher + subscriber).
func WithSettingEngineFunc(fn func(*webrtc.SettingEngine)) ConnectOption

fn runs after the SDK finishes configuring the SettingEngine and before webrtc.NewAPI, so callers can layer ICE interface/IP filters, SetNAT1To1IPs, etc. without losing the SDK's own settings.

Usage:

room, err := lksdk.ConnectToRoom(url, info, cb,
    lksdk.WithSettingEngineFunc(func(se *webrtc.SettingEngine) {
        se.SetInterfaceFilter(func(name string) bool { return name == "eth0" || name == "lo" })
        se.SetIPFilter(func(ip net.IP) bool { return ip.To4() != nil })
    }),
)

Details

  • signalling.ConnectParams.SettingEngineFunc carries the hook; WithSettingEngineFunc sets it (mirrors the existing option pattern).
  • Threaded into both NewPCTransport calls (publisher + subscriber) and invoked in NewPCTransport just before webrtc.NewAPI.
  • No behavior change when unset. Unit test included (TestWithSettingEngineFunc). go build ./... && go test green.

Happy to adjust naming or scope to fit your conventions.

🤖 Generated with Claude Code

…gEngine

The SDK builds its webrtc.SettingEngine internally in NewPCTransport with no
extension point, so callers cannot influence ICE behavior beyond the existing
WithICETransportPolicy / WithDisableTURN options.

When a client is co-located with the SFU on a host that has many network
interfaces (docker bridges, veth, IPv6), pion gathers ICE host candidates from
all of them and can select an unreachable one, silently breaking the media
path. The fix is SettingEngine.SetInterfaceFilter / SetIPFilter, which the SDK
does not currently expose.

WithSettingEngineFunc passes the SettingEngine to a caller-supplied func after
the SDK finishes configuring it and before the API is built, for both the
publisher and subscriber PeerConnections. It is opt-in and changes nothing when
unset.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@UbiShipDev1 UbiShipDev1 requested a review from a team as a code owner June 27, 2026 04:34
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@cnderrauber cnderrauber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good!

@cnderrauber

Copy link
Copy Markdown
Contributor

@UbiShipDev1 could you please sign our Contributor License Agreement?

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.

3 participants