WebRTC enables voice/video calling directly in a web browser without requiring a separate softphone application. This guide covers integrating WebRTC calling with an Asterisk-based PBX.
Why WebRTC Calling Is Valuable
Rather than requiring users to install a dedicated softphone application, WebRTC lets calling happen directly within a web browser — genuinely lowers the friction for click-to-call functionality, browser-based support widgets, or web application-integrated calling.
Prerequisites: Asterisk with WebRTC Support
See How to Install Asterisk PBX on a VPS for base setup — ensure your Asterisk installation includes WebRTC-related modules (chan_pjsip with WebSocket transport support, commonly included in modern Asterisk builds).
Step 1 — Configure a WebSocket Transport in PJSIP
[transport-wss]
type=transport
protocol=wss
bind=0.0.0.0:8089
cert_file=/etc/asterisk/keys/cert.pem
priv_key_file=/etc/asterisk/keys/privkey.pem
WebRTC requires secure WebSocket (WSS) transport — genuine TLS certificates are mandatory, not optional, since browsers refuse insecure WebRTC connections for privacy/security reasons.
Step 2 — Configure a WebRTC-Enabled Endpoint
[webrtc-user]
type=endpoint
transport=transport-wss
webrtc=yes
context=internal
disallow=all
allow=opus,ulaw
webrtc=yes enables the necessary WebRTC-specific handling (DTLS-SRTP for media encryption, ICE for connectivity) automatically for this endpoint.
Step 3 — Set Up ICE/STUN for WebRTC Connectivity
[general]
stun_server=stun.yourdomain.com:3478
See How to Configure NAT Traversal for SIP (STUN/TURN) — WebRTC relies heavily on ICE (which uses STUN/TURN) for establishing connectivity, particularly important since browser-based clients are almost always behind NAT.
Step 4 — Build the Browser-Side WebRTC Client
<script src="https://cdn.jsdelivr.net/npm/sip.js"></script>
<script>
const userAgent = new SIP.UserAgent({
uri: SIP.UserAgent.makeURI('sip:[email protected]'),
transportOptions: { server: 'wss://yourdomain.com:8089/ws' },
});
userAgent.start();
</script>
A JavaScript SIP library (SIP.js is a common choice) handles the browser-side WebRTC/SIP signaling, letting you build calling functionality directly into a web page.
Handling Microphone Permissions
Browsers require explicit user permission for microphone access — ensure your application properly requests and handles this permission flow, including graceful handling if permission is denied.
Testing Across Different Browsers
WebRTC implementation details can vary subtly across browsers — test your specific implementation across the major browsers your users actually use, rather than assuming universal compatibility without verification.
Securing the WebRTC Endpoint
See How to Secure a VoIP Server Against Toll Fraud for general VoIP security principles — WebRTC endpoints need the same authentication/authorization rigor as any other SIP endpoint; don't assume browser-based access is inherently safer.
Common Errors
Connection fails with certificate errors — verify your WSS transport uses a genuinely valid, browser-trusted TLS certificate (see How to Set Up SRTP and TLS Encryption for Secure VoIP); browsers are strict about certificate validity for WebRTC connections, more so than some traditional SIP clients.
Continue Reading
- How to Configure NAT Traversal for SIP (STUN/TURN)
- How to Set Up SRTP and TLS Encryption for Secure VoIP
- How to Secure a VoIP Server Against Toll Fraud
Browse more articles in VoIP & Communication Servers.