mirror of
https://github.com/livekit/livekit.git
synced 2026-04-17 10:25:40 +00:00
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package rtc
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/pion/webrtc/v3"
|
|
|
|
"github.com/livekit/livekit-server/pkg/config"
|
|
)
|
|
|
|
type WebRTCConfig struct {
|
|
Configuration webrtc.Configuration
|
|
SettingEngine webrtc.SettingEngine
|
|
Receiver ReceiverConfig
|
|
}
|
|
|
|
type ReceiverConfig struct {
|
|
maxBitrate uint64
|
|
maxBufferTime int
|
|
}
|
|
|
|
type ExternalIP string
|
|
|
|
func NewWebRTCConfig(conf *config.RTCConfig, externalIP ExternalIP) (*WebRTCConfig, error) {
|
|
c := webrtc.Configuration{
|
|
SDPSemantics: webrtc.SDPSemanticsUnifiedPlan,
|
|
}
|
|
s := webrtc.SettingEngine{}
|
|
|
|
if conf.ICEPortRangeStart != 0 && conf.ICEPortRangeEnd != 0 {
|
|
if err := s.SetEphemeralUDPPortRange(conf.ICEPortRangeStart, conf.ICEPortRangeEnd); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
iceUrls := make([]string, 0)
|
|
for _, stunServer := range conf.StunServers {
|
|
iceUrls = append(iceUrls, fmt.Sprintf("stun:%s", stunServer))
|
|
}
|
|
c.ICEServers = []webrtc.ICEServer{
|
|
{
|
|
URLs: iceUrls,
|
|
},
|
|
}
|
|
if conf.UseExternalIP {
|
|
s.SetNAT1To1IPs([]string{string(externalIP)}, webrtc.ICECandidateTypeHost)
|
|
}
|
|
|
|
return &WebRTCConfig{
|
|
Configuration: c,
|
|
SettingEngine: s,
|
|
Receiver: ReceiverConfig{
|
|
maxBitrate: conf.MaxBitrate,
|
|
maxBufferTime: conf.MaxBufferTime,
|
|
},
|
|
}, nil
|
|
}
|