forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icetransport_test.go
74 lines (61 loc) · 1.57 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
68
69
70
71
72
73
74
// +build !js
package webrtc
import (
"math/rand"
"sync/atomic"
"testing"
"time"
"github.com/pion/transport/test"
)
func TestICETransport_OnSelectedCandidatePairChange(t *testing.T) {
iceComplete := make(chan bool)
api := NewAPI()
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()
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)
}
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)
})
}
}
err = signalPair(pcOffer, pcAnswer)
if err != nil {
t.Fatal(err)
}
<-iceComplete
if atomic.LoadInt32(&senderCalledCandidateChange) == 0 {
t.Fatalf("Sender ICETransport OnSelectedCandidateChange was never called")
}
err = pcOffer.Close()
if err != nil {
t.Fatal(err)
}
err = pcAnswer.Close()
if err != nil {
t.Fatal(err)
}
}