Core Architectural Principle
Comparing Real-Time Technologies
1. WebSockets: Persistent State Synchronization
Why Use WebSockets?
- Sub-100ms Latency: Eliminates HTTP header overhead on every frame.
- State Sync: Ideal for broadcasting live dashboard metrics, active call statuses, and role-based notifications.
- Signaling Channel: Acts as the negotiation medium required to establish a WebRTC peer connection.
WebSocket Connection Setup
2. WebRTC & NAT Traversal: Connecting Peers Directly
Text
The Role of STUN & TURN Servers
- STUN (Session Traversal Utilities for NAT): A lightweight server that tells a client: "Here is your public IP and port." The peers then exchange these ICE Candidates via WebSockets. If the NAT type allows simple mapping, a direct P2P link is established.
- TURN (Traversal Using Relays around NAT): If restrictive enterprise firewalls or symmetric NATs block direct P2P streaming, the connection falls back to a TURN server. The TURN server acts as a relay proxy for all media traffic.
Configuring ICE Servers in WebRTC
Technical Insights & FAQ
Can WebSockets replace WebRTC for audio and video streaming?
Why are TURN servers necessary if STUN is free?
How do you combine React/Next.js state with WebSockets efficiently?