forked from muaz-khan/WebRTC-Experiment
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
291 lines (248 loc) · 11.3 KB
/
index.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!DOCTYPE html>
<html lang="en">
<head>
<script>
if(!location.hash.replace('#', '').length) {
location.href = location.href.split('#')[0] + '#' + (Math.random() * 100).toString().replace('.', '');
location.reload();
}
</script>
<title>WebRTC One-to-Many Audio-Broadcasting | Muaz Khan</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="author" type="text/html" href="https://plus.google.com/100325991024054712503">
<meta name="author" content="Muaz Khan">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link href="https://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet" type="text/css" />
<script>
var hash = window.location.hash.replace('#', '');
if (!hash.length) location.href = location.href + '#meeting-roomid-' + ((Math.random() * new Date().getTime()).toString(36).toLowerCase().replace(/\./g, '-'));
</script>
<style>
html { background: #eee; }
body {
font-family: "Inconsolata", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;
font-size: 1.2em;
line-height: 1.2em;
margin: 0;
}
body {
background: #fff;
border: 1px solid;
border-color: #ddd #aaa #aaa #ddd;
border-radius: 5px;
margin: .5em auto 0 auto;
padding: .8em;
padding-top: 0;
}
h1, h2 {
border-bottom: 1px solid black;
display: inline;
font-weight: normal;
line-height: 36px;
padding: 0 0 3px 0;
}
h1 {
background: rgb(238, 238, 238);
border-bottom-width: 2px;
display: block;
margin-top: 0;
padding: .3em;
text-align: center;
}
:-moz-any-link:focus {
border: 0;
color: #000;
}
::selection { background: #ccc; }
::-moz-selection { background: #ccc; }
button {
-moz-border-radius: 3px;
-moz-transition: none;
-webkit-transition: none;
background: #0370ea;
background: -moz-linear-gradient(top, #008dfd 0, #0370ea 100%);
background: -webkit-linear-gradient(top, #008dfd 0, #0370ea 100%);
border: 1px solid #076bd2;
border-radius: 3px;
color: #fff;
display: inline-block;
font-family: inherit;
font-size: .8em;
line-height: 1.3;
padding: 5px 12px;
text-align: center;
text-shadow: 1px 1px 1px #076bd2;
}
button:hover { background: rgb(9, 147, 240); }
button:active { background: rgb(10, 118, 190); }
button[disabled] {
background: none;
border: 1px solid rgb(187, 181, 181);
color: gray;
text-shadow: none;
}
#remote-media-streams video { width: 10em; }
#local-media-stream video { width: 34em; }
footer { text-align: center; }
code {
color: rgb(204, 14, 14);
font-family: inherit;
}
audio, video { vertical-align: bottom; }
pre {
border-left: 2px solid red;
margin-left: 2em;
padding-left: 1em;
}
</style>
<script src="https://www.webrtc-experiment.com/socket.io.js"></script>
<script src="https://www.webrtc-experiment.com/one-to-many-audio-broadcasting/meeting.js"> </script>
</head>
<body>
<h1>
WebRTC One-to-Many Audio-Broadcasting / <a href="https://github.com/muaz-khan/WebRTC-Experiment/tree/master/audio-broadcast" target="_blank">Source Code</a>
</h1>
<p>
<a href="https://www.webrtc-experiment.com/">HOME</a>
<span> © </span>
<a href="http://www.MuazKhan.com/" target="_blank">Muaz Khan</a>
.
<a href="http://twitter.com/WebRTCWeb" target="_blank" title="Twitter profile for WebRTC Experiments">@WebRTCWeb</a>
.
<a href="https://github.com/muaz-khan?tab=repositories" target="_blank" title="Github Profile">Github</a>
.
<a href="https://github.com/muaz-khan/WebRTC-Experiment/issues?state=open" target="_blank">Latest issues</a>
.
<a href="https://github.com/muaz-khan/WebRTC-Experiment/commits/master" target="_blank">What's New?</a>
</p>
<section class="plusone-gplus">
<div class="g-plusone" data-href="https://www.webrtc-experiment.com/"></div>
</section>
<section>
<h2>Setup a new meeting:</h2>
<button id="setup-new-meeting">Setup New Meeting</button>
</section>
<table style="border-left: 1px solid black; width: 100%;">
<tr>
<td>
<h2 style="display: block; text-align: center;">
Local Media Stream</h2>
<section id="local-media-stream"></section>
</td>
</tr>
<tr>
<td>
<h2 style="display: block; text-align: center;">
Remote Media Streams</h2>
<section id="remote-media-streams"></section>
</td>
</tr>
</table>
<script>
var hash = window.location.hash.replace('#', '');
var meeting = new Meeting(hash);
var remoteMediaStreams = document.getElementById('remote-media-streams');
var localMediaStream = document.getElementById('local-media-stream');
var channel = location.href.replace(/\/|:|#|%|\.|\[|\]/g, '');
var sender = Math.round(Math.random() * 999999999) + 999999999;
var SIGNALING_SERVER = 'https://socketio-over-nodejs2.herokuapp.com:443/';
io.connect(SIGNALING_SERVER).emit('new-channel', {
channel: channel,
sender: sender
});
var socket = io.connect(SIGNALING_SERVER + channel);
socket.on('connect', function () {
// setup peer connection & pass socket object over the constructor!
});
socket.send = function (message) {
socket.emit('message', {
sender: sender,
data: message
});
};
meeting.openSignalingChannel = function(callback) {
return socket.on('message', callback);
};
// on getting media stream
meeting.onaddstream = function(e) {
if (e.type == 'local') localMediaStream.appendChild(e.audio);
if (e.type == 'remote') remoteMediaStreams.insertBefore(e.audio, remoteMediaStreams.firstChild);
};
// using firebase for signaling
meeting.firebase = 'rtcweb';
// if someone leaves; just remove his audio
meeting.onuserleft = function(userid) {
var audio = document.getElementById(userid);
if (audio) audio.parentNode.removeChild(audio);
};
// check pre-created meeting rooms
meeting.check();
document.getElementById('setup-new-meeting').onclick = function() {
// setup new meeting room
meeting.setup('meeting room name');
this.disabled = true;
this.parentNode.innerHTML = '<h2><a href="' + location.href + '" target="_blank">Share this link</a></h2>';
};
</script>
<br />
<br />
<p>If 10 users join your broadcasted room, <strong>20 RTP ports</strong> will be opened on your browser:<p>
<ol>
<li>10 RTP ports for <strong>outgoing</strong> audio streams</li>
<li>10 RTP ports for <strong>incoming</strong> audio streams</li>
</ol>
<h2>Difference between one-way broadcasting and one-to-many broadcasting</h2>
<p>For 10 users session, maximum 10 RTP ports for outgoing audio stream will be opened.<p>
<p>On each participant's side; only one <strong>incoming</strong> RTP port will be opened.<p>
<p>Unlike one-way broadcasting; one-to-many broadcasting experiment opens both outgoing as well as incoming RTP ports for each participant.<p>
<br />
<br />
<pre>
<script src="https://www.webrtc-experiment.com/one-to-many-audio-broadcasting/meeting.js"></script>
</pre>
<pre>
var meeting = new Meeting('meeting-unique-id');
// on getting local or remote streams
meeting.onaddstream = function(e) {
// e.type == 'local' ---- it is local media stream
// e.type == 'remote' --- it is remote media stream
document.body.appendChild(e.audio);
};
// custom signaling channel
// you can use each and every signaling channel
// any websocket, socket.io, or XHR implementation
// any SIP server
// anything! etc.
meeting.openSignalingChannel = function(callback) {
return io.connect().on('message', callback);
};
// check pre-created meeting rooms
// it is useful to auto-join
// or search pre-created sessions
meeting.check();
document.getElementById('setup-new-meeting').onclick = function() {
meeting.setup('meeting room name');
};
// if someone leaves; just remove his audio
meeting.onuserleft = function(userid) {
var audio = document.getElementById(userid);
if(audio) audio.parentNode.removeChild(audio);
};
</pre>
<br />
<br />
<section style="border: 1px solid rgb(189, 189, 189); border-radius: .2em; margin: 1em 3em;">
<h2 id="feedback" style="border-bottom: 1px solid rgb(189, 189, 189); padding: .2em .4em;">Feedback</h2>
<div>
<textarea id="message" style="border: 1px solid rgb(189, 189, 189); height: 8em; margin: .2em; outline: none; resize: vertical; width: 98%;" placeholder="Have any message? Suggestions or something went wrong?"></textarea>
</div>
<button id="send-message" style="font-size: 1em;">Send Message</button>
</section>
<footer>
<p> <a href="https://www.webrtc-experiment.com/" target="_blank">WebRTC Experiments!</a> © <a href="https://plus.google.com/100325991024054712503" rel="author" target="_blank">Muaz Khan</a>, <span>2013 </span> » <a href="mailto:[email protected]" target="_blank">Email</a> » <a href="http://twitter.com/muazkh" target="_blank">@muazkh</a> » <a href="https://github.com/muaz-khan" target="_blank">Github</a></p>
</footer>
<script src="https://www.webrtc-experiment.com/common.js"> </script>
</body>
</html>