-
Notifications
You must be signed in to change notification settings - Fork 54
/
candidate-exchange.https.html
97 lines (92 loc) · 3.16 KB
/
candidate-exchange.https.html
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html>
<head>
<title>Candidate exchange</title>
<meta name=timeout content=long>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../RTCPeerConnection-helper.js"></script>
</head>
<body>
<script>
function iceGatheringCompleteWaiter(pc) {
const waiter = new Promise((resolve) => {
const eventHandler = () => {
if (pc.iceGatheringState == 'complete') {
pc.removeEventListener('icegatheringstatechange', eventHandler, false);
resolve();
}
};
if (pc.iceGatheringState == 'complete') {
resolve();
} else {
pc.addEventListener('icegatheringstatechange', eventHandler, false);
}
});
return waiter;
}
promise_test(async t => {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());
pc1.createDataChannel('datachannel');
coupleIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);
await waitForIceStateChange(pc1, ['connected', 'completed']);
}, 'Two way ICE exchange works');
promise_test(async t => {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());
let candidates = [];
pc1.createDataChannel('datachannel');
pc1.onicecandidate = e => {
candidates.push(e.candidate);
}
// Candidates from PC2 are not delivered to pc1, so pc1 will use
// peer-reflexive candidates.
await doSignalingHandshake(pc1, pc2);
const waiter = iceGatheringCompleteWaiter(pc1);
await waiter;
for (const candidate of candidates) {
if (candidate) {
pc2.addIceCandidate(candidate);
}
}
await Promise.all([waitForIceStateChange(pc1, ['connected', 'completed']),
waitForIceStateChange(pc2, ['connected', 'completed'])]);
const candidate_pair = pc1.sctp.transport.iceTransport.getSelectedCandidatePair();
assert_equals(candidate_pair.local.type, 'host');
assert_equals(candidate_pair.remote.type, 'prflx');
}, 'Adding only caller -> callee candidates gives a connection');
promise_test(async t => {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());
let candidates = [];
pc1.createDataChannel('datachannel');
pc2.onicecandidate = e => {
candidates.push(e.candidate);
}
// Candidates from pc1 are not delivered to pc2. so pc2 will use
// peer-reflexive candidates.
await doSignalingHandshake(pc1, pc2);
const waiter = iceGatheringCompleteWaiter(pc2);
await waiter;
for (const candidate of candidates) {
if (candidate) {
pc1.addIceCandidate(candidate);
}
}
await Promise.all([waitForIceStateChange(pc1, ['connected', 'completed']),
waitForIceStateChange(pc2, ['connected', 'completed'])]);
const candidate_pair = pc2.sctp.transport.iceTransport.getSelectedCandidatePair();
assert_equals(candidate_pair.local.type, 'host');
assert_equals(candidate_pair.remote.type, 'prflx');
}, 'Adding only callee -> caller candidates gives a connection');
</script>
</body>
</html>