mirror of
https://github.com/pion/webrtc.git
synced 2025-10-14 11:23:43 +08:00

GenerateMulticastDNSCandidates -> SetICEMulticastDNSMode. Before a user wasn't able to disable mDNS. By changing it we can do more with this API.
100 lines
2.0 KiB
Go
100 lines
2.0 KiB
Go
// +build !js
|
|
|
|
package webrtc
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/pion/ice/v2"
|
|
"github.com/pion/transport/test"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewICEGatherer_Success(t *testing.T) {
|
|
// Limit runtime in case of deadlocks
|
|
lim := test.TimeOut(time.Second * 20)
|
|
defer lim.Stop()
|
|
|
|
report := test.CheckRoutines(t)
|
|
defer report()
|
|
|
|
opts := ICEGatherOptions{
|
|
ICEServers: []ICEServer{{URLs: []string{"stun:stun.l.google.com:19302"}}},
|
|
}
|
|
|
|
gatherer, err := NewAPI().NewICEGatherer(opts)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if gatherer.State() != ICEGathererStateNew {
|
|
t.Fatalf("Expected gathering state new")
|
|
}
|
|
|
|
gatherFinished := make(chan struct{})
|
|
gatherer.OnLocalCandidate(func(i *ICECandidate) {
|
|
if i == nil {
|
|
close(gatherFinished)
|
|
}
|
|
})
|
|
|
|
if err = gatherer.Gather(); err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
<-gatherFinished
|
|
|
|
params, err := gatherer.GetLocalParameters()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if len(params.UsernameFragment) == 0 ||
|
|
len(params.Password) == 0 {
|
|
t.Fatalf("Empty local username or password frag")
|
|
}
|
|
|
|
candidates, err := gatherer.GetLocalCandidates()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if len(candidates) == 0 {
|
|
t.Fatalf("No candidates gathered")
|
|
}
|
|
|
|
assert.NoError(t, gatherer.Close())
|
|
}
|
|
|
|
func TestICEGather_mDNSCandidateGathering(t *testing.T) {
|
|
// Limit runtime in case of deadlocks
|
|
lim := test.TimeOut(time.Second * 20)
|
|
defer lim.Stop()
|
|
|
|
report := test.CheckRoutines(t)
|
|
defer report()
|
|
|
|
s := SettingEngine{}
|
|
s.SetICEMulticastDNSMode(ice.MulticastDNSModeQueryAndGather)
|
|
|
|
gatherer, err := NewAPI(WithSettingEngine(s)).NewICEGatherer(ICEGatherOptions{})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
gotMulticastDNSCandidate, resolveFunc := context.WithCancel(context.Background())
|
|
gatherer.OnLocalCandidate(func(c *ICECandidate) {
|
|
if c != nil && strings.HasSuffix(c.Address, ".local") {
|
|
resolveFunc()
|
|
}
|
|
})
|
|
|
|
assert.NoError(t, gatherer.Gather())
|
|
|
|
<-gotMulticastDNSCandidate.Done()
|
|
assert.NoError(t, gatherer.Close())
|
|
}
|