Remove STUN candidates, disconnect clients on ICE failed

This commit is contained in:
David Zhao
2021-06-28 12:47:16 -07:00
parent 815fd5066d
commit 343aec98a0
4 changed files with 6 additions and 14 deletions
+2 -2
View File
@@ -32,8 +32,8 @@ rtc:
# max_bitrate: 3145728 # max_bitrate: 3145728
# # number of packets to buffer in the SFU, defaults to 500 # # number of packets to buffer in the SFU, defaults to 500
# packet_buffer_size: 500 # packet_buffer_size: 500
# # optional stun servers to use. by default LiveKit uses Google's public STUN servers # # optional STUN servers for LiveKit clients to use. Clients will be configured to use these STUN servers automatically.
# # LiveKit will automatically configure connected clients to use the same STUN servers # # by default LiveKit clients use Google's public STUN servers
# stun_servers: # stun_servers:
# - server1 # - server1
# # minimum amount of time between pli/fir rtcp packets being sent to an individual # # minimum amount of time between pli/fir rtcp packets being sent to an individual
+1 -10
View File
@@ -2,7 +2,6 @@ package rtc
import ( import (
"errors" "errors"
"fmt"
"net" "net"
"syscall" "syscall"
@@ -47,15 +46,6 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
loggerFactory := logging.NewDefaultLoggerFactory() loggerFactory := logging.NewDefaultLoggerFactory()
lkLogger := loggerFactory.NewLogger("livekit-mux") lkLogger := loggerFactory.NewLogger("livekit-mux")
iceUrls := make([]string, 0)
for _, stunServer := range rtcConf.StunServers {
iceUrls = append(iceUrls, fmt.Sprintf("stun:%s", stunServer))
}
c.ICEServers = []webrtc.ICEServer{
{
URLs: iceUrls,
},
}
if rtcConf.UseExternalIP && externalIP != "" { if rtcConf.UseExternalIP && externalIP != "" {
s.SetNAT1To1IPs([]string{externalIP}, webrtc.ICECandidateTypeHost) s.SetNAT1To1IPs([]string{externalIP}, webrtc.ICECandidateTypeHost)
} }
@@ -74,6 +64,7 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
var udpMux *ice.UDPMuxDefault var udpMux *ice.UDPMuxDefault
var udpMuxConn *net.UDPConn var udpMuxConn *net.UDPConn
var err error var err error
if rtcConf.UDPPort != 0 { if rtcConf.UDPPort != 0 {
udpMuxConn, err = net.ListenUDP("udp4", &net.UDPAddr{ udpMuxConn, err = net.ListenUDP("udp4", &net.UDPAddr{
Port: int(rtcConf.UDPPort), Port: int(rtcConf.UDPPort),
+2 -1
View File
@@ -851,7 +851,8 @@ func (p *ParticipantImpl) handlePublisherICEStateChange(state webrtc.ICEConnecti
// "participant", p.identity) // "participant", p.identity)
if state == webrtc.ICEConnectionStateConnected { if state == webrtc.ICEConnectionStateConnected {
p.updateState(livekit.ParticipantInfo_ACTIVE) p.updateState(livekit.ParticipantInfo_ACTIVE)
} else if state == webrtc.ICEConnectionStateDisconnected || state == webrtc.ICEConnectionStateFailed { } else if state == webrtc.ICEConnectionStateFailed {
// only close when failed, to allow clients opportunity to reconnect
go func() { go func() {
_ = p.Close() _ = p.Close()
}() }()
+1 -1
View File
@@ -54,7 +54,7 @@ func TestICEStateChange(t *testing.T) {
p.onClose = func(participant types.Participant) { p.onClose = func(participant types.Participant) {
close(closeChan) close(closeChan)
} }
p.handlePublisherICEStateChange(webrtc.ICEConnectionStateDisconnected) p.handlePublisherICEStateChange(webrtc.ICEConnectionStateFailed)
select { select {
case <-closeChan: case <-closeChan: