Send stun servers to clients (#69)
* Send stun servers to clients * use TURN/UDP as STUN servers
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user