Calls, SFU and TURN
What the server needs for direct and group calls, ports, NAT, TURN over TLS and testing.
Calls run over WebRTC. The federation server only connects participants and hands out settings; audio and video bypass it:
- a direct call goes straight between devices, and through TURN (coturn) when they cannot see each other;
- a group call, voice room or link call goes through the SFU, the federation's media server
(
backend/comon_sfu). The SFU forwards streams without decoding them.
The ready-made stack runs both services and writes their settings itself. Without TURN, devices behind strict NAT do not connect; without the SFU, a group call does not start.
Ports
| Port | Protocol | Service |
|---|---|---|
| 3478 | TCP and UDP | TURN |
| 49160–49200 | UDP | TURN: relayed traffic |
| 7882 | UDP | SFU: all group call media on one port |
| 5349 | TCP | TURN over TLS, if enabled |
Open them in the machine's firewall. If the server is behind a router, forward the same external ports to the server's LAN address without renumbering them. An HTTPS proxy does not carry this traffic.
The SFU's control API (port 7880) is reachable only inside the Docker network. Do not publish it.
Federation server settings
The --call-config option points to a JSON file:
{
"stun_urls": ["stun:chat.example.org:3478"],
"turn_urls": [
"turn:chat.example.org:3478?transport=udp",
"turn:chat.example.org:3478?transport=tcp"
],
"turn_secret_file": "/run/secrets/turn-secret",
"sfu_url": "http://sfu:7880",
"sfu_secret_file": "/run/secrets/sfu-secret"
}| Field | Meaning |
|---|---|
stun_urls, turn_urls | Servers the devices receive. Up to 8 addresses. |
turn_secret_file | coturn's shared secret (static-auth-secret). From it the server issues devices temporary TURN credentials valid for 4 hours. |
sfu_url | The address of the SFU's control API inside the network. |
sfu_secret_file | The secret shared by the server and the SFU. |
Without --call-config devices get neither STUN nor TURN; without sfu_url group calls answer
"not supported".
TURN (coturn)
The ready-made stack writes turnserver.conf with the shared secret, ports 49160–49200 and
external-ip, the public address coturn tells devices. By default it is the address the domain
resolves to.
TURN runs in the SFU's network namespace (network_mode: service:sfu), so devices that come through
TURN can reach the SFU's media. If you recreate the SFU, recreate TURN too.
SFU
| Option | Variable | Default | Meaning |
|---|---|---|---|
-listen | COMON_SFU_LISTEN | :7880 | Control API address, internal network only |
-secret-file | COMON_SFU_SECRET_FILE | required | File with the shared secret |
-udp-port | COMON_SFU_UDP_PORT | 7882 | The single UDP port for all media |
-public-ips | COMON_SFU_PUBLIC_IPS | none | Comma-separated addresses the SFU tells devices |
-log-level | COMON_SFU_LOG_LEVEL | info | debug, info, warn or error |
In the ready-made stack the variables live in sfu.env. The SFU uses neither STUN nor TURN: it has
its own public address. Room state is kept in memory: after an SFU restart, running group calls
reconnect by themselves, spread over up to three seconds.
If UDP 7882 is taken, set another port in COMON_SFU_UDP_PORT in sfu.env and publish the same
one for the sfu service in compose.yaml.
Server behind NAT
external-ipinturnserver.confandCOMON_SFU_PUBLIC_IPSinsfu.envmust name the public IPv4 reachable from the internet. If the domain resolves to a private address inside your network, enter the public one by hand.- When the public address changes, update both values and recreate
sfuandturn. - Devices on the same network as the server reach the public address only if the router can
send such traffic back inside (hairpin NAT). Many home routers cannot, and then group calls from
the home network go only through TURN or not at all. Add the server's LAN address to
COMON_SFU_PUBLIC_IPSafter a comma (<public>,<local>): the SFU offers both, and a device at home takes the one it can reach.
TURN over TLS
Some browsers and networks let only TLS out. They need turns:. Get a certificate for the
federation's domain (PEM: chain and key) and run:
python3 tools/mvp-stack.py enable-turn-tls \
--turn-tls-cert /path/fullchain.pem --turn-tls-key /path/privkey.pem
python3 tools/mvp-stack.py upThe command copies the files to turn-tls/ in the state, turns on TLS in coturn on port 5349 (or
--turn-tls-port) and adds turns:<domain>:<port>?transport=tcp to calls.json. The plain 3478
ports stay.
coturn reads the certificate only at start: after renewing it, run enable-turn-tls with the new
files and restart turn. Caddy's certificate lives in its storage; you can export it or issue a
separate one.
Port 443 gets through the strictest networks, but the proxy already holds it. That needs a separate IP for coturn or a separate TURN name that the proxy passes through by SNI without terminating. The ready-made stack does not set that up.
Testing
Test from outside your network, from a phone on a mobile network: running containers and an open TCP port do not prove that UDP gets through.
- A direct call between a phone on a mobile network and a computer on another network.
- A group call with three participants, including a phone on the server's home Wi-Fi.
- If
turns:is on, a call from a browser on a network where UDP is blocked.
The server writes every call event to its log on a calls line: call start and end with a reason
(cause=), participants joining and leaving (reason=), SFU commands and their errors.
Limits
| What | How many |
|---|---|
| Group call participants | 32 |
| Ringing timeout | 45 seconds |
| Return after a drop | 20 seconds |
| Calls at once per person | 8 |
| TURN credentials | 4 hours |
| Call links per person | 50 |
| Link call guests across the federation | 1024 |
Link calls and guests are described in Features; guests can be allowed or forbidden in the federation settings.