A few days ago, my girlfriend came home. I was busy coding. She wanted to talk. I said, "Just five more minutes." Five minutes became thirty. Thirty became an hour. Eventually she got upset, left, and went home.
Now it was night. And suddenly I wasn't focused on coding anymore. I was worried. So I called her.
She hung up. I called again. Hung up. At this point I knew things were getting serious. So I tried one last thing. I hit the video call button. This time she picked up. And within a few seconds, there she was. I could see her.
She could see me. We could talk in real time.
But after the call ended, I started wondering about something.
How did that actually happen?
Think about it.
My laptop is sitting in one house.Her phone is sitting in another. They're connected to completely different networks.They have never met before.Yet somehow, after pressing one button, they found each other and started communicating almost instantly.
That's exactly the problem WebRTC solves.
WebRTC is a technology that allows two devices to communicate directly in real time.
Audio.
Video.
Messages.
Files.
Anything.
But here's the interesting part.
lets say my browser is A and hers is B.
When I press the video call button, my browser doesn't magically know where her's is.
And her browser doesn't magically know where my browser is.
The first challenge is simple.
They need to find each other.
but it is not possible to find each other in this ocean of internet, so a middle server is needed to connect both of them , this is called signalling server , and this exchange In WebRTC, is called signaling.
Signaling is basically the introduction phase. A signal server can be anything a websocket,http or firestore .
So browser A stores its information in signal server , and browser B reads that information , now B knows about A, But A dosen't know about B, so now B stores its information in signal server , and then A gets information about B , now A knows B and B knows A.
this information is called SDP-session Description protocol , it contains info about what browser supports , like video and audio format text etc.
But there's still one problem.
both of then know about each other but they dont know how to connect to each other , so here comes ICE - Interactive Connectivity Establishment.
As part of connection process , browser gathers a list of ICE candidates, they describe about the ip address of the browser, so now both the browser share there ip address to the signaling server and both get to know the path of each other and finally a connection is established between both of them, and no signaling server is needed now , a direct peer to peer connection has been established now.
The video.
The audio.
The messages.
Everything starts flowing between them in real time.
And the funny thing is...
by the time my girlfriend is explaining why she's upset...
the browser has already exchanged SDP information, ICE candidates, and established a peer-to-peer connection.
All in just a few seconds.
That's WebRTC.
A lot of complicated networking happening behind the scenes...
so you can have one simple conversation.