Send stun servers to clients (#69)
* Send stun servers to clients * use TURN/UDP as STUN servers
This commit is contained in:
@@ -12,6 +12,11 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var DEFAULT_STUN_SERVERS = []string{
|
||||||
|
"stun.l.google.com:19302",
|
||||||
|
"stun1.l.google.com:19302",
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Port uint32 `yaml:"port"`
|
Port uint32 `yaml:"port"`
|
||||||
PrometheusPort uint32 `yaml:"prometheus_port"`
|
PrometheusPort uint32 `yaml:"prometheus_port"`
|
||||||
@@ -104,12 +109,9 @@ func NewConfig(confString string, c *cli.Context) (*Config, error) {
|
|||||||
UDPPort: 0,
|
UDPPort: 0,
|
||||||
ICEPortRangeStart: 0,
|
ICEPortRangeStart: 0,
|
||||||
ICEPortRangeEnd: 0,
|
ICEPortRangeEnd: 0,
|
||||||
StunServers: []string{
|
StunServers: []string{},
|
||||||
"stun.l.google.com:19302",
|
MaxBitrate: 3 * 1024 * 1024, // 3 mbps
|
||||||
"stun1.l.google.com:19302",
|
PacketBufferSize: 500,
|
||||||
},
|
|
||||||
MaxBitrate: 3 * 1024 * 1024, // 3 mbps
|
|
||||||
PacketBufferSize: 500,
|
|
||||||
PLIThrottle: PLIThrottleConfig{
|
PLIThrottle: PLIThrottleConfig{
|
||||||
LowQuality: 500 * time.Millisecond,
|
LowQuality: 500 * time.Millisecond,
|
||||||
MidQuality: time.Second,
|
MidQuality: time.Second,
|
||||||
|
|||||||
@@ -514,14 +514,12 @@ func (r *RoomManager) handleRTCMessage(roomName, identity string, msg *livekit.R
|
|||||||
func (r *RoomManager) iceServersForRoom(ri *livekit.Room) []*livekit.ICEServer {
|
func (r *RoomManager) iceServersForRoom(ri *livekit.Room) []*livekit.ICEServer {
|
||||||
var iceServers []*livekit.ICEServer
|
var iceServers []*livekit.ICEServer
|
||||||
|
|
||||||
if len(r.rtcConfig.Configuration.ICEServers) > 0 {
|
hasSTUN := false
|
||||||
iceServers = append(iceServers, &livekit.ICEServer{
|
|
||||||
Urls: r.rtcConfig.Configuration.ICEServers[0].URLs,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if r.config.TURN.Enabled {
|
if r.config.TURN.Enabled {
|
||||||
var urls []string
|
var urls []string
|
||||||
if r.config.TURN.UDPPort > 0 {
|
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))
|
urls = append(urls, fmt.Sprintf("turn:%s:%d?transport=udp", r.config.RTC.NodeIP, r.config.TURN.UDPPort))
|
||||||
}
|
}
|
||||||
if r.config.TURN.TLSPort > 0 {
|
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
|
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