Send stun servers to clients (#69)

* Send stun servers to clients

* use TURN/UDP as STUN servers
This commit is contained in:
David Zhao
2021-07-26 15:43:26 -07:00
committed by GitHub
parent d49d541a9e
commit f8782fae3f
2 changed files with 28 additions and 11 deletions
+8 -6
View File
@@ -12,6 +12,11 @@ import (
"gopkg.in/yaml.v3"
)
var DEFAULT_STUN_SERVERS = []string{
"stun.l.google.com:19302",
"stun1.l.google.com:19302",
}
type Config struct {
Port uint32 `yaml:"port"`
PrometheusPort uint32 `yaml:"prometheus_port"`
@@ -104,12 +109,9 @@ func NewConfig(confString string, c *cli.Context) (*Config, error) {
UDPPort: 0,
ICEPortRangeStart: 0,
ICEPortRangeEnd: 0,
StunServers: []string{
"stun.l.google.com:19302",
"stun1.l.google.com:19302",
},
MaxBitrate: 3 * 1024 * 1024, // 3 mbps
PacketBufferSize: 500,
StunServers: []string{},
MaxBitrate: 3 * 1024 * 1024, // 3 mbps
PacketBufferSize: 500,
PLIThrottle: PLIThrottleConfig{
LowQuality: 500 * time.Millisecond,
MidQuality: time.Second,
+20 -5
View File
@@ -514,14 +514,12 @@ func (r *RoomManager) handleRTCMessage(roomName, identity string, msg *livekit.R
func (r *RoomManager) iceServersForRoom(ri *livekit.Room) []*livekit.ICEServer {
var iceServers []*livekit.ICEServer
if len(r.rtcConfig.Configuration.ICEServers) > 0 {
iceServers = append(iceServers, &livekit.ICEServer{
Urls: r.rtcConfig.Configuration.ICEServers[0].URLs,
})
}
hasSTUN := false
if r.config.TURN.Enabled {
var urls []string
if r.config.TURN.UDPPort > 0 {
// UDP TURN is used as STUN
hasSTUN = true
urls = append(urls, fmt.Sprintf("turn:%s:%d?transport=udp", r.config.RTC.NodeIP, r.config.TURN.UDPPort))
}
if r.config.TURN.TLSPort > 0 {
@@ -535,6 +533,15 @@ func (r *RoomManager) iceServersForRoom(ri *livekit.Room) []*livekit.ICEServer {
})
}
}
if len(r.config.RTC.StunServers) > 0 {
hasSTUN = true
iceServers = append(iceServers, iceServerForStunServers(r.config.RTC.StunServers))
}
if !hasSTUN {
iceServers = append(iceServers, iceServerForStunServers(config.DEFAULT_STUN_SERVERS))
}
return iceServers
}
@@ -548,3 +555,11 @@ func applyDefaultRoomConfig(room *livekit.Room, conf *config.RoomConfig) {
})
}
}
func iceServerForStunServers(servers []string) *livekit.ICEServer {
iceServer := &livekit.ICEServer{}
for _, stunServer := range servers {
iceServer.Urls = append(iceServer.Urls, fmt.Sprintf("stun:%s", stunServer))
}
return iceServer
}