diff --git a/pkg/rtc/transport.go b/pkg/rtc/transport.go index 4d775698c..de4f47dbf 100644 --- a/pkg/rtc/transport.go +++ b/pkg/rtc/transport.go @@ -706,19 +706,6 @@ func (t *PCTransport) SetPreferTCP(preferTCP bool) { } func (t *PCTransport) AddICECandidate(candidate webrtc.ICECandidateInit) { - if !t.params.Config.UseMDNS { - candidateValue := strings.TrimPrefix(candidate.Candidate, "candidate:") - if candidateValue != "" { - candidate, err := ice.UnmarshalCandidate(candidateValue) - if err != nil { - t.params.Logger.Errorw("failed to parse ice candidate", err) - } else if strings.HasSuffix(candidate.Address(), ".local") { - t.params.Logger.Debugw("ignoring mDNS candidate", "candidate", candidateValue) - return - } - } - } - t.postEvent(event{ signal: signalRemoteICECandidate, data: &candidate, @@ -1395,6 +1382,11 @@ func (t *PCTransport) handleRemoteICECandidate(e event) error { filtered = true } + if !t.params.Config.UseMDNS && types.IsCandidateMDNS(*c) { + t.params.Logger.Debugw("ignoring mDNS candidate", "candidate", c.Candidate) + filtered = true + } + t.connectionDetails.AddRemoteCandidate(*c, filtered, true) if filtered { return nil @@ -1440,6 +1432,11 @@ func (t *PCTransport) filterCandidates(sd webrtc.SessionDescription, preferTCP, continue } excluded := preferTCP && !c.NetworkType().IsTCP() + if !excluded { + if !t.params.Config.UseMDNS && types.IsICECandidateMDNS(c) { + excluded = true + } + } if !excluded { filteredAttrs = append(filteredAttrs, a) } diff --git a/pkg/rtc/types/ice.go b/pkg/rtc/types/ice.go index a659e6d03..059ded5de 100644 --- a/pkg/rtc/types/ice.go +++ b/pkg/rtc/types/ice.go @@ -224,6 +224,8 @@ func (d *ICEConnectionDetails) SetSelectedPair(pair *webrtc.ICECandidatePair) { } } +// ------------------------------------------------------------- + func isCandidateEqualTo(c1, c2 *webrtc.ICECandidate) bool { if c1 == nil && c2 == nil { return true @@ -332,3 +334,16 @@ func unmarshalCandidate(i ice.Candidate) (*webrtc.ICECandidate, error) { return &c, nil } + +func IsCandidateMDNS(candidate webrtc.ICECandidateInit) bool { + c, err := unmarshalICECandidate(candidate) + if err != nil { + return false + } + + return IsICECandidateMDNS(c) +} + +func IsICECandidateMDNS(candidate ice.Candidate) bool { + return strings.HasSuffix(candidate.Address(), ".local") +}