Docs

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

PortProtocolService
3478TCP and UDPTURN
49160–49200UDPTURN: relayed traffic
7882UDPSFU: all group call media on one port
5349TCPTURN 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"
}
FieldMeaning
stun_urls, turn_urlsServers the devices receive. Up to 8 addresses.
turn_secret_filecoturn's shared secret (static-auth-secret). From it the server issues devices temporary TURN credentials valid for 4 hours.
sfu_urlThe address of the SFU's control API inside the network.
sfu_secret_fileThe 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

OptionVariableDefaultMeaning
-listenCOMON_SFU_LISTEN:7880Control API address, internal network only
-secret-fileCOMON_SFU_SECRET_FILErequiredFile with the shared secret
-udp-portCOMON_SFU_UDP_PORT7882The single UDP port for all media
-public-ipsCOMON_SFU_PUBLIC_IPSnoneComma-separated addresses the SFU tells devices
-log-levelCOMON_SFU_LOG_LEVELinfodebug, 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-ip in turnserver.conf and COMON_SFU_PUBLIC_IPS in sfu.env must 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 sfu and turn.
  • 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_IPS after 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 up

The 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.

  1. A direct call between a phone on a mobile network and a computer on another network.
  2. A group call with three participants, including a phone on the server's home Wi-Fi.
  3. 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

WhatHow many
Group call participants32
Ringing timeout45 seconds
Return after a drop20 seconds
Calls at once per person8
TURN credentials4 hours
Call links per person50
Link call guests across the federation1024

Link calls and guests are described in Features; guests can be allowed or forbidden in the federation settings.

On this page