Skip to main content

What you’ll build

You build a web page that registers to Routr over WebSocket and calls an Asterisk server, without creating an Agent in the database. Instead, you sign a JSON Web Token (JWT) whose claims describe the caller. The browser sends the token in an X-Connect-Token header, the Connect processor verifies it with your public key, and treats the caller as an ephemeral agent for as long as the token is valid. RTPEngine, driven by the RTPRelay middleware, bridges the browser’s WebRTC media to the plain RTP that Asterisk expects. This is how you let website visitors call your contact center without giving each of them a SIP account.

Prerequisites

  • Docker with Docker Compose
  • Node.js and npm
  • OpenSSL
  • A browser with microphone access (Chrome, Firefox, or Safari)
  • The IP address of your machine on your local network (for example, 192.168.1.3)

Steps

1

Create a signing key pair

Create a folder for the tutorial and a keys folder inside it.
Generate an RSA private key. You sign tokens with it, so keep it secret and never ship it to the browser.
Derive the public key from it. Routr uses the public key to verify tokens.
2

Define the services

Create a dialplan for Asterisk. It answers calls to the asterisk extension and plays a short prompt.Filename: extensions.conf
Create a compose.yaml file. It runs routr-one with the public key mounted, an Asterisk server, and RTPEngine.Filename: compose.yaml
What each setting does:
  • RTPENGINE_HOST makes routr-one start the RTPRelay middleware and point it at RTPEngine.
  • CONNECT_VERIFIER_PUBLIC_KEY_PATH turns on ephemeral agents. The Connect processor reads the key at startup and verifies every X-Connect-Token with it.
  • CONNECT_VERIFIER_OPTIONS is optional. Its JSON is passed to the verifier, here to accept only RS256 signatures.
  • Port 5062 is EdgePort’s WebSocket (ws) listener. The browser connects there.
3

Start the stack

Start the services. Replace the address with your own.
Check that the three containers are up.
4

Create the Domain and the Asterisk Peer

Install rctl.
Create a Domain with the SIP URI sip.local. An ephemeral agent must belong to a Domain that exists.
Create credentials with username asterisk and password asterisk, then a Peer with username asterisk, AOR sip:asterisk@sip.local, and those credentials.
Restart Asterisk so it registers now.
Print the Domain’s reference. You need it for the token.
5

Sign a token

Set up a small Node.js project and install jsonwebtoken.
Create a script that signs the claims with your private key. Replace domainRef with the reference from the previous step.Filename: create-jwt.js
The claims tell Routr who the caller is and what they can do:Run the script and copy the token it prints.
In production, sign tokens on your backend after you decide the visitor may call, and keep expiresIn short. Anyone holding a valid token can call the aorLink until it expires.
6

Build the web client

Create a page that uses SIP.js’s SimpleUser to connect to EdgePort’s WebSocket port, register, and call. The token goes in an X-Connect-Token header on both the REGISTER and the INVITE. Replace the token and the IP address.Filename: index.html
This page loads SIP.js from a CDN to keep the tutorial short. In a real app, install sip.js from npm and bundle it.
7

Serve the page and register

Browsers only allow microphone access on https pages or on localhost. Serve the folder on localhost.
Open http://localhost:8080 and allow microphone access when asked.
The page shows Registered. Routr accepted the REGISTER because the token verified, and it stored the browser’s route under sip:visitor@sip.local.
If the page stays on Connecting…, check that port 5062 is published and the IP in server is correct. If the registration fails with 403 Forbidden, the token didn’t verify: check that public.key matches the private key, the token hasn’t expired, and domain matches your Domain’s SIP URI.
8

Call Asterisk

Click Call. Routr verifies the token on the INVITE, finds the Peer whose AOR equals aorLink, and routes the call agent-to-peer. RTPRelay asks RTPEngine to bridge the browser’s WebRTC media to Asterisk.
The page shows In call and you hear Asterisk’s “Hello world” prompt in the browser.

Clean up

Stop the static server with Ctrl+C, then stop and remove the containers.

Use a verifier service instead of a key

If you’d rather not mount a public key in Routr, run a gRPC service that implements the Verifier interface in verifier.proto and set CONNECT_VERIFIER_ADDR (for example, verifier:51915) on the Connect processor instead of CONNECT_VERIFIER_PUBLIC_KEY_PATH. Set only one of the two.

Next steps

Enable WebRTC

RTPRelay and RTPEngine settings for Docker and Kubernetes.

RTPRelay

How the media middleware works and how to configure it.

Connect processor

Environment variables, including the verifier settings.

Load balance Asterisk

Put several Asterisk servers behind the same Peer.