Integration
Video relay
How video calls and live streams travel, and how to run your own TURN server with coturn.
#You do not need to set anything up
FX Phone carries the picture of a video call between the two phones over WebRTC through a TURN relay. The voice stays on your voice resource.
With the TURN fields in config_server.lua left empty, the picture goes through the Fixitfy relay (ServerConfig.Video.Hosted = true). The server enrols itself on the first video call. If no relay answers, the camera stays off and the call itself still works.
This page is for servers that want the picture to pass through their own machine. Once you fill in your own TURN settings, the Fixitfy relay is not used for that server.
Players' IP addresses are never shown to each other: with AllowDirect = false the whole picture passes through the TURN server.
Settings: config_server.lua (ServerConfig.Video) and Calls configuration (Config.Video).
#What you need
The steps below are for Ubuntu 22.04 or 24.04. The TURN server can be the same machine as the FiveM server; a separate machine is recommended. coturn has no official Windows build, so a Windows game server needs a separate small Linux machine for TURN.
- A fixed public IP address.
- Optional but recommended: a domain name pointing at that IP, for TLS.
- Open ports:
3478UDP and TCP,5349TCP (TLS),49160-49660UDP (media), and80TCP for the certificate if you set up TLS. - Bandwidth: the picture passes through the server, so it both receives and sends every stream. One call uses up to
Config.Video.MaxBitratein and out for each of the two directions. Choose your provider's traffic allowance accordingly.
The files for this setup are in fx-phone/setup/integration/video-relay/: a turnserver.conf template and a health check script.
#1. Install coturn
bashsudo apt update
sudo apt install -y coturn
sudo sed -i 's/^#\?TURNSERVER_ENABLED=.*/TURNSERVER_ENABLED=1/' /etc/default/coturn
Generate a secret. Do not share it; it goes into config_server.lua in step 4.
bashopenssl rand -hex 32
#2. Configure
Copy the turnserver.conf template from the setup folder to the server and fill in its values:
bashsudo cp /etc/turnserver.conf /etc/turnserver.conf.backup
sudo nano /etc/turnserver.conf
| Field | Value |
|---|---|
static-auth-secret |
The secret from step 1 |
realm |
Your domain name, or any name |
external-ip |
Only behind NAT (the public IP does not show on the machine's network card): PUBLIC_IP/PRIVATE_IP |
cert, pkey |
Enabled after step 5, if you set up TLS |
coturn listens on all of the machine's addresses; you do not need a listening-ip line.
Do not change the security lines in the template. no-tcp-relay and the denied-peer-ip lines keep a player in a call from reaching your server's own services or the private network through TURN.
#3. Firewall and service
bashsudo ufw allow 3478/udp
sudo ufw allow 3478/tcp
sudo ufw allow 5349/tcp
sudo ufw allow 49160:49660/udp
sudo systemctl enable coturn
sudo systemctl restart coturn
sudo systemctl status coturn --no-pager
If your provider's panel has its own firewall, open the same ports there too.
#4. FX Phone settings
Fill in ServerConfig.Video in config_server.lua. This file is never sent to players.
luaServerConfig.Video = {
IceServers = {
{ urls = { 'turn:SERVER_IP:3478?transport=udp', 'turn:SERVER_IP:3478?transport=tcp' } },
-- With TLS: { urls = { 'turns:turn.example.com:5349?transport=tcp' } },
},
TurnSecret = 'THE_SECRET_FROM_STEP_1',
CredentialSeconds = 600,
AllowDirect = false,
}
Make sure Config.Video.Enabled = true and restart fx-phone.
The login for a call is minted on the server for each side separately and is only valid for CredentialSeconds. A fixed password never reaches the client.
#5. TLS
Some players' networks block UDP. TLS on port 5349 works in that case too. It needs a domain name.
coturn runs as the turnserver user and cannot read the key under /etc/letsencrypt. The hook below copies the certificate to a place coturn can read every time it is issued or renewed, and restarts coturn:
bashsudo apt install -y certbot
sudo ufw allow 80/tcp
sudo tee /usr/local/bin/coturn-cert-hook >/dev/null <<'EOF'
#!/bin/sh
set -e
install -d -o turnserver -g turnserver -m 750 /etc/coturn/certs
install -o turnserver -g turnserver -m 644 "$RENEWED_LINEAGE/fullchain.pem" /etc/coturn/certs/fullchain.pem
install -o turnserver -g turnserver -m 600 "$RENEWED_LINEAGE/privkey.pem" /etc/coturn/certs/privkey.pem
systemctl restart coturn
EOF
sudo chmod +x /usr/local/bin/coturn-cert-hook
sudo certbot certonly --standalone -d turn.example.com --deploy-hook /usr/local/bin/coturn-cert-hook
Port 80/tcp must stay open: certbot verifies through it at every renewal. If a web server already uses port 80 on this machine, --standalone does not work; use --webroot -w <your web root> instead.
When the certificate renews, the hook restarts coturn. In video calls running at that moment the picture drops for an instant and the phone tries to reconnect once. The voice is not affected.
Then remove the # in front of the cert and pkey lines in turnserver.conf, restart coturn, and add the turns: line to IceServers.
#6. Health check
Copy the health check script from the setup folder to the TURN server and run it with the server's public IP or domain:
bashchmod +x saglik.sh
./saglik.sh SERVER_IP
The script asks for the secret without echoing it, so it stays out of the shell history. It checks from the inside that the service runs, that the ports listen, and that a temporary login gets an address from TURN over UDP and TCP.
A test from the inside cannot see the provider's firewall. The script therefore ends by printing a username and password valid for 10 minutes. Enter them on a WebRTC "Trickle ICE" test page on your own computer and gather candidates. If the list shows a line of type relay, the server works from the outside. Then try a video call in game.
#Troubleshooting
| Symptom | Cause and fix |
|---|---|
| The call continues with voice only and says the video could not connect | Ports closed, or TurnSecret differs between coturn and config_server.lua. Run the health check and the outside test |
No relay line in the outside test |
Port 3478 or the 49160-49660 UDP range is closed in the provider's panel; behind NAT, external-ip is missing |
coturn does not start, the log says Cannot bind |
A listening-ip was added by hand and that IP is not on the machine. Remove the line |
Console: video calls are off: ServerConfig.Video has no TURN server, Hosted is false and AllowDirect is false |
Hosted was set to false and IceServers is empty or TurnSecret is missing |
| Some players never get a picture | Their network blocks UDP. Set up TLS (step 5) |
| The picture stutters | Not enough bandwidth on the TURN server, or Config.Video.MaxBitrate is too high. Lower it |
coturn logs: sudo journalctl -u coturn -f.
#Live streams
Live streams use the same relay. The streamer's phone sends one picture per viewer, so a full stream uses up to Config.Live.MaxViewers times Config.Live.MaxBitrate. See Live and social configuration and Live.