WebRTC: The Backbone of Modern Communication Systems
Know about the high-level working of WebRTC Protocol.
Since the internet's inception, the ability to transfer data has always been evolving. In earlier times ( before the internet ), we were transfering data via cables through physical electronic waves. After that, we tend to transfer data using some protocols defined by some masters who initially had an idea about connecting the world via the internet. After some more evolution, we could also transfer the data wirelessly by introducing something known as BLE ( Bluetooth ) or WiFi, which is technically also a protocol.
In modern times, we are speedily transferring data. We can chat with someone with just a click or can see someone on our mobile or smart devices with a click. This is technically a "Transfer of data from your system to another system via the internet". To achieve this kind of real-time data transfer from one device to another WebRTC ( Web Real-Time Communication ) was introduced.
What is WebRTC?
WebRtc is an open-source project which enables web browsers and mobile applications to conduct or to have real-time communication with their pre-defined APIs, by allowing peer-to-peer connection between the concerned devices. It allows audio, video and streaming inside web pages via this P2P connection.
Enough of the definitions, let's understand how WebRTC works under the hood.
How does WebRTC work?
Now, let's say I need to do a video call to my friend or a voice call to my friend over WhatsApp. This is a transfer of data packets from my device to my friend's device via the Internet.
To transfer the data packets via the internet, there are some pre-defined rules which are often known as Protocols. We will not go deep into the protocol in this article, but they are pre-defined sets of rules that are required to send data packets via the internet between two devices that are connected via the internet.
The two most commonly and most used protocols are
TCP ( Transmission Control Protocol )
UDP ( User Datagram Protocol )
Here the important thing to know is that WebRTC uses UDP as a data transmission protocol, simply because it can transfer data speedily between two connected devices via the internet as compared to TCP.
Now to transfer the data between two devices with WebRTC, there are certain things or information we need from both devices.
To connect the web browsers of the concerned entities, who want to transfer data ( be it a video call, voice call or streaming ), WebRTC need something known as the Public IP of the concerned devices.
For eg: If I want to call my friend, I will require his phone number, and then I can contact him via phone and then we can transfer/hear our voices on our cell phones.
Here as we can see in the above diagram, Private IP is an address that devices use to connect with local routers ( Routers in our home or offices ). Public IP is an address that routers use to connect with the Internet.
Now here's the interesting thing. The Public IP address of a router is always unique while the Private IP address for two different routers can be similar. Thus Private IP is only used to connect with our local router, and when the router wants to send our request to the internet it uses its own Public IP address to cater for our request. So in this process, our Private IP address is not exposed to the internet, but only the Public IP of our router is exposed.
Now here's the problem. To connect the concerned devices with WebRTC, we need the Public IP address of the routers to which the concerned devices are connected.
For Eg: In my house, my wifi router has some Public IP address and on the other hand, In my friend's house, he has a wifi router with another Public IP address. If we want to connect our web-browsers for a video call let's say, then we need to provide information about our Public IP addresses to WebRTC and then we can connect via WebRTC for a video call.
To get the required information about the Public IP address, we need to request TURN / ICE servers to get our Public IP address.
What is a Traversal Using Relays around NAT ( TURN ) ?
TURN servers provide the necessary information to a device about its public IP configurations.
Now when the concerned devices request the TURN server to get information about public IP configurations, the TURN server will provide the same to devices and each device will have information about its Public IP address.
The last step in the process is to now provide the Public IP addresses of concerned devices to each other. In this, we need some medium to share one device's public IP address with another device and vice versa, this step is called Signaling.
What is Signaling and Session Description?
When a device requests for its public IP address to the TURN server, the TURN server will not only give the public IP address as a simple string. Instead, It will provide a full configuration object which is called Session Description ( SDP ).
In Session Description ( SDP ), there is a Public IP address, Private IP address and other necessary information about a device which is very much necessary to get a P2P connection with another device.
Thus we need to transfer this SDP of one device with another device and vice versa to create a P2P connection between these two devices and hence establish WebRTC between these two devices.
To transfer the SDP configurations between concerned devices, we need to connect the concerned devices with an external server using WebSockets, so that the SDP can be transferred from one device to another and vice versa.
When these SDPs are shared between the concerned devices, after that the P2P connection is established between that concerned devices.
Now connected devices can transfer data using a P2P connection via WebRTC. These devices can now do a video call, audio call or file transfer ( Not recommended though ), using WebRTC and with an underlying P2P connection.
We have reached to an end for this article. In this article, we have seen some very basic and high-level working of WebRTC and its underlying components.
In the further articles, we will see some networking topology for connecting more and more devices with WebRTC using P2P connections and some coding parts as well.
Thank you for taking the time to read this article and make sure to learn something new every day.๐
If you have any doubts or concerns, mail me at dharmjoshi01@gmail.com