forked from fippo/simulcast-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremb.html
101 lines (93 loc) · 3.79 KB
/
remb.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
<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: 'unified-plan'});
const pc2 = new RTCPeerConnection({sdpSemantics: 'plan-b'});
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();
})
.then((offer) => {
var videoPart = SDPUtils.getMediaSections(offer.sdp)[0];
var match = videoPart.match(/a=ssrc:(\d+) cname:(.*)\r\n/);
var msid = videoPart.match(/a=ssrc:(\d+) msid:(.*)\r\n/);
var lines = offer.sdp.trim().split('\r\n');
var removed = lines.splice(lines.length - 4, 4);
var videoSSRC1 = parseInt(match[1]);
var rtxSSRC1 = SDPUtils.matchPrefix(videoPart, 'a=ssrc-group:FID ')[0].split(' ')[2];
var videoSSRC2 = videoSSRC1 + 1;
var rtxSSRC2 = videoSSRC1 + 2;
var videoSSRC3 = videoSSRC1 + 3;
var rtxSSRC3 = videoSSRC1 + 4;
lines.push(removed[0]);
lines.push(removed[1]);
lines.push('a=ssrc:' + videoSSRC2 + ' cname:' + match[2]);
lines.push('a=ssrc:' + videoSSRC2 + ' msid:' + msid[2]);
lines.push('a=ssrc:' + rtxSSRC2 + ' cname:' + match[2]);
lines.push('a=ssrc:' + rtxSSRC2 + ' msid:' + msid[2]);
lines.push('a=ssrc:' + videoSSRC3 + ' cname:' + match[2]);
lines.push('a=ssrc:' + videoSSRC3 + ' msid:' + msid[2]);
lines.push('a=ssrc:' + rtxSSRC3 + ' cname:' + match[2]);
lines.push('a=ssrc:' + rtxSSRC3 + ' msid:' + msid[2]);
lines.push('a=ssrc-group:FID ' + videoSSRC2 + ' ' + rtxSSRC2);
lines.push('a=ssrc-group:FID ' + videoSSRC3 + ' ' + rtxSSRC3);
lines.push('a=ssrc-group:SIM ' + videoSSRC1 + ' ' + videoSSRC2 + ' ' + videoSSRC3);
offer.sdp = lines.join('\r\n') + '\r\n';
var offer2 = {
type: 'offer',
sdp: offer.sdp,
};
offer2.sdp = offer2.sdp.replace('a=ssrc-group:SIM ' + videoSSRC1 + ' ' + videoSSRC2 + ' ' + videoSSRC3 + '\r\n', '');
offer2.sdp = offer2.sdp.replace('a=ssrc:' + videoSSRC1 + ' msid:' + msid[2], 'a=ssrc:' + videoSSRC1 + ' msid:low low');
offer2.sdp = offer2.sdp.replace('a=ssrc:' + rtxSSRC1 + ' msid:' + msid[2], 'a=ssrc:' + rtxSSRC1 + ' msid:low low');
offer2.sdp = offer2.sdp.replace('a=ssrc:' + videoSSRC2 + ' msid:' + msid[2], 'a=ssrc:' + videoSSRC2 + ' msid:mid mid');
offer2.sdp = offer2.sdp.replace('a=ssrc:' + rtxSSRC2 + ' msid:' + msid[2], 'a=ssrc:' + rtxSSRC2 + ' msid:mid mid');
offer2.sdp = offer2.sdp.replace('a=ssrc:' + videoSSRC3 + ' msid:' + msid[2], 'a=ssrc:' + videoSSRC3 + ' msid:hi hi');
offer2.sdp = offer2.sdp.replace('a=ssrc:' + rtxSSRC3 + ' msid:' + msid[2], 'a=ssrc:' + rtxSSRC3 + ' msid:hi hi');
offer2.sdp = offer2.sdp.replace(/a=msid:(.*)\r\n/, '');
offer2.sdp = offer2.sdp.replace(/holmer/, 'that-guy');
return Promise.all([
pc1.setLocalDescription(offer),
pc2.setRemoteDescription(offer2),
]);
})
.then(() => pc2.createAnswer())
.then(answer => {
return Promise.all([
pc2.setLocalDescription(answer),
pc1.setRemoteDescription(answer),
]);
})
.then(() => {
window.setInterval(() => {
draw(pc1, pc2);
}, 2000);
})
.catch(e => console.error(e));
</script>
</body>
</html>