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 anX-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 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.
keys folder inside it.2
Define the services
Create a dialplan for Asterisk. It answers calls to the Create a What each setting does:
asterisk extension and plays a short prompt.Filename: extensions.confcompose.yaml file. It runs routr-one with the public key mounted, an Asterisk server, and RTPEngine.Filename: compose.yamlRTPENGINE_HOSTmakesroutr-onestart the RTPRelay middleware and point it at RTPEngine.CONNECT_VERIFIER_PUBLIC_KEY_PATHturns on ephemeral agents. The Connect processor reads the key at startup and verifies everyX-Connect-Tokenwith it.CONNECT_VERIFIER_OPTIONSis optional. Its JSON is passed to the verifier, here to accept only RS256 signatures.- Port
5062is 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 Create a Domain with the SIP URI Create credentials with username Restart Asterisk so it registers now.Print the Domain’s reference. You need it for the token.
rctl.sip.local. An ephemeral agent must belong to a Domain that exists.asterisk and password asterisk, then a Peer with username asterisk, AOR sip:asterisk@sip.local, and those credentials.5
Sign a token
Set up a small Node.js project and install Create a script that signs the claims with your private key. Replace The claims tell Routr who the caller is and what they can do:
jsonwebtoken.domainRef with the reference from the previous step.Filename: create-jwt.jsRun the script and copy the token it prints.
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.htmlThis 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 Open If the page stays on Connecting…, check that port
https pages or on localhost. Serve the folder on localhost.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.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 withCtrl+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 theVerifier 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.