Fireship · @fireship
WebRTC in 100 Seconds // Build a Video Chat app from Scratch
Uploaded March 15, 2021 · Length 11:19
Summary
Build a peer-to-peer video chat app from scratch using WebRTC, vanilla JavaScript, and Firebase as the signaling server.
- webrtc
- video chat
- peer-to-peer
- javascript
- firebase
- signaling server
- web development
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
webrtc exchange real-time audio video
- 0:03
streams with your friends
- 0:04
entirely in the browser i'm here live
- 0:06
that's not i'm not a cat
- 0:08
if you want to build your own video
- 0:09
conferencing app to capitalize on the
- 0:11
work from home boom
- 0:12
then webrtc is the api you're looking
- 0:14
for because it allows you to establish a
- 0:17
peer-to-peer connection between two or
- 0:18
more browsers
- 0:19
where they can exchange audio video
- 0:21
media directly without the need for a
- 0:23
third-party server or native app
- 0:25
it works like this the first pier will
- 0:27
create an offer
- 0:28
asking for another peer to connect to
- 0:30
them this will result
- 0:31
in an stp object or session description
- 0:34
protocol
- 0:34
which contains information describing
- 0:36
the peer-to-peer connection
- 0:38
like the video codec timing and so on
- 0:40
the data will then be saved in a server
- 0:42
where it can then be read by another
- 0:44
peer to answer the call which is
- 0:45
achieved by creating an stp answer
- 0:48
and writing that to the server this
- 0:50
process is known as
- 0:51
signaling and it's handled by a third
- 0:53
party server the signaling server allows
- 0:55
the two parties to securely exchange
- 0:57
connection data
- 0:58
but never touches the media that's
- 0:59
actually transmitted between the peers
- 1:01
but here's where things get tricky most
- 1:03
devices in the real world sit behind
- 1:05
firewalls
- 1:05
and ip addresses constantly change
- 1:07
thanks to network address translation
- 1:10
this makes peer-to-peer connection
- 1:11
complicated from a networking standpoint
- 1:13
but luckily there's a standard called
- 1:15
interactive connectivity establishment
- 1:17
or ice which helps clients coordinate
- 1:20
the discovery of their public-facing ip
- 1:22
addresses
- 1:23
now both peers will generate a list of
- 1:25
ice candidates
- 1:26
which contain an ip address and port
- 1:28
that pier 1 can use to connect to pier
- 1:31
2.
- 1:31
in the background webrtc will do this by
- 1:34
making a series of requests to a stun
- 1:36
server
- 1:36
a stun server is not something you need
- 1:38
to set up on your own because there are
- 1:40
many free options out there
- 1:41
from reliable sources like google each
- 1:43
peer will save their ice candidates in
- 1:45
the database where they can then be read
- 1:47
by the other peer
- 1:48
the algorithm will then automatically
- 1:50
determine which candidate is best
- 1:52
at which point real-time media can begin
- 1:54
flowing between the two peers
- 1:55
this has been webrtc in 100 seconds if
- 1:58
you want to see more short videos like


