De Ce WebRTC
WebRTC oferă cea mai mică latență pentru audio în browser. Folosește UDP pentru transport, cu NAT traversal built-in. Ideal pentru conversații real-time.
50-100ms
Typical latency
UDP
Transport protocol
P2P
Direct connection
Core Components
RTCPeerConnection
Manages peer-to-peer connection și media
MediaStream
Handles audio/video tracks
ICE Candidates
Network path discovery
STUN Server
NAT address discovery
TURN Server
Media relay when direct fails
SDP
Session description protocol
WebRTC vs WebSocket
| Aspect | WebRTC | WebSocket |
|---|---|---|
| Protocol | UDP (primarily) | TCP |
| Latency | Lower (~50-100ms) | Higher (~100-200ms) |
| NAT Traversal | Built-in (ICE) | Requires proxy |
| Reliability | Unreliable default | Reliable |
| Setup Complexity | Higher | Lower |
| Browser Support | All modern | All modern |
Connection Flow
1getUserMedia() - Get microphone access
2Create RTCPeerConnection with ICE config
3Add audio track to peer connection
4Create and send SDP offer
5Receive SDP answer from server
6Exchange ICE candidates
7Connection established - stream audio
Browser Support
| Browser | Support | Notes |
|---|---|---|
| Chrome | Full | Best performance |
| Firefox | Full | Good compatibility |
| Safari | Full | iOS 11+, macOS 11+ |
| Edge | Full | Chromium-based |
| Opera | Full | Chromium-based |
STUN/TURN Configuration
const configuration = {
iceServers: [
{ urls: 'stun:stun.kallina.ai:3478' },
{
urls: 'turn:turn.kallina.ai:3478',
username: 'user',
credential: 'pass'
}
]
};
const pc = new RTCPeerConnection(configuration);