WebRTC Tutorial
Learn WebRTC step by step: 36 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is WebRTC? Learn what WebRTC is, what it can do (video calls, voice, file transfer, games), how it differs from WebSockets and HTTP, and what this course will teach.
- Your First Loopback Call Build your first WebRTC connection: two RTCPeerConnection objects in one page exchange an offer, an answer and ICE candidates, then send a message.
- The WebRTC API Overview A map of the WebRTC API: RTCPeerConnection, MediaStream, RTCRtpSender, RTCDataChannel, getStats and the protocols (ICE, DTLS, SRTP, SCTP) beneath them.
- Environment, Secure Contexts and Permissions Set up for WebRTC: secure contexts (HTTPS and localhost), camera and microphone permission prompts, Permissions-Policy, feature detection and browser support.
Concepts and Signalling
- The Offer/Answer Handshake Understand the WebRTC offer/answer model: signalling states, setLocalDescription and setRemoteDescription, provisional answers, rollback and renegotiation.
- SDP Explained Learn to read WebRTC SDP line by line: session and media sections, codecs and payload types, ICE credentials, DTLS fingerprints, directions, and when to edit SDP.
- Signalling Channels Design a WebRTC signalling channel: what messages to send, how to use WebSockets and rooms, queue early ICE candidates, and handle joins, leaves and errors.
- Perfect Negotiation Learn the perfect negotiation pattern: polite and impolite peers, offer collisions (glare), rollback, ignoring offers, and a complete symmetrical implementation.
Media Capture and Streams
- Capturing Media with getUserMedia Capture camera and microphone with navigator.mediaDevices.getUserMedia: show a live preview, handle every error, stop devices and test without hardware.
- Constraints and Devices Control capture with media constraints (ideal, exact, min, max), list cameras and microphones with enumerateDevices, switch devices, and tune audio processing.
- MediaStream and Tracks Understand MediaStream and MediaStreamTrack: ids, kinds, readyState, enabled versus muted versus stopped, cloning, adding and removing tracks, and track events.
- Capturing from Canvas and Web Audio Create WebRTC media without a camera: canvas.captureStream for generated video, Web Audio MediaStreamDestination for synthesized sound, and a video element's captureStream.
- Screen Capture and Recording Share a screen, window or tab with getDisplayMedia, handle the user stopping the share, and record any MediaStream to a file with MediaRecorder.
Peer Connections and ICE
- The RTCPeerConnection Life Cycle Learn the four RTCPeerConnection state machines (signaling, ICE gathering, ICE connection, connection), their events, the configuration object and how to close cleanly.
- ICE Candidates and NAT Understand why peers need ICE: private addresses and NAT, candidate types (host, srflx, relay), candidate pairs, priorities, mDNS hostnames and connectivity checks.
- Trickle ICE and ICE Restarts Learn trickle ICE for fast call setup, how end-of-candidates works, when to use restartIce, and how to recover from disconnected and failed connections.
- Transceivers and Senders Master RTCRtpTransceiver, RTCRtpSender and RTCRtpReceiver: direction, mid, replaceTrack without renegotiation, setParameters bitrate limits and setCodecPreferences.
- Sending Video and Audio over a Connection Send audio and video over an RTCPeerConnection: addTrack, the ontrack event, rendering remote streams, removing tracks, measuring frames with getStats, and a complete call template.
Data Channels
- Data Channels: Sending Messages Between Peers Learn how RTCDataChannel sends text and binary data directly between browsers: create a channel, handle open, message and close events, and test it in a loopback demo.
- Data Channel Reliability and Ordering Choose between reliable and unreliable delivery for RTCDataChannel. Learn ordered, maxRetransmits and maxPacketLifeTime, head-of-line blocking, and which setup fits games or files.
- Binary Data, Message Size and Backpressure Send strings, JSON, ArrayBuffers and Blobs over RTCDataChannel, respect maxMessageSize, chunk big payloads, and use bufferedAmount and bufferedAmountLow to avoid flooding.
- Data Channel Protocols: Negotiated Channels and Patterns Design a message protocol on top of RTCDataChannel: negotiated channels with fixed ids, typed envelopes, request and response with ids, heartbeats and multiple channels.
Servers: STUN, TURN and SFU
- STUN Servers and NAT: How Peers Find Each Other Understand why home routers hide your address, how a STUN server reveals your public IP and port, what host and srflx candidates are, and how to configure iceServers.
- TURN Servers: Relaying Media When Direct Paths Fail Learn when WebRTC needs a TURN relay, how ephemeral TURN credentials are generated with HMAC, how to force relay mode, and what a basic coturn setup looks like.
- Mesh, MCU and SFU: Choosing a Multi-Party Topology Compare mesh, MCU and SFU architectures for group video calls. Calculate bandwidth per participant, understand server cost and latency, and pick the right topology for your app.
- SFU in Practice: Simulcast, SVC and Layer Selection See how simulcast and scalable video coding let an SFU send each viewer the right quality. Configure sendEncodings with rid, read parameters and simulate layer selection.
Quality and Debugging
- Reading getStats for Call Quality Use RTCPeerConnection.getStats() to measure bitrate, packet loss, jitter and round-trip time. Compute rates from two snapshots and build a small quality monitor you can run.
- Controlling Bitrate and Adapting to Bandwidth Learn how WebRTC adapts to bandwidth automatically and how you can steer it: maxBitrate, maxFramerate, scaleResolutionDownBy, degradationPreference, contentHint and codec preferences.
- Debugging WebRTC: States, Errors and a Checklist A practical WebRTC debugging guide: track connection and ICE states, read common error names, use chrome://webrtc-internals, and follow a checklist when a call will not connect.
Security and Applications
- WebRTC Security: DTLS, SRTP and Certificate Fingerprints See how WebRTC encrypts everything by default: the DTLS handshake, SRTP media keys, SDP certificate fingerprints, what a signalling attacker can do, and how to verify peers.
- WebRTC Privacy: Permissions, mDNS Candidates and IP Leaks Understand what WebRTC reveals about users: local and public IP addresses, device labels and permissions. Learn mDNS candidates, relay-only mode, Permissions Policy and good consent UX.
- WebRTC in Real Apps: Reconnection, Scaling and E2EE Move WebRTC from demo to product: recover from network changes with ICE restarts and backoff, scale signalling, add end-to-end encryption with encoded transforms, and plan monitoring.
Projects and Practice
- Project: A Peer-to-Peer Chat With Typing Indicators Build a two-person chat on WebRTC data channels: a signalling stand-in, connection status, typed messages, typing indicators and delivery receipts, all running in one page.
- Project: File Transfer With Progress and Checksum Build a peer-to-peer file sender: a metadata header, 16 KiB chunks with backpressure, progress reporting, reassembly into a Blob and SHA-256 verification, all runnable in one page.
- Project: A Signalling Server With Rooms Design a WebSocket signalling server for WebRTC: join a room, relay offers, answers and candidates, handle leave events. Run the same protocol against an in-page hub and read the Node server.
- Practice: WebRTC Exercises With Solutions Test your WebRTC skills with four hands-on exercises: measure round-trip time, prove ordered delivery, classify candidates and build a stats summary, each with a runnable solution.