Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ func (e *RTCEngine) createPublisherPCLocked(configuration webrtc.Configuration)
OnRTTUpdate: e.setRTT,
IsSender: true,
DTLSEllipticCurves: e.connParams.DTLSEllipticCurves,
SettingEngineFunc: e.connParams.SettingEngineFunc,
}); err != nil {
return err
}
Expand Down Expand Up @@ -519,6 +520,7 @@ func (e *RTCEngine) createSubscriberPCLocked(configuration webrtc.Configuration)
Interceptors: e.connParams.Interceptors,
IncludeDefaultInterceptors: e.connParams.IncludeDefaultInterceptors,
DTLSEllipticCurves: e.connParams.DTLSEllipticCurves,
SettingEngineFunc: e.connParams.SettingEngineFunc,
}); err != nil {
return err
}
Expand Down
11 changes: 11 additions & 0 deletions room.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ func WithICETransportPolicy(iceTransportPolicy webrtc.ICETransportPolicy) Connec
}
}

// WithSettingEngineFunc customizes the pion SettingEngine (ICE interface/IP
// filters, NAT1To1 mappings, timeouts) before the WebRTC API is constructed.
// fn is invoked for every PeerConnection the SDK creates (publisher and
// subscriber). Use it when the host has interfaces or IPs that must be excluded
// from ICE candidate gathering and the existing options are insufficient.
func WithSettingEngineFunc(fn func(*webrtc.SettingEngine)) ConnectOption {
return func(p *connParams) {
p.SettingEngineFunc = fn
}
}

// WithDisableTURN removes TURN/TURNS URLs from the ICE server configuration
// provided by the SFU. Use this when the client is co-located with the SFU
// and does not need relay candidates.
Expand Down
39 changes: 39 additions & 0 deletions setting_engine_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2024 LiveKit, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package lksdk

import (
"testing"

"github.com/pion/webrtc/v4"

"github.com/livekit/server-sdk-go/v2/signalling"
)

func TestWithSettingEngineFunc(t *testing.T) {
p := &connParams{ConnectParams: &signalling.ConnectParams{}}

called := false
WithSettingEngineFunc(func(se *webrtc.SettingEngine) { called = true })(p)

if p.SettingEngineFunc == nil {
t.Fatal("WithSettingEngineFunc must set ConnectParams.SettingEngineFunc")
}

p.SettingEngineFunc(&webrtc.SettingEngine{})
if !called {
t.Fatal("the stored func must be the one supplied to WithSettingEngineFunc")
}
}
7 changes: 7 additions & 0 deletions signalling/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ type ConnectParams struct {

ICETransportPolicy webrtc.ICETransportPolicy

// SettingEngineFunc, if set, is invoked with the pion SettingEngine after the
// SDK builds it (per PeerConnection) and before the WebRTC API is created. It
// lets callers customize ICE behavior the SDK does not otherwise expose — for
// example SetInterfaceFilter / SetIPFilter to exclude interfaces or IPs from
// candidate gathering. See WithSettingEngineFunc.
SettingEngineFunc func(*webrtc.SettingEngine)

// DisableTURN removes TURN/TURNS URLs from the ICE server list provided by the SFU.
// Use this when the client is co-located with the SFU and does not need relay candidates.
DisableTURN bool
Expand Down
6 changes: 6 additions & 0 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type PCTransportParams struct {
OnRTTUpdate func(rtt uint32)
IsSender bool
DTLSEllipticCurves []dtlsElliptic.Curve
SettingEngineFunc func(*webrtc.SettingEngine)
}

func (t *PCTransport) registerDefaultInterceptors(params PCTransportParams, i *interceptor.Registry) error {
Expand Down Expand Up @@ -219,6 +220,11 @@ func NewPCTransport(params PCTransportParams) (*PCTransport, error) {
if lf != nil {
se.LoggerFactory = lf
}
// Allow callers to customize the SettingEngine (ICE interface/IP filters,
// NAT1To1, etc.) before the API is built.
if params.SettingEngineFunc != nil {
params.SettingEngineFunc(&se)
}

api := webrtc.NewAPI(webrtc.WithMediaEngine(m), webrtc.WithSettingEngine(se), webrtc.WithInterceptorRegistry(i))
pc, err := api.NewPeerConnection(params.Configuration)
Expand Down
Loading