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
+1 -10
View File
@@ -2,7 +2,6 @@ package rtc
import (
"errors"
"fmt"
"net"
"syscall"
@@ -47,15 +46,6 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
loggerFactory := logging.NewDefaultLoggerFactory()
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 != "" {
s.SetNAT1To1IPs([]string{externalIP}, webrtc.ICECandidateTypeHost)
}
@@ -74,6 +64,7 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
var udpMux *ice.UDPMuxDefault
var udpMuxConn *net.UDPConn
var err error
if rtcConf.UDPPort != 0 {
udpMuxConn, err = net.ListenUDP("udp4", &net.UDPAddr{
Port: int(rtcConf.UDPPort),
+2 -1
View File
@@ -851,7 +851,8 @@ func (p *ParticipantImpl) handlePublisherICEStateChange(state webrtc.ICEConnecti
// "participant", p.identity)
if state == webrtc.ICEConnectionStateConnected {
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() {
_ = p.Close()
}()
+1 -1
View File
@@ -54,7 +54,7 @@ func TestICEStateChange(t *testing.T) {
p.onClose = func(participant types.Participant) {
close(closeChan)
}
p.handlePublisherICEStateChange(webrtc.ICEConnectionStateDisconnected)
p.handlePublisherICEStateChange(webrtc.ICEConnectionStateFailed)
select {
case <-closeChan: