Matrix RTC/Element Call Setup
This guide assumes that you are using docker compose for deployment. LiveKit only provides Docker images.
You can find help setting up MatrixRTC in our dedicated room - #matrixrtc:continuwuity.org
Instructions
1. Domain
LiveKit should live on its own domain or subdomain. In this guide we use livekit.example.com - this should be replaced with a domain you control.
Make sure the DNS record for the (sub)domain you plan to use is pointed to your server.
2. Services
Using LiveKit with Matrix requires two services - LiveKit itself, and a service (lk-jwt-service) that grants Matrix users permission to connect to it.
You must generate a key and secret to allow the Matrix service to authenticate with LiveKit. LK_MATRIX_KEY should be around 20 random characters, and LK_MATRIX_SECRET should be around 64. Remember to replace these with the actual values!
LiveKit provides a utility to generate secure random keys
Create a docker-compose.yml file as following:
Next, we need to configure LiveKit. In the same directory, create livekit.yaml with the following content - remembering to replace LK_MATRIX_KEY and LK_MATRIX_SECRET with the values you generated:
Firewall hints
You will need to allow ports 7881/tcp and 50100:50200/udp through your firewall. If you use UFW, the commands are: ufw allow 7881/tcp and ufw allow 50100:50200/udp.
3. Telling clients where to find LiveKit
To tell clients where to find LiveKit, you need to add the address of your lk-jwt-service to the [global.matrix_rtc] config section using the foci option.
The variable should be a list of servers serving as MatrixRTC endpoints. Clients discover these via the /_matrix/client/v1/rtc/transports endpoint (MSC4143).
Remember to replace the URL with the address you are deploying your instance of lk-jwt-service to.
4. Configure your Reverse Proxy
Reverse proxies can be configured in many different ways - so we can't provide a step by step for this.
All paths should be forwarded to LiveKit by default, with the exception of the following path prefixes, which should be forwarded to the JWT/Authentication service:
/sfu/get/healthz/get_token
Example caddy config
Example nginx config
Note that for websockets to work, you need to have this somewhere outside your server block:
Example traefik router
6. Start Everything
Start up the services using your usual method - for example docker compose up -d.
Additional TURN configuration
Using LiveKit's built-in TURN server
LiveKit includes a built-in TURN server which can be used in place of an external option. This TURN server will only work with LiveKit, so you can't use it for legacy Matrix calling or anything else.
If you don't want to set up a separate TURN server, you can enable this with the following changes:
Recreate the LiveKit container (with docker-compose up -d livekit) to apply these changes. Remember to allow the new 3478/udp and 50100:50200/udp ports through your firewall.
Integration with an external TURN server
If you've already set up coturn, you can configure Livekit to use it.
Before continuing, make sure coturn's min-port and max-port do not overlap with LiveKit's port range:
Generate a long random secret for LiveKit, and add it to your coturn config under the static-auth-secret option. You can add as many secrets as you want, so set a different one for LiveKit to use.
Then configure LiveKit, making sure to replace COTURN_SECRET with the one you generated:
Restart LiveKit and coturn to apply these changes.
Testing
To test that LiveKit is successfully integrated with Continuwuity, you will need to replicate its Token Exchange Flow.
First, you will need an access token for your current login session. These can be found in your client's settings or obtained via this website.
Then, using that token, request another OpenID token for use with the lk-jwt-service:
Next, create a payload.json file with the following content:
payload.json
Replace matrix_server_name and claimed_user_id with your information, and <openid_access_token> with the one you got from the previous step. Other values can be left as-is.
You can then send this payload to the lk-jwt-service:
The lk-jwt-service will, after checking against Continuwuity, answer with a jwt token to create a LiveKit media room. Use this token to test at the LiveKit Connection Tester. If everything works there, then you have set up LiveKit successfully!
Troubleshooting
To debug any issues, you can place a call or redo the Testing instructions, and check the container logs for any specific errors. Use docker-compose logs --follow to follow them in real-time.
Common errors in Element Call UI
MISSING_MATRIX_RTC_FOCUS: LiveKit is missing from Continuwuity's config file- "Waiting for media" popup always showing: a LiveKit URL has been configured in Continuwuity, but your client cannot connect to it for some reason
Docker loopback networking issues
Some distros do not allow Docker containers to connect to its host's public IP by default. This would cause lk-jwt-service to fail connecting to livekit or continuwuity on the same host. As a result, you would see connection refused/connection timeouts log entries in the JWT service, even when LIVEKIT_URL has been configured correctly.
To alleviate this, you can try one of the following workarounds:
-
Use
network_mode: hostfor thelk-jwt-servicecontainer (instead of the default bridge networking). -
Add an
extra_hostsfile mapping livekit's (and continuwuity's) domain name to a localhost address: -
(untested, use at your own risk) Implement an iptables workaround as shown here.
After implementing the changes and restarting your compose, you can test whether the connection works by cURLing from a sidecar container:
Workaround for non-federating servers
When deploying on servers with federation disabled (allow_federation = false), LiveKit will fail as it can't fetch the required OpenID endpoint via federation paths.
As a workaround, you can enable federation, but forbid all remote servers via the following config parameters:
Subscribe to issue !1440 for future updates on this matter.
Related Documentation
Guides:
- Element Call self-hosting documentation
- Community guide with overview of LiveKit's mechanisms
- Community guide using systemd
Specifications:
Source code: