forked from fippo/simulcast-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstraint.html
134 lines (129 loc) · 4.79 KB
/
constraint.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<html>
<head>
<meta charset="utf-8">
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script src="https://rawgit.com/otalk/sdp/master/sdp.js"></script>
<script src="https://webrtc.github.io/samples/src/js/third_party/graph.js"></script>
<script src="test-assert.js"></script>
<script src="draw-graphs.js"></script>
<style>
video {
width: 320px;
}
</style>
</head>
<body>
<div id="local">
<h2>Local Video</h2>
</div>
<div id="remotes">
<h2>Remote Videos</h2>
</div>
<script>
const pc1 = new RTCPeerConnection({sdpSemantics: 'plan-b'});
const pc2 = new RTCPeerConnection({sdpSemantics: 'unified-plan'});
pc1.onicecandidate = (e) => pc2.addIceCandidate(e.candidate);
pc2.onicecandidate = (e) => pc1.addIceCandidate(e.candidate);
pc2.ontrack = (e) => show(e.streams[0], true);
navigator.mediaDevices.getUserMedia({video: {width: 1280, height: 720}})
.then((stream) => {
pc1.addTrack(stream.getVideoTracks()[0], stream);
show(stream, false);
return pc1.createOffer({numberOfSimulcastLayers: 3});
})
.then((offer) => {
const sections = SDPUtils.splitSections(offer.sdp);
const dtls = SDPUtils.getDtlsParameters(sections[1], sections[0]);
const ice = SDPUtils.getIceParameters(sections[1], sections[0]);
const rtpParameters = SDPUtils.parseRtpParameters(sections[1]);
const rtcpParameters = SDPUtils.parseRtcpParameters(sections[1]);
// unified plan things.
rtpParameters.headerExtensions = rtpParameters.headerExtensions.filter(ext => {
return ext.uri !== 'urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id' &&
ext.uri !== 'urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id' &&
ext.uri !== 'urn:ietf:params:rtp-hdrext:sdes:mid';
});
let sdp = SDPUtils.writeSessionBoilerplate() +
SDPUtils.writeDtlsParameters(dtls, 'actpass') +
SDPUtils.writeIceParameters(ice) +
'a=group:BUNDLE video 1 2\r\n' +
'a=msid-semantic:WMS *\r\n';
const codecs = SDPUtils.writeRtpDescription('video', rtpParameters) +
SDPUtils.writeRtcpParameters({
mux:rtcpParameters.mux,
reducedSize: rtcpParameters.reducedSize,
});
const fidGroups = SDPUtils.matchPrefix(sections[1], 'a=ssrc-group:FID ');
if (fidGroups.length > 0) {
const [videoSSRC1, rtxSSRC1] = fidGroups[0].substr(17).split(' ').map(ssrc => parseInt(ssrc, 10));
sdp += codecs +
'a=setup:actpass\r\n' +
'a=mid:video\r\n' +
'a=msid:low low\r\n' +
'a=ssrc:' + videoSSRC1 + ' cname:something\r\n';
'a=ssrc:' + rtxSSRC1 + ' cname:something\r\n' +
'a=ssrc-group:FID ' + videoSSRC1 + ' ' + rtxSSRC1 + '\r\n';
}
if (fidGroups.length > 1) {
const [videoSSRC2, rtxSSRC2] = fidGroups[1].substr(17).split(' ').map(ssrc => parseInt(ssrc, 10));
sdp += codecs +
'a=setup:actpass\r\n' +
'a=mid:1\r\n' +
'a=msid:mid mid\r\n' +
'a=ssrc:' + videoSSRC2 + ' cname:something\r\n' +
'a=ssrc:' + rtxSSRC2 + ' cname:something\r\n' +
'a=ssrc-group:FID ' + videoSSRC2 + ' ' + rtxSSRC2 + '\r\n';
}
if (fidGroups.length > 2) {
const [videoSSRC3, rtxSSRC3] = fidGroups[2].substr(17).split(' ').map(ssrc => parseInt(ssrc, 10));
sdp += codecs +
'a=setup:actpass\r\n' +
'a=mid:2\r\n' +
'a=msid:hi hi\r\n' +
'a=ssrc:' + videoSSRC3 + ' cname:something\r\n' +
'a=ssrc:' + rtxSSRC3 + ' cname:something\r\n' +
'a=ssrc-group:FID ' + videoSSRC3 + ' ' + rtxSSRC3 + '\r\n';
}
return Promise.all([
pc1.setLocalDescription(offer),
pc2.setRemoteDescription({
type: 'offer',
sdp,
}),
]);
})
.then(() => pc2.createAnswer())
.then(answer => {
const sections = SDPUtils.splitSections(answer.sdp);
const dtls = SDPUtils.getDtlsParameters(sections[1], sections[0]);
const ice = SDPUtils.getIceParameters(sections[1], sections[0]);
const rtpParameters = SDPUtils.parseRtpParameters(sections[1]);
const rtcpParameters = SDPUtils.parseRtcpParameters(sections[1]);
let sdp = SDPUtils.writeSessionBoilerplate() +
SDPUtils.writeDtlsParameters(dtls, 'active') +
SDPUtils.writeIceParameters(ice) +
'a=group:BUNDLE video\r\n' +
'a=msid-semantic:WMS *\r\n';
const codecs = SDPUtils.writeRtpDescription('video', rtpParameters) +
SDPUtils.writeRtcpParameters({
mux:rtcpParameters.mux,
reducedSize: rtcpParameters.reducedSize,
});
sdp += codecs;
return Promise.all([
pc2.setLocalDescription(answer),
pc1.setRemoteDescription({
type: 'answer',
sdp
}),
]);
})
.then(() => {
window.setInterval(() => {
draw(pc1, pc2);
}, 2000);
})
.catch(e => console.error(e));
</script>
</body>
</html>