All you Need to know About WebRTC in 2022. [The complete guide]

 All you Need to know About WebRTC in 2022.

    Today we are going to talk about WebRTC a technology used by Google, Discord, Zoom, etc and there are a lot more. This technology is used for making video calling applications. 

So, What we are going to cover?

1. What is WebRTC?
2. What is Signalling Server?
3. What is STUN Server?
4. What is TURN Server?
5. What is SDP?
6. What are ICE Candidates?
7. How to make direct connection between peers?
8. How to all work together?

#1] What is WebRTC?

WebRTC ( Web Real Time Communication ) is an open source project that enables peer-to-peer communication between browsers or the applications(mobile). In other words, WebRTC allows you to exchange any kind of media through the web (such as Video, Audio and Data) without any required plugin or framework.

    1. Google MEET and Google Hangouts.
    2. Facebook Messenger.
    3. Discord.
    4. Zoom.

#2] What is Signalling Server?

Signalling server does not do anything that is WebRTC specific. Signalling server helps to exchange the data or information which are required to establish direct connection between users. For this we can use anything what we like such as, WebSockets, XMLHttpRequest or Firebase or any preferred tech stack.

So, what type of information we exchange here?
When we need to connect to other user we need some information about the browser or application and the STUN server [Some Internet Connection Details] so that we can make a direct peer connection. 

#3] What is STUN Server?

We need to call the other user but HOW? 
For Example:- In our phone we dial the number of user to make a call. And we get connected.
Same in STUN server we share internet connection details such as public IP to other user and other user makes A answer by sending back his Internet connection details. 
  • STUN (Session Traversal Utilities for NAT) that allows client to discover their public IP Address and the type of NAT they are behind. This information is used to establish the media connection.
  • In 15-20% cases STUN will fail to establish connection between the peers we will need TURN Sever.

#4] What is TURN Server?

    When the caller tries to connect to other user and try to send connection details and If the other user is behind a NAT then it is not possible for the STUN server to connect and share the details, so it fails.
And Here comes the TURN server in place and even if the user is behind any NAT TURN server will make the connection possible.
  • TURN server is TRAVERSAL Using Relay NAT, and it is protocol for relaying network traffic.
  • It will be used is STUN Server fails to connect.
  • TURN server will be used as an assist to establish connection between the peers
  • Turn Server area not public because of the costs which they can generate because of the traffic which is going through them.

#5] What is SDP?
Before we make a direct peer connection first we need to exchange some data i.e the SDP  through the signalling server. The caller will create a offer and send SDP information to the calle through signalling server. An Calle will save the offer and create a answer and send it to the caller through signalling server. Now, both the caller and calle have information to connect to each other.
  • The Session Description Protocol is a format to describing multimedia communication sessions for the purposes of session announcement and session invitation.
  • It does not deliver the media but data is used for negotiation between peers of various audio, video codecs, source address, timing information of audio and video.  

#6] What are ICE Candidates?

    We saw how to connect and direct peer connection through signalling server. But what about STUN server details we share for the connection. ICE Candidates are the internet connection details we get from STUN server.

  • As well as exchanging information about the media (discussed above in Offer/Answer & SDP). peers must exchange information about the network connection. This is known as ICE Candidates and details the available methods peer is able to communicate (directly or through TURN server). Typically, each peer will propose it’s best candidates first making its way down the line towards their worse candidates. Ideally, candidates are UDP (since it’s faster, and media streams are able to recover from interruptions relatively easily), but ICE standard does allow TCP candidates as well. 

#7] How WebRTC works?

WebRTC with STUN server

In Above diagram, you can see I have added numbers for you so it becomes easy to understand the flow.

  1. Caller John makes a offer with connection details through the signalling server to calle Kate. Then kate saves the offer from John and send the answer with it’s connection details and John saves Kate’s offers.
  2.   STUN Server will get ICE Candidates from both the Caller and Calle’s.
  3. Stun Server will send ICE Candidates to Caller and Calle.
  4. John’s ICE Candidates will flow through signalling server to Kate. And Kate’s ICE Candidates will flow through signalling server to John.
  5. If The users are not behind any NAT then call will be established. But if user is behind NAT then the connection will be established through TURN server as below diagram.
WebRTC with TURN server

Thank you Guys! Today we learned about WebRTC and How it works? I hope you understood the foundation of the WebRTC based application. If you like it please comment about your opinions.

1 thought on “All you Need to know About WebRTC in 2022. [The complete guide]”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top