WebRTC
In one line
WebRTC enables real-time peer-to-peer audio, video, and arbitrary data communication directly between browsers.
In simple words
WebRTC (Web Real-Time Communication) is a browser API that lets two browsers establish a direct peer-to-peer connection and stream audio, video, or arbitrary data — without the media passing through a server. This enables video chats, screen sharing, and low-latency multiplayer games in the browser.
The connection involves three steps: signaling (exchange connection info via a server), connection (establish the peer link via ICE/STUN/TURN), and streaming (send media tracks or data channels). Once connected, media flows directly between peers for minimal latency.
WebRTC handles the hard parts — codec negotiation, NAT traversal, encryption — for you. You capture media with getUserMedia, create an RTCPeerConnection, and attach tracks. Data channels let you send arbitrary binary/text data with optional reliable delivery.
Example
// Get the user's camera and create a peer connection
async function startCall() {
const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
const pc = new RTCPeerConnection();
stream.getTracks().forEach(track => pc.addTrack(track, stream));
pc.ontrack = (e) => {
document.querySelector("video").srcObject = e.streams[0];
};
// Signaling (offer/answer) would be exchanged via a signaling server
}
startCall();getUserMedia captures camera/mic. Tracks are added to an RTCPeerConnection. The remote peer's tracks arrive via ontrack.
Related terms
Related Resources
Related Lessons
- WebRTC
Learn real-time communication.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.