-
Notifications
You must be signed in to change notification settings - Fork 4k
/
index.html
400 lines (320 loc) · 15 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<!--
> Muaz Khan - https://github.com/muaz-khan
> MIT License - https://www.webrtc-experiment.com/licence/
> Documentation - https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RTCall
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title>RTCall.js — A library for Browser-to-Browser audio-only calling | 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/ MuazKhan">
<meta name="author" content="Muaz Khan">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="https://www.webrtc-experiment.com/style.css">
<style>
audio {
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
-o-transition: all 1s ease;
-webkit-transition: all 1s ease;
transition: all 1s ease;
vertical-align: top;
}
input {
border: 1px solid #d9d9d9;
border-radius: 1px;
font-size: 2em;
margin: .2em;
width: 30%;
}
.setup {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
font-size: 102%;
height: 47px;
margin-left: -9px;
margin-top: 8px;
position: absolute;
}
p { padding: 1em; }
li {
border-bottom: 1px solid rgb(189, 189, 189);
border-left: 1px solid rgb(189, 189, 189);
padding: .5em;
}
</style>
<script>
document.createElement('article');
document.createElement('footer');
</script>
<!-- scripts used for broadcasting -->
<script src="https://www.webrtc-experiment.com/RTCall.js"> </script>
<script src="https://www.webrtc-experiment.com/socket.io.js"> </script>
</head>
<body>
<article>
<header style="text-align: center;">
<h1>
<a href="https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RTCall" target="_blank">RTCall.js</a>
— A library for Browser-to-Browser audio-only calling
</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>
</header>
<div class="github-stargazers"></div>
<!-- just copy this <section> and next script -->
<section class="experiment" style="padding: 3em 0;">
<div id="customers-list"></div>
<div id="audios-container"></div>
<div id="call-admin-box" style="display: none;">
<h2>Want to call admin?</h2>
<button id="call-admin">Call Admin</button>
</div>
</section>
<script>
// Muaz Khan - https://github.com/muaz-khan
// MIT License - https://www.webrtc-experiment.com/licence/
// Documentation - https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RTCall
function $(selector) {
return document.querySelector(selector);
}
HTMLElement.prototype.hide = function() {
this.style.display = 'none';
};
HTMLElement.prototype.show = function(block) {
this.style.display = block || 'inline-block';
};
function getRandomNumber() {
return Math.round(Math.random() * 60535) 5000;
}
</script>
<!-- if no admin; first person is considered "admin"! -->
<script>
function initAdmin() {
var parentNode = document.querySelector('.experiment');
var h2 = document.createElement('h2');
h2.innerHTML = 'You\'re an admin! <a href="' location.href.replace('?admin=true', '') '" target="_blank">Want to be a customer?</a><br /><br />';
parentNode.insertBefore(h2, parentNode.firstChild);
var rtcall = new RTCall();
rtcall.callerid = 'admin';
rtcall.admin = true;
rtcall.oncustomer = function(customer) {
customersList = $('#customers-list');
div = document.createElement('div');
div.className = 'customer-div';
callButton = document.createElement('button');
infoArea = document.createElement('span');
callButton.innerHTML = 'Call';
callButton.onclick = function() {
rtcall.call(customer.callerid);
customersList.hide();
$('#call-admin-box').hide();
};
infoArea.innerHTML = customer.callerid ' is online.';
div.appendChild(callButton);
div.appendChild(infoArea);
customersList.appendChild(div, customersList.firstChild);
};
rtcall.onincomingcall = function(caller) {
onincomingcall(caller, rtcall);
};
rtcall.onstream = onstream;
rtcall.init();
}
</script>
<!-- all other persons are "visitors" or "customers"! -->
<script>
function initCustomer() {
var parentNode = document.querySelector('.experiment');
var h2 = document.createElement('h2');
h2.innerHTML = 'You\'re a customer! <a href="?admin=true" target="_blank">Want to be an admin?</a><br /><br />';
parentNode.insertBefore(h2, parentNode.firstChild);
var rtcall = new RTCall();
rtcall.callerid = 'customer:' getRandomNumber();
rtcall.admin = false; // because he is a customer
rtcall.onincomingcall = function(caller) {
onincomingcall(caller, rtcall);
};
rtcall.onstream = onstream;
rtcall.init();
// customer can call admin too
$('#call-admin-box').show();
$('#call-admin').onclick = function() {
rtcall.call('admin');
$('#call-admin-box').hide();
};
}
</script>
<script>
// this function is fired twice
// once for admin
// once for customer
// that's why separated here
function onstream(e) {
div = document.createElement('div');
div.innerHTML = '<h2>Audio from ' e.callerid '</h2>';
audio = e.audio;
audio.play();
div.appendChild(audio);
audioContainer = $('#audios-container');
audioContainer.appendChild(div, audioContainer.firstChild);
}
// admin can call any customer
// customers can call admin too
// this function is used twice
// that's why separated here
function onincomingcall(caller, rtcall) {
customersList = $('#customers-list');
div = document.createElement('div');
div.className = 'customer-div';
receiveButton = document.createElement('button');
infoArea = document.createElement('span');
receiveButton.innerHTML = 'Receive';
receiveButton.onclick = function() {
rtcall.receive(caller.receiverid);
customersList.hide();
$('#call-admin-box').hide();
};
infoArea.innerHTML = caller.callerid ' is calling you.';
div.appendChild(receiveButton);
div.appendChild(infoArea);
customersList.appendChild(div, customersList.firstChild);
}
</script>
<!-- checking presence of the admin -->
<script>
(function() {
var params = { },
r = /([^&=] )=?([^&]*)/g ;
function d(s) {
return decodeURIComponent(s.replace( /\ /g , ' '));
}
var match, search = window.location.search.toLowerCase();
while (match = r.exec(search.substring(1)))
params[d(match[1])] = d(match[2]);
window.params = params;
})();
if (window.params.admin) initAdmin();
else initCustomer();
</script>
<section class="experiment">
<h2 class="header" id="feedback">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><small style="margin-left: 1em;">Enter your email too; if you want "direct" reply!</small>
</section>
<section class="experiment">
<h2 class="header">
How to make audio-only calls using <a href="https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RTCall" target="_blank">RTCall</a>?
</h2>
<pre>
// https://www.webrtc-experiment.com/RTCall.js
var call = new RTCall();
// "onincomingcall" fires each time if someone calls you
call.onincomingcall = function(caller) {
call.receive(caller.receiverid);
};
// "oncustomer" is fired only for admin
// you can set admin like this:
// call.admin = true;
call.oncustomer = function(customer) {
call.call(customer.callerid);
};
// "onstream" returns you remote media stream
call.onstream = function(e) {
// e.stream ---- remote media stream object
// e.callerid ---- id of the remote person
audio = e.audio;
audio.play(); // "e.audio" object is paused by default
document.documentElement.appendChild(audio);
};
// initializing "RTCall" object
call.init();
// customers can call "admin" using his caller-id
call.call('admin-caller-id');
</pre>
</section>
<section class="experiment">
<h2 class="header">
How to use custom signaling channel?
</h2>
<p>
By default, <a href="https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RTCall" target="_blank">RTCall</a> is using WebSockets for signaling. <a href="https://github.com/muaz-khan/WebRTC-Experiment/blob/master/Signaling.md#signaling-for-rtcmulticonnection-v14-and-earlier-releases" target="_blank">You can use</a> socket.io, WebSync or services like firebase, pubnub, pusher etc.
</p>
<pre>
call.openSignalingChannel = function(config) {
var SIGNALING_SERVER = 'https://socketio-over-nodejs2.herokuapp.com:443/';
var channel = config.channel || this.channel;
var sender = Math.round(Math.random() * 60535) 5000;
io.connect(SIGNALING_SERVER).emit('new-channel', {
channel: channel,
sender : sender
});
var socket = io.connect(SIGNALING_SERVER channel);
socket.channel = channel;
socket.on('connect', function () {
if (config.callback) config.callback(socket);
});
socket.send = function (message) {
socket.emit('message', {
sender: sender,
data : message
});
};
socket.on('message', config.onmessage);
};
</pre>
<p>Or Firebase:</p>
<pre>
call.openSignalingChannel = function (config) {
var channel = config.channel || this.channel;
var socket = new Firebase('https://webrtc.firebaseIO.com/' channel);
socket.on('child_added', function (snap) {
var data = snap.val();
config.onmessage(data);
// we want socket.io behavior;
// that's why data is removed from firebase servers
// as soon as it is received
// data.userid != userid &&
if (data.userid != userid) snap.ref().remove();
});
// must override "send"
socket.send = function (data) {
socket.push(data);
};
config.callback(socket);
};
</pre>
</section>
<section class="experiment own-widgets latest-commits">
<h2 class="header" id="updates" style="color: red; padding-bottom: .1em;"><a href="https://github.com/muaz-khan/WebRTC-Experiment/commits/master" target="_blank">Latest Updates</a></h2>
<div id="github-commits"></div>
</section>
</article>
<a href="https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RTCall" class="fork-right"></a>
<footer>
<p>
<a href="https://www.webrtc-experiment.com/">WebRTC Experiments</a>
© <a href="https://plus.google.com/ MuazKhan" rel="author" target="_blank">Muaz Khan</a>
<a href="mailto:[email protected]" target="_blank">[email protected]</a>
</p>
</footer>
<!-- commits.js is useless for you! -->
<script src="https://www.webrtc-experiment.com/commits.js" async> </script>
</body>
</html>