P2P Connections with WebRTC

Introduction

With the advancement of the internet, modern-day web browsers are becoming more powerful every day with the introduction of native APIs like WebGL and WebRTC. In earlier days when we wanted to establish a connection between two web browsers, we needed a server in between transferring requests to and fro. But with WebRTC, Connections can be made from browser to browser without any need for a server.

How does it work?

WebRTC provides simple JavaScript APIs that any developer can use in their web or native applications. Establishing a connection using WebRTC is usually a three-step process.

  1. Signaling
  2. Connecting
  3. Communicating

Let’s go over these one by one,

Signaling

In order to connect to any peer on the internet, we need to know where the client is located. So when a client wants to stream the data, It will create an offer and put it on the signaling server. This offer contains information about the client. When creating this offer, we must note that not all devices are visible on the public internet and might not have the capability to expose their public IP addresses. It is hard to find the public IP address of the devices that sit behind a NAT (Network Address Translation) layer.

Hence, to avoid the problems included with clients behind NAT we use a protocol called Interactive Connectivity Establishment (ICE). ICE finds a way to get the connection between peers by relying on STUN. A STUN server returns the public IP address of the respective peer which can be further shared over the public internet.

Once we have the public address and are able to establish the peer connection, we no longer need STUN servers. So, we have the public address and are ready to connect. Now a peer will create an offer and  ready to connect.

Once peer A is ready to start a communication it creates an offer called SDP (Session Description Protocol) which is basically a JSON object that contains information about the session like the media format and network information

Connecting

Now that we have an SDP offer from peer A, we want the other peer(s) to accept that offer. The SDP offer will now be sent to the signaling server and the signaling server will take care of sending offers to other peer(s) on the internet who wants to join or connect. Once peer B wants to connect it accepts the SDP offer and sends its IP address for the connection.

Communication

Once both parties offer and accept the offer we can transfer the data. Since both peers have Public IP addresses they no longer need any server medium to transfer data between them unless they are behind NAT(Network Address Translation) servers which translates the public IP address to a local IP address keeping the client protected from the outside world. But even with NATs in the picture the communication is done through the P2P mechanism.

Who uses WebRTC?

Many popular streaming services in today’s world are mostly relying on WebRTC for P2P communication. As per Google Chrome’s report, people are streaming more than 214 million minutes on WebRTC per day and the count is only on Google Chrome without including other web browsers.

Some of the tech giants who use WebRTC are as follows,

  1. Google Meet and Hangouts
  2. Facebook Messenger
  3. Discord
  4. Amazon Chime
  5. House Party

WebRTC will be Widely used in Video Conferencing, Online Gaming, etc. Since the server is eliminated, there is almost no network traffic, the cost of servers is reduced and latency is involved in p2p connections.

About the author

Ramachandra Reddy Satti

Add comment

5 − 1 =

Welcome to Miracle's Blog

Our blog is a great stop for people who are looking for enterprise solutions with technologies and services that we provide. Over the years Miracle has prided itself for our continuous efforts to help our customers adopt the latest technology. This blog is a diary of our stories, knowledge and thoughts on the future of digital organizations.


For contacting Miracle’s Blog Team for becoming an author, requesting content (or) anything else please feel free to reach out to us at blog@miraclesoft.com.

Who we are?

Miracle Software Systems, a Global Systems Integrator and Minority Owned Business, has been at the cutting edge of technology for over 24 years. Our teams have helped organizations use technology to improve business efficiency, drive new business models and optimize overall IT.

Recent Posts