This repository has been archived by the owner on Apr 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
doublecandidate.html
79 lines (71 loc) · 2.19 KB
/
doublecandidate.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
<html>
<head>
<meta charset="utf-8">
<title>How to send a MediaStreamTrack with ORTC</title>
<style>
#container {
margin: 0 auto 0 auto;
max-width: 40em;
}
video {
height: 225px;
width: calc(50% - 12px)
}
</style>
</head>
<body>
<div id="container">
<video id="localVideo" autoplay muted></video>
<video id="remoteVideo" autoplay></video>
<p>
This shows how to send a MediaStreamTrack with ORTC. Note that ORTC is only supported in Microsoft Edge right now and (at the time of this writing) is considered experimental.
</p>
</div>
<script>
var iceOptions = { "gatherPolicy": "all", "iceServers": [] };
// At the Sender side, create an ICE gatherer, an ICE transport
// and a DTLS transport.
var gatherer1 = new RTCIceGatherer(iceOptions);
var transport1 = new RTCIceTransport(gatherer1);
var dtls1 = new RTCDtlsTransport(transport1);
var gatherer2 = new RTCIceGatherer(iceOptions);
// Exchange ICE candidates.
gatherer1.onlocalcandidate = function (evt) {
console.log('1 -> 2', evt.candidate);
//transport2.addRemoteCandidate(evt.candidate);
};
function parseCandidate(line) {
var parts;
// Parse both variants.
if (line.indexOf('a=candidate:') === 0) {
parts = line.substring(12).split(' ');
} else {
parts = line.substring(10).split(' ');
}
var candidate = {
foundation: parts[0],
component: parts[1],
protocol: parts[2].toLowerCase(),
priority: parseInt(parts[3], 10),
ip: parts[4],
port: parseInt(parts[5], 10),
// skip parts[6] == 'typ'
type: parts[7]
};
return candidate;
};
// why do these have different priorities? from mantis
var first = parseCandidate('a=candidate:1796272311 1 UDP 2130706431 52.89.123.61 20425 typ host generation 0');
var second = parseCandidate('candidate:1796272311 2 UDP 2130706430 52.89.123.61 20425 typ host generation 0');
transport1.setRemoteCandidates([
first, second
]);
// Next, start the ICE transports with the parameters from the remote side
// and the gatherer.
transport1.start(gatherer1, gatherer2.getLocalParameters(), 'controlling');
transport1.onicestatechange = function() {
console.log('ICE transport 1 state change', transport1.state);
};
</script>
</body>
</html>