Support for custom TURN servers (#409)

Closes #271
This commit is contained in:
David Zhao
2022-02-05 23:15:58 -08:00
committed by GitHub
parent e6c236357a
commit 81521f80db
3 changed files with 49 additions and 9 deletions
+23 -1
View File
@@ -494,6 +494,7 @@ func (r *RoomManager) handleRTCMessage(_ context.Context, roomName livekit.RoomN
func (r *RoomManager) iceServersForRoom(ri *livekit.Room) []*livekit.ICEServer {
var iceServers []*livekit.ICEServer
rtcConf := r.config.RTC
hasSTUN := false
if r.config.TURN.Enabled {
@@ -515,7 +516,28 @@ func (r *RoomManager) iceServersForRoom(ri *livekit.Room) []*livekit.ICEServer {
}
}
if len(r.config.RTC.STUNServers) > 0 {
if len(rtcConf.TURNServers) > 0 {
hasSTUN = true
for _, s := range r.config.RTC.TURNServers {
scheme := "turn"
transport := "tcp"
if s.Protocol == "tls" {
scheme = "turns"
} else if s.Protocol == "udp" {
transport = "udp"
}
is := &livekit.ICEServer{
Urls: []string{
fmt.Sprintf("%s:%s:%d?transport=%s", scheme, s.Host, s.Port, transport),
},
Username: s.Username,
Credential: s.Credential,
}
iceServers = append(iceServers, is)
}
}
if len(rtcConf.STUNServers) > 0 {
hasSTUN = true
iceServers = append(iceServers, iceServerForStunServers(r.config.RTC.STUNServers))
}