-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
800 lines (773 loc) · 32.2 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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2022-05-15 Sun 15:50 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Project: Video calling application</title>
<meta name="generator" content="Org mode" />
<link
rel="stylesheet"
type="text/css"
href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/htmlize.css"
/>
<link
rel="stylesheet"
type="text/css"
href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/readtheorg.css"
/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script
type="text/javascript"
src="https://fniessen.github.io/org-html-themes/src/lib/js/jquery.stickytableheaders.min.js"
></script>
<script
type="text/javascript"
src="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/js/readtheorg.js"
></script>
<style>
pre.src {
background-color: #303030;
color: #e5e5e5;
}
</style>
<style>
#content {
max-width: 1800px;
}
</style>
<script type="text/javascript">
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id) {
var target = document.getElementById(id);
if (null != target) {
elem.classList.add("code-highlighted");
target.classList.add("code-highlighted");
}
}
function CodeHighlightOff(elem, id) {
var target = document.getElementById(id);
if (null != target) {
elem.classList.remove("code-highlighted");
target.classList.remove("code-highlighted");
}
}
/*]]>*/ //-->
// @license-end
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
displayAlign: "center",
displayIndent: "0em",
"HTML-CSS": { scale: 100,
linebreaks: { automatic: "false" },
webFont: "TeX"
},
SVG: {scale: 100,
linebreaks: { automatic: "false" },
font: "TeX"},
NativeMML: {scale: 100},
TeX: { equationNumbers: {autoNumber: "AMS"},
MultLineWidth: "85%",
TagSide: "right",
TagIndent: ".8em"
}
});
</script>
<script
type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"
></script>
</head>
<body>
<div id="content">
<h1 class="title">Project: Video calling application</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li>
<a href="#org2aa826e">1. Getting Started</a>
<ul>
<li><a href="#org0fc061b">1.1. Installing</a></li>
<li><a href="#org3b58f61">1.2. Live site</a></li>
</ul>
</li>
<li>
<a href="#org33ac6e7">2. Objectives</a>
<ul>
<li>
<a href="#org846e0cc"
>2.1. Create an application which will set up an 1:1 video
call.</a
>
</li>
</ul>
</li>
<li><a href="#orgbdc307c">3. Technology Stack</a></li>
<li>
<a href="#orgdb0893d">4. Topics deep-dive</a>
<ul>
<li><a href="#org6eb3f61">4.1. Webrtc</a></li>
<li><a href="#orgb1c0058">4.2. NAT</a></li>
<li><a href="#org6791b95">4.3. STUN</a></li>
<li><a href="#org21e8e54">4.4. TURN</a></li>
<li><a href="#org0bea613">4.5. ICE</a></li>
<li><a href="#org29f4449">4.6. SDP</a></li>
</ul>
</li>
<li>
<a href="#org41dc089">5. WebRTC demo</a>
<ul>
<li><a href="#org7a0c26c">5.1. Ex outline</a></li>
<li><a href="#org61ea94f">5.2. Code outilne</a></li>
<li><a href="#orge0e0caa">5.3. Example with text</a></li>
<li><a href="#org35ca4e7">5.4. Example with media</a></li>
<li><a href="#org0947fa9">5.5. WebRTC Pros and Cons</a></li>
<li>
<a href="#org373686c">5.6. Set custom STUN and TURN server</a>
</li>
</ul>
</li>
<li><a href="#org39b0835">6. Resources</a></li>
</ul>
</div>
</div>
<div id="outline-container-org2aa826e" class="outline-2">
<h2 id="org2aa826e">
<span class="section-number-2">1.</span> Getting Started
</h2>
<div class="outline-text-2" id="text-1"></div>
<div id="outline-container-org0fc061b" class="outline-3">
<h3 id="org0fc061b">
<span class="section-number-3">1.1.</span> Installing
</h3>
<div class="outline-text-3" id="text-1-1">
<div class="org-src-container">
<pre class="src src-shell">
git clone <url>
npm i
npm start
</pre
>
</div>
</div>
</div>
<div id="outline-container-org3b58f61" class="outline-3">
<h3 id="org3b58f61">
<span class="section-number-3">1.2.</span> Live site
</h3>
<div class="outline-text-3" id="text-1-2">
<p>
Have a look at the live app by clicking
<a href="https://vast-anchorage-00245.herokuapp.com/">here</a>.
</p>
<ol class="org-ol">
<li>Open live app in two different devices.</li>
<li>In device 1 type a room name and hit go.</li>
<li>In device 2 type the same room name and hit go.</li>
<li>Video call will be established between these two devices.</li>
</ol>
</div>
</div>
</div>
<div id="outline-container-org33ac6e7" class="outline-2">
<h2 id="org33ac6e7">
<span class="section-number-2">2.</span> Objectives
</h2>
<div class="outline-text-2" id="text-2"></div>
<div id="outline-container-org846e0cc" class="outline-3">
<h3 id="org846e0cc">
<span class="section-number-3">2.1.</span> Create an application
which will set up an 1:1 video call.
</h3>
<div class="outline-text-3" id="text-2-1"></div>
<div id="outline-container-orgb6ec166" class="outline-4">
<h4 id="orgb6ec166">Working outline (basic)</h4>
<div class="outline-text-4" id="text-orgb6ec166"></div>
<ul class="org-ul">
<li>
<a id="orgd6a53e4"></a><span class="todo TODO">TODO</span>
<b>To set up a video call bewtween two users</b><br />
<div class="outline-text-5" id="text-orgd6a53e4">
<p>
one of them has to set up a call - i.e generate a
<b>call-id</b> and share it with the other person he wants
to connect with, using any other msging platform. Next, the
other user will use this id to join into the call.
</p>
</div>
</li>
<li>
<a id="orgcecfa88"></a><span class="todo TODO">TODO</span>
<b>Leaving the call</b><br />
<div class="outline-text-5" id="text-orgcecfa88">
<p>
When a meeting id is generated, a virtual space is created
for two people to join in and have a chat, both people can
join the space, or leave it an any moment.
</p>
</div>
</li>
<li>
<a id="org06d6310"></a><span class="todo TODO">TODO</span>
<b>Terminating the call</b><br />
<div class="outline-text-5" id="text-org06d6310">
<p>
The person who is creating the call has a special power to
<b>terminate it</b>.
<i
>If both users have left the call for a specified time
\(t\) then it <b>auto-terminates</b></i
>
</p>
</div>
</li>
</ul>
</div>
<div id="outline-container-org65cde68" class="outline-4">
<h4 id="org65cde68">User functions to be implemented.</h4>
<div class="outline-text-4" id="text-org65cde68"></div>
<ul class="org-ul">
<li>
<a id="org0ceb721"></a><span class="todo TODO">TODO</span>
<b
>Allocate the call space on specific time, given by the
creater of the call</b
><br />
<div class="outline-text-5" id="text-org0ceb721">
<p>
When the user creates a call-id, he will have an option to
create the call now or <b>shedule</b> it on a specific
date-time. Then both of them have to join in at that time.
</p>
</div>
</li>
</ul>
</div>
<div id="outline-container-orgd42bada" class="outline-4">
<h4 id="orgd42bada">API connectivity</h4>
<div class="outline-text-4" id="text-orgd42bada">
<p>
Video calling web-app has to integrate with other applications
built by team members. So it has to has to have an api by which
the team member can schedule an appointment, using their own
application interface.
</p>
</div>
</div>
</div>
</div>
<div id="outline-container-orgbdc307c" class="outline-2">
<h2 id="orgbdc307c">
<span class="section-number-2">3.</span> Technology Stack
</h2>
<div class="outline-text-2" id="text-3">
<ol class="org-ol">
<li>JS, HTML, CSS</li>
<li>Webrtc</li>
<li>Firebase/Setting up a STUN server</li>
</ol>
</div>
</div>
<div id="outline-container-orgdb0893d" class="outline-2">
<h2 id="orgdb0893d">
<span class="section-number-2">4.</span> Topics deep-dive
</h2>
<div class="outline-text-2" id="text-4"></div>
<div id="outline-container-org6eb3f61" class="outline-3">
<h3 id="org6eb3f61">
<span class="section-number-3">4.1.</span> Webrtc
</h3>
<div class="outline-text-3" id="text-4-1"></div>
<div id="outline-container-org16bae30" class="outline-4">
<h4 id="org16bae30">Overview</h4>
<div class="outline-text-4" id="text-org16bae30">
<ul class="org-ul">
<li>Stands for Web real-time communication.</li>
<li>
Find a Peer to peer path to exchange video and audio in a
clear and efficient manner.
</li>
<li>Standardized API</li>
<li>A want to connet to B</li>
<li>
A finds to find out all possible ways the <b>public</b> can
connect to it.
</li>
<li>
B finds to find out all possible ways the <b>public</b> can
connect to it.
</li>
<li>
A and B signal this session information via other means
<ul class="org-ul">
<li>WhatsApp, QR, Tweet, Websockets, HTTP fetch</li>
</ul>
</li>
<li>
A connects to B via the most optimal path. (a graph network
structure)
</li>
<li>A & B exhanges their supported media and security.</li>
<li>
Key terms
<ul class="org-ul">
<li>NAT</li>
<li>STUN</li>
<li>ICE</li>
<li>SDP</li>
<li>Signalling the SDP.</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-orgb1c0058" class="outline-3">
<h3 id="orgb1c0058">
<span class="section-number-3">4.2.</span> NAT
</h3>
<div class="outline-text-3" id="text-4-2"></div>
<div id="outline-container-orgaeb0147" class="outline-4">
<h4 id="orgaeb0147">Overview</h4>
<div class="outline-text-4" id="text-orgaeb0147">
<div id="org3094fc1" class="figure">
<p><img src="./img/nat_send.png" alt="nat_send.png" /></p>
<p>
<span class="figure-number">Figure 1: </span>send data using
NAT
</p>
</div>
<div id="orgfc12ff7" class="figure">
<p><img src="./img/nat_rec.png" alt="nat_rec.png" /></p>
<p>
<span class="figure-number">Figure 2: </span>recieve data
using NAT
</p>
</div>
<p>There are 4 kinds of NAT:</p>
<ol class="org-ol">
<li>
<p>Full cone or One to One NAT</p>
<ul class="org-ul">
<li>
<p>
Packets to external IP:port on the router always maps to
internal IP:port without exceptions.
</p>
<div id="org1c21b73" class="figure">
<p><img src="./img/nat1.png" alt="nat1.png" /></p>
<p>
<span class="figure-number">Figure 3: </span>Full cone
nat
</p>
</div>
</li>
</ul>
<p>
<img src="./img/nat2.png" alt="nat2.png" />
Here we don't check if we know the person, sending the info
ie, NAT table's destination ip and port doesn't need to
match with incoming ip packet's ip or port.
</p>
</li>
<li>Address restricted NAT</li>
<li>Port restricted NAT</li>
<li>Symmetric NAT</li>
</ol>
</div>
</div>
</div>
<div id="outline-container-org6791b95" class="outline-3">
<h3 id="org6791b95">
<span class="section-number-3">4.3.</span> STUN
</h3>
<div class="outline-text-3" id="text-4-3"></div>
<div id="outline-container-orgc37d391" class="outline-4">
<h4 id="orgc37d391">Overview</h4>
<div class="outline-text-4" id="text-orgc37d391">
<ul class="org-ul">
<li>Session traversal utilities for NAT</li>
<li>Tell me my public ip address/port through NAT</li>
<li>Works for full-cone, Port/Adress restricted NAT</li>
<li>Doesn't work for symmetric NAT</li>
<li>Cheap to maintain</li>
</ul>
<div id="org37d1733" class="figure">
<p><img src="./img/stun.png" alt="stun.png" /></p>
<p>
<span class="figure-number">Figure 4: </span>STUN When it
works
</p>
</div>
</div>
</div>
</div>
<div id="outline-container-org21e8e54" class="outline-3">
<h3 id="org21e8e54">
<span class="section-number-3">4.4.</span> TURN
</h3>
<div class="outline-text-3" id="text-4-4"></div>
<div id="outline-container-org4ee0a3e" class="outline-4">
<h4 id="org4ee0a3e">Overview</h4>
<div class="outline-text-4" id="text-org4ee0a3e">
<ul class="org-ul">
<li>Traversal using relays around NAT</li>
<li>In case of Symmetric NAT we use TURN</li>
<li>It's just a server that relays packets</li>
<li><p>Expensive to maintain and run</p></li>
</ul>
<div id="org9b61f9a" class="figure">
<p><img src="./img/turn.png" alt="turn.png" /></p>
</div>
</div>
</div>
</div>
<div id="outline-container-org0bea613" class="outline-3">
<h3 id="org0bea613">
<span class="section-number-3">4.5.</span> ICE
</h3>
<div class="outline-text-3" id="text-4-5"></div>
<div id="outline-container-org7e93db5" class="outline-4">
<h4 id="org7e93db5">Overview</h4>
<div class="outline-text-4" id="text-org7e93db5">
<ul class="org-ul">
<li>Interactive Connectivity Establishment</li>
<li>
ICE collects all available candidates (local IP addresses,
reflexive addresses - STUN ones and relayed addresses - TURN
ones)
</li>
<li>Called ice candidates</li>
<li>
All the collected addresses are then sent to the remote peer
via SDP
</li>
</ul>
</div>
</div>
<div id="outline-container-org8c9d803" class="outline-4">
<h4 id="org8c9d803">onIceCandidiate and addIceCandidate</h4>
<div class="outline-text-4" id="text-org8c9d803">
<ul class="org-ul">
<li>
To maintain the connection as new candidates come and go
</li>
<li>
onIceCandidate tells user there is a new candidate after the
SDP has already been created
</li>
<li>The candidate is signalled and sent to the other party</li>
<li>
The other party uses addiceCandidate to add it to its SDP
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-org29f4449" class="outline-3">
<h3 id="org29f4449">
<span class="section-number-3">4.6.</span> SDP
</h3>
<div class="outline-text-3" id="text-4-6"></div>
<div id="outline-container-orgf0e65af" class="outline-4">
<h4 id="orgf0e65af">Overview</h4>
<div class="outline-text-4" id="text-orgf0e65af">
<ul class="org-ul">
<li>Session Description Protocol</li>
<li>
A format that describes ice candidates, networking options,
media options, security options and other stuff
</li>
<li>Not really a protocol but a format</li>
<li>Most important concept WebRTC</li>
<li>
The goal is to take the SDP generated by a user and send it
"somehow" to the other party
</li>
</ul>
</div>
</div>
</div>
</div>
<div id="outline-container-org41dc089" class="outline-2">
<h2 id="org41dc089">
<span class="section-number-2">5.</span> WebRTC demo
</h2>
<div class="outline-text-2" id="text-5"></div>
<div id="outline-container-org7a0c26c" class="outline-3">
<h3 id="org7a0c26c">
<span class="section-number-3">5.1.</span> Ex outline
</h3>
<div class="outline-text-3" id="text-5-1">
<ol class="org-ol">
<li>A wants to connect to B</li>
<li>
A creates and "offer", it finds all ice candidates, security
options, audio/video stream options and generates SDP,
<b>the offer is basically the SDP</b>
</li>
<li>A signals the offer somehow to B</li>
<li>B creates the "answer" after setting A's offer</li>
<li>B signals the "answer" to A</li>
<li>Connection is created!!.</li>
</ol>
</div>
</div>
<div id="outline-container-org61ea94f" class="outline-3">
<h3 id="org61ea94f">
<span class="section-number-3">5.2.</span> Code outilne
</h3>
<div class="outline-text-3" id="text-5-2">
<p>What are we going to do-</p>
<ol class="org-ol">
<li>We will connect browsers (Browsers A and B)</li>
<li>
A will create an offer (sdp) and set it as local description
</li>
<li>B will get the offer and set it as remote description</li>
<li>
B creates an answer sets it as its local description and signals
the answer(sdp) to A
</li>
<li>A sets the answer as its remote description.</li>
<li>Connection established, exchange data!!</li>
</ol>
</div>
</div>
<div id="outline-container-orge0e0caa" class="outline-3">
<h3 id="orge0e0caa">
<span class="section-number-3">5.3.</span> Example with text
</h3>
<div class="outline-text-3" id="text-5-3">
<p>
Here well will make two browsers send text data between each
other. Input code in browser console, to start a communication
channel
</p>
<p>
<b>Browser 1, initiator</b>
</p>
<div class="org-src-container">
<pre
class="src src-javascript"
><span style="color: #9d81ba;">const</span> <span style="color: #7CF083;">lc</span> = <span style="color: #9d81ba;">new</span> <span style="color: #62D2DB;">RTCPeerConnection</span>();
<span style="color: #454459;">// </span><span style="color: #454459;">creating a data channel, a chanell we are gonna communicate through</span>
<span style="color: #9d81ba;">const</span> <span style="color: #7CF083;">dc</span> = lc.createDataChannel(<span style="color: #f5c791;">"channel"</span>);
<span style="color: #454459;">// </span><span style="color: #454459;">when we recive a msg print the following</span>
dc.onmessage = e => console.log(<span style="color: #f5c791;">"Just got a message "</span> + e.data);
dc.onopen = e => console.log(<span style="color: #f5c791;">"Connection Open"</span>);
<span style="color: #454459;">// </span><span style="color: #454459;">before creating an offer, reprint sdp every-time new ice candidate is encounterd</span>
lc.onicecandidate = e => console.log(<span style="color: #f5c791;">"New ice candidate! reprinting SDP"</span> + JSON.stringify(lc.localDescription));
<span style="color: #454459;">// </span><span style="color: #454459;">wait 12 secs?</span>
<span style="color: #454459;">// </span><span style="color: #454459;">create the offer (promise)</span>
lc.createOffer().then(o => lc.setLocalDescription(0)).then(a => console.log(<span style="color: #f5c791;">"set succesfully!"</span>));
<span style="color: #454459;">// </span><span style="color: #454459;">signal to peer 2</span>
</pre>
</div>
<p>
<b>Browser 2, accepts the offer, and gives an answer</b>
</p>
<div class="org-src-container">
<pre
class="src src-javascript"
><span style="color: #9d81ba;">const</span> <span style="color: #7CF083;">offer</span> = {paste spd data}
<span style="color: #9d81ba;">const</span> <span style="color: #7CF083;">rc</span> = <span style="color: #9d81ba;">new</span> <span style="color: #62D2DB;">RTCPeerConnection</span>();
rc.onicecandidate = e => console.log(<span style="color: #f5c791;">"New ice candidate! reprinting SDP"</span> + JSON.stringify(rc.localDescription));
rc.ondatachannel = e => {
rc.dc = e.channel;
rc.dc.onmessage = e => console.log(<span style="color: #f5c791;">"new message from client!"</span> + e.data)
rc.dc.onopen = e => console.log(<span style="color: #f5c791;">"Connection OPENED!!!"</span>)
};
rc.setRemoteDescription(offer).then(a => console.log(<span style="color: #f5c791;">"offer set!"</span>));
rc.createAnswer().then (a => rc.setLocalDescription(a)).then(a => console.log(<span style="color: #f5c791;">"answer created"</span>));
<span style="color: #454459;">// </span><span style="color: #454459;">Now signal the answer back to peer 1</span>
</pre>
</div>
<p>
<b>Browser 1, accepts the answer, sets up the channel</b>
</p>
<div class="org-src-container">
<pre
class="src src-javascript"
><span style="color: #9d81ba;">const</span> <span style="color: #7CF083;">answer</span> = paste_aswer_from_brower_2;
lc.setRemoteDescription(answer);
<span style="color: #454459;">// </span><span style="color: #454459;">pray and see if connection is opened</span>
<span style="color: #454459;">// </span><span style="color: #454459;">if connection opened, to send data</span>
dc.send(<span style="color: #f5c791;">"Hello, how are you?"</span>);
</pre>
</div>
<p>
<b>Browser 2, send data, after connection is opened</b>
</p>
<div class="org-src-container">
<pre
class="src src-javascript"
>rc.dc.send(<span style="color: #f5c791;">"I am fine ThankYou!!"</span>);
</pre>
</div>
</div>
</div>
<div id="outline-container-org35ca4e7" class="outline-3">
<h3 id="org35ca4e7">
<span class="section-number-3">5.4.</span> Example with media
</h3>
<div class="outline-text-3" id="text-5-4">
<p>
Send video and audio between two browsers. Same workflow as prev
only difference being, we need to save the stream using
<code>MediaDevices.getUserMedia()</code> function and pass it to
<code>lc.addTrack(stream)</code>
</p>
</div>
</div>
<div id="outline-container-org0947fa9" class="outline-3">
<h3 id="org0947fa9">
<span class="section-number-3">5.5.</span> WebRTC Pros and Cons
</h3>
<div class="outline-text-3" id="text-5-5"></div>
<div id="outline-container-org0cb6301" class="outline-4">
<h4 id="org0cb6301">Pros</h4>
<div class="outline-text-4" id="text-org0cb6301">
<ul class="org-ul">
<li>
Peer to peer is great! low latency for high bandwith content.
</li>
<li>Standardized API I don't have to built my own.</li>
</ul>
</div>
</div>
<div id="outline-container-orgef08d49" class="outline-4">
<h4 id="orgef08d49">Cons</h4>
<div class="outline-text-4" id="text-orgef08d49">
<ul class="org-ul">
<li>Maintaining STUNS and TURN sernvers</li>
<li>
P2P fails apart in case of multiple participants (discord
case)
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-org373686c" class="outline-3">
<h3 id="org373686c">
<span class="section-number-3">5.6.</span> Set custom STUN and TURN
server
</h3>
<div class="outline-text-3" id="text-5-6">
<ul class="org-ul">
<li><i>Serach public STUN servers</i></li>
<li>
<a href="https://github.com/coturn/coturn"
>coturn create your own STUN and TURN server github</a
>
</li>
</ul>
<div class="org-src-container">
<pre
class="src src-javascript"
><span style="color: #9d81ba;">const</span> <span style="color: #7CF083;">iceConfiguration</span> = {
iceServers : [{
urls: <span style="color: #f5c791;">'turn:turnserver.company.com:3478'</span>,
username: <span style="color: #f5c791;">'optional-username'</span>,
credentials: <span style="color: #f5c791;">'auth-token'</span>},
{ urls: <span style="color: #f5c791;">""</span>,
username: <span style="color: #f5c791;">""</span>,
credential: <span style="color: #f5c791;">""</span>
}
}]
}
<span style="color: #9d81ba;">const</span> <span style="color: #7CF083;">pc</span> = <span style="color: #9d81ba;">new</span> <span style="color: #62D2DB;">RTCPeerConnection</span>(configuration);
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org39b0835" class="outline-2">
<h2 id="org39b0835">
<span class="section-number-2">6.</span> Resources
</h2>
<div class="outline-text-2" id="text-6">
<ul class="org-ul">
<li>
<a href="https://www.youtube.com/watch?v=FExZvpVvYxA"
>WebRtc CrashCourse</a
>
</li>
<li>
<a href="https://www.html5rocks.com/en/tutorials/webrtc/basics/"
>WebRTC basics blog by html5 rocks</a
>
</li>
<li>
<a href="https://developer.mozilla.org/en-US/d"
>https://developer.mozilla.org/en-US/d</a
>
</li>
<li>
<a href="https://developer.mozilla.org/en-US/d"
>https://developer.mozilla.org/en-US/d</a
>
</li>
<li>
<a href="https://developer.mozilla.org/en-US/d"
>https://developer.mozilla.org/en-US/d</a
>
</li>
<li>
<a href="https://tools.ietf.org/html/draft-iet"
>https://tools.ietf.org/html/draft-iet</a
>
</li>
<li>
<a href="https://support.frozenmountain.com/hc"
>https://support.frozenmountain.com/hc</a
>
</li>
<li>
<a href="https://webrtcforthecurious.com/"
>https://webrtcforthecurious.com/</a
>
</li>
<li>
<a href="https://getvoip.com/blog/2013/02/27/s"
>https://getvoip.com/blog/2013/02/27/s</a
>
</li>
<li>
<a href="https://www.onsip.com/voip-resources/"
>https://www.onsip.com/voip-resources/</a
>
</li>
<li>
<a href="http://io13webrtc.appspot.com/#52"
>http://io13webrtc.appspot.com/#52</a
>
</li>
<li>
<a href="https://www.youtube.com/watch?v=PoRJizFvM7s"
>Asycn Javascrip crash course</a
>
</li>
<li>
<a href="https://ably.com/topic/socketio"
>Everything you need to know about socket.io</a
>
</li>
</ul>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="date">Created: 2022-05-15 Sun 15:50</p>
<p class="validation">
<a href="https://validator.w3.org/check?uri=referer">Validate</a>
</p>
</div>
</body>
</html>