forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icetransport_test.go
67 lines (55 loc) · 1.58 KB
/
icetransport_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// +build !js
package webrtc
import (
"math/rand"
"sync/atomic"
"testing"
"time"
"github.com/pion/transport/test"
"github.com/stretchr/testify/assert"
)
func TestICETransport_OnSelectedCandidatePairChange(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()
api := NewAPI()
api.mediaEngine.RegisterDefaultCodecs()
pcOffer, pcAnswer, err := api.newPair()
if err != nil {
t.Fatal(err)
}
opusTrack, err := pcOffer.NewTrack(DefaultPayloadTypeOpus, rand.Uint32(), "audio", "pion1")
if err != nil {
t.Fatal(err)
}
if _, err = pcOffer.AddTrack(opusTrack); err != nil {
t.Fatal(err)
}
iceComplete := make(chan bool)
pcAnswer.OnICEConnectionStateChange(func(iceState ICEConnectionState) {
if iceState == ICEConnectionStateConnected {
time.Sleep(3 * time.Second) // TODO PeerConnection.Close() doesn't block for all subsystems
close(iceComplete)
}
})
senderCalledCandidateChange := int32(0)
for _, sender := range pcOffer.GetSenders() {
dtlsTransport := sender.Transport()
if dtlsTransport == nil {
continue
}
if iceTransport := dtlsTransport.ICETransport(); iceTransport != nil {
iceTransport.OnSelectedCandidatePairChange(func(pair *ICECandidatePair) {
atomic.StoreInt32(&senderCalledCandidateChange, 1)
})
}
}
assert.NoError(t, signalPair(pcOffer, pcAnswer))
<-iceComplete
if atomic.LoadInt32(&senderCalledCandidateChange) == 0 {
t.Fatalf("Sender ICETransport OnSelectedCandidateChange was never called")
}
assert.NoError(t, pcOffer.Close())
assert.NoError(t, pcAnswer.Close())
}