# Configuring WebRTC in Asterisk (FreePBX)

## Technical requirements

* **The telephony server must be accessible from the Internet, i.e. it must have a static IP.**
* **Must have a working SSL/TLS certificate.**
* Asterisk version not less than 11 ([?](#webrtc-support-in-asterisk)), but for convenience preferably 15 ([?](#pjsip-in-asterisk)) or at least 13 ([?](#configuration-examples)).
* When using browser-based softphone, wss (WebSocket Secure) must be configured on the Asterisk server, and the port must be open to the outside (usually 8089) ([?](#freepbx)).

  This is configured in the admin interface:

  Advanced Settings > Asterisk Builtin mini-HTTP section > HTTPS Bind Port
* Port range for RTP (typically 10000-20000) ([?](#freepbx)).

  It is configured in the administrator interface:

  Settings → Asterisk SIP Settings → General SIP Settings Tab

## Setting

This example describes how to configure WebRTC in an already running FreePBX server:

* is available at \<example>.com and **has an SSL/TLS certificate**;
* FreePBX version 16, Asterisk version 15;
* wss is configured on port 8089;
* all other relevant ports are open.

## Configuring FreePBX

{% hint style="danger" %}
If the "Change To CHAN\_PjSIP Driver" button (see below, in the internal number setting) is available, you do not need to do anything in this section.
{% endhint %}

**Settings ➝ Advanced Settings**

| Section Dialplan and Operational |      |
| -------------------------------- | ---- |
| SIP Channel Driver               | both |

**Settings ➝ Asterisk SIP Settings**

**Tab “SIP Legacy Settings \[chan\_sip]”**

**Verify that the variables are set:**

| Section Advanced General Settings |                                                                                     |
| --------------------------------- | ----------------------------------------------------------------------------------- |
| Other SIP Settings                | <p>icesupport = yes</p><p>media\_encryption = dtls</p><p>tlscipher = AES256-SHA</p> |

## Creating and setting up an extension number (extension)

Go to the FreePBX configuration interface and log in: https\://\<example>.com/&#x20;

Go to section **Applications ➝ Extensions**

Button “**+ Add Extension**” **➝** “**+ Add New SIP (Legacy) \[chan\_sip] Extension**” (other versions of FreePBX may be “Add New Chan\_SIP extension”)

**In the tab General:**

| Section Add Extension |      |
| --------------------- | ---- |
| User Extension        | 1001 |
| Display Name          | 1001 |

**Press the button Submit**

After that, open editing of the newly created extension in the list of extensions (in the line with 5001 in the Actions column, click the edit button with a pencil icon).

**Go to the tab Advanced**

**First change the SIP Driver to PjSIP:**

| Tab Advanced → Section Edit Extension |                             |
| ------------------------------------- | --------------------------- |
| Enable WebRTC defaults                | Yes                         |
| Media Encryption                      | DTLS-SRTP (not recommended) |

**Press the button Submit**

**Then change the SIP Driver back:**

| Tab Advanced → Section Edit Extension |                            |
| ------------------------------------- | -------------------------- |
| Change SIP Driver                     | Change To CHAN\_SIP Driver |

**Now to make the remaining customizations:**

| Tab Advanced → Section Edit Extension |                       |
| ------------------------------------- | --------------------- |
| Transport                             | All - WSS Primary     |
| Enable AVPF                           | Yes                   |
| Force AVP                             | Yes                   |
| Enable ICE Support                    | Yes                   |
| Enable rtcp Mux                       | Yes                   |
| Enable Encryption                     | Yes (SRTP only)       |
| Section DTLS                          |                       |
| Enable DTLS                           | Yes (there should be) |
| Use Certificate                       | \<example>.com        |

**Press the button Submit**

**Press the button Apply Config**

## Testing that wss works

Let's use the sipML5 live demo from Doubango as an example:

<https://www.doubango.org/sipml5/call.htm>

### Setting

**First, the "Expert mode?" button.**

The advanced settings page should open in the next tab

| Disable Video        | v (checkmark)       |
| -------------------- | ------------------- |
| WebSocket Server URL | wss\://.com:8089/ws |

**Press the button Save**

**Back to the main tab**

| Display Name     | 1001                                                                                            |
| ---------------- | ----------------------------------------------------------------------------------------------- |
| Private Identity | 1001                                                                                            |
| Public Identity  | sip:1001@\<example>.com                                                                         |
| Password         | <p>Copy from FreePBX settings</p><p>Extension: 1001 ➝ General tab ➝ Edit Extension ➝ Secret</p> |
| Realm            | \<example>.com                                                                                  |

**Button Login**

The word Connected should appear at the top above the Registration heading.

### Call

Now you can make the call.

Under the Call control heading, dial the desired number (\*43 for an echo call or a cell phone number with 8 first).

**Press the button Call ➝ Audio**

**There's a call that should go out.**

**Profit!**

### Links

#### **WebRTC support in Asterisk**

Initial support for WebRTC in Asterisk starting with version 11:

* [New in 11 - Asterisk Project - Asterisk Project Wiki](https://wiki.asterisk.org/wiki/display/AST/New+in+11)
* [Asterisk WebRTC Support - Asterisk Project - Asterisk Project Wiki](https://wiki.asterisk.org/wiki/display/AST/Asterisk+WebRTC+Support)

#### **PjSIP in Asterisk**

* New chan\_pjsip driver in Asterisk 12: [New in 12 - Asterisk Project - Asterisk Project Wiki](https://wiki.asterisk.org/wiki/display/AST/New+in+12)
* PjSIP is available by default in Asterisk 15: [PJSIP-pjproject - Asterisk Project - Asterisk Project Wiki](https://wiki.asterisk.org/wiki/display/AST/PJSIP-pjproject)

#### **FreePBX**

* [Ports used on your PBX - PBX Platforms - Documentation](https://wiki.freepbx.org/display/PPS/Ports+used+on+your+PBX)

#### **Configuration examples**

* [Configuring Asterisk for WebRTC Clients](https://wiki.asterisk.org/wiki/display/AST/Configuring+Asterisk+for+WebRTC+Clients)&#x20;
* [WebRTC clients SIPML5 JSSIP setup configurations and complete end to end client server call demo](https://youtu.be/7pA7j0kt5vA)

<br>
