How to Configure WebRTC for Browser-Based Calling

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

Browse more articles in VoIP & Communication Servers.

  • webrtc asterisk browser calling, pjsip websocket transport, sip.js browser softphone, webrtc click to call setup
  • 0 Utilizadores acharam útil
Esta resposta foi útil?

Artigos Relacionados

How to Install Asterisk PBX on a VPS

Asterisk is the foundational open-source telephony engine powering most self-hosted PBX systems...

How to Install FreePBX on a VPS

FreePBX is a widely-used, open-source web interface built on top of Asterisk — making PBX...

How to Set Up SIP Trunking for Your PBX

A SIP trunk connects your self-hosted PBX to the public telephone network, letting you make and...

How to Configure Extensions and Voicemail in Asterisk

Extensions are the individual phone lines within your PBX system, and voicemail lets callers...

How to Secure a VoIP Server Against Toll Fraud

An unsecured VoIP server is a common target for toll fraud — attackers who compromise weak...