🐋 Intro
WebRTC enables real time communication between browsers directly.
- Capturing media: grabbing your camera and microphone.
- Making a connection: setting up a secure “pipe” between them
- Sending encrypted data: ****All streams are encrypted (DTLS-SRTP).
🛠️ How WebRTC Works
- Media Capture using
getUserMedia().
- Signaling (the “handshake”)
- WebRTC needs SDP & ICE to connect, so apps use a signaling server (WebSockets or HTTP) to exchange them.
- SDP (Session Description Protocol): describes what codecs, resolutions, and formats each side supports.
- ICE Candidates: possible best network paths (IP addresses, ports) to connect.
- Peer-to-Peer Connection
- Once signaling is done, browsers try to connect directly using RTCPeerConnection.
- They use STUN/TURN servers:
- STUN servers help reveal your public IP so peers can attempt a direct connection.
- TURN servers step in when firewalls/NATs are too strict, relaying traffic through a middleman.
- Data Flow — After the connection is established, streams flow directly
🧊 ICE (Interactive Connectivity Establishment)
- A framework WebRTC uses to figure out how two devices can connect over the internet.
- Why it’s needed: Devices can be behind firewalls, routers, or NATs (Network Address Translators), so their “real” address isn’t always obvious.
- How it works:
- Each browser gathers possible connection points (called ICE candidates) — these might be local IPs, public IPs, or relay addresses.
- The browsers exchange these candidates via signaling.
- They test which path actually works best (fastest, most reliable).