Production Best Practices
Going from “it works on my machine” to “it works for all users, reliably” requires addressing security, reliability, performance, and monitoring. This guide covers the key areas.Authentication
Use JWT in production
Generate JWTs on your backend
Handle token refresh
One credential per user
Never share a Telephony Credential across multiple users. Each user must have their own JWT to ensure they receive their own incoming calls.Connection Management
One client instance per tab
Clean up on page unload
Handle reconnection gracefully
Audio Quality
Request microphone with constraints
Monitor call quality
Enable call reports in production:Recommend headphones for agents
Built-in speakers + microphone create echo. For call center agents, recommend USB headsets or enforce echo cancellation.Network Configuration
Allowlist Telnyx domains
Ensure your firewall allows:| Domain | Port | Protocol | Purpose |
|---|---|---|---|
rtc.telnyx.com | 443 | WebSocket (TLS) | Signaling |
stun.telnyx.com | 3478 | UDP | STUN (ICE) |
turn.telnyx.com | 3478 | UDP | TURN relay |
turn.telnyx.com | 443 | TCP | TURN fallback |
api.telnyx.com | 443 | HTTPS | REST API |
Don’t force relay unless necessary
Error Handling
Always handle errors
Handle connection failures
Don’t show raw errors to users
Memory Management
Clean up call references
Remove event listeners
Monitoring & Observability
Enable call reports
Track key metrics
| Metric | Good | Warning | Critical |
|---|---|---|---|
| MOS | > 4.0 | 3.0–4.0 | < 3.0 |
| RTT | < 150ms | 150–300ms | > 300ms |
| Jitter | < 20ms | 20–50ms | > 50ms |
| Packet Loss | < 1% | 1–3% | > 3% |
Log quality issues server-side
Deployment Checklist
| Requirement | Details |
|---|---|
| Authentication uses JWT | login_token in production, not login+password |
| JWT generated on backend | API key never in browser |
Token refresh handles TOKEN_EXPIRING_SOON | Call client.updateToken() on warning code 34001 |
beforeunload disconnects client | Hang up calls and call client.disconnect() |
enableCallReports: true | Automatic call reports for production monitoring |
| Error handling covers key events | userMediaError, socket.close, socket.error |
| Firewall allows Telnyx domains | rtc.telnyx.com:443, stun.telnyx.com:3478, turn.telnyx.com:443 |
Reconnection UI shown during reconnecting state | Users should see connection status |
Call references cleaned up on destroyed state | Prevent memory leaks |
No forceRelayCandidate: true unless required | Forced relay adds 20-80ms latency |
| Quality metrics logged to monitoring | Track MOS, RTT, jitter, packet loss |
| User-friendly error messages | No raw errors shown to users |