TURN (Traversal Using Relays around NAT) relays media when peers cannot connect directly, for example across restrictive firewalls or NAT. Configure the relay once on the signaling server to advertise defaults to browser pages and compatible WebRTC 2.0 C# applications.
Current signaling image
Use the latest WebRTC 2.0 signaling server release and its TURN configuration guide. The image contains signaling, browser pages, and sample authorization. Run the TURN relay as a separate service.
1. Configure the separate TURN service
Deploy a TURN service such as Coturn, or use the Medialooks TURN server image. Configure its public hostname or IPv4 address, relay user and password, listening port, and media relay port range. Allow the listening and configured relay ports through the firewall. A relay behind NAT also needs its public address configured correctly.
For the Medialooks TURN image, set USERNAME, PASSWORD, and REMOTE_IP in that service's Compose configuration before starting it. These are settings of the TURN service; the signaling server advertises the matching client settings in the next step.
2. Set TURN_SERVERS in the signaling project's .env file
Use the relay credentials and address from step 1:
TURN_SERVERS='turn_user@replace_with_turn_password:turn.example.com:3478'
The format is username@password:hostname:port. Use an ASCII DNS hostname or IPv4 address with an explicit port from 1 to 65535. This setting describes a UDP TURN endpoint; clients construct turn:hostname:port from it. URI prefixes, IPv6 addresses, transport queries, and turns: endpoints are not supported by this shared setting.
Usernames and passwords must contain printable ASCII characters without whitespace or any of : @ ; / \ ? #. Dedicated credentials using letters, digits, -, _, +, and = fit the format and these single-quoted .env examples without additional escaping.
For more than one relay, separate complete entries with semicolons:
TURN_SERVERS='turn_user@replace_with_turn_password:turn.example.com:3478;backup_user@replace_with_backup_password:backup.example.com:3478'
Keep any existing WEBRTC_IMAGE or HTTPS settings in the same file. An empty or unset TURN_SERVERS keeps the existing connection behavior. Invalid entries stop the container at startup with a configuration error.
3. Apply the configuration and reconnect clients
From the signaling source directory, recreate the service with the updated environment:
docker compose up -d
For the supplied direct-TLS configuration, use:
docker compose -f compose.yaml -f docker/compose.tls.yaml up -d
Reload browser pages and reconnect C# applications so new peer connections receive the updated settings. Use HTTPS for browser capture outside localhost and for native receivers, as described in HTTPS deployment.
Browser and C# configuration
The signaling server advertises the configured string as server_metadata.turn_server during connection setup. Browser pages apply it to their ICE configuration. Native WebRTC 2.0 peers use it when an explicit application or peer setting has not already supplied a TURN server. This covers browser publishers, viewers, Web Guests, and compatible C# receivers.
For MConnect, the selection order is the object's turn_server, a peer-provided turn_server, then the signaling default. Registry defaults for MConnect are loaded from HKEY_CURRENT_USER\Software\Medialooks\MConnect. Applications using the MWebRTC compatibility API with WebRTC 2.0 enabled load HKEY_CURRENT_USER\Software\Medialooks\WebRTC instead. Explicit native or peer TURN configuration takes precedence over the server default; check the registry path and object properties used by your application's API if a previous override appears to hide a server change.
Adding TURN supplies a fallback for media connectivity; direct connections remain available. To verify relay use, inspect the selected ICE candidate pair in the receiving client's WebRTC diagnostics and confirm it uses a relay candidate.
TURN usernames and passwords are sent to connected clients so they can authenticate to the relay. Use dedicated relay credentials, keep the signaling .env file out of source control, and apply the access rules required by your application.
Legacy multi-service signaling bundle
The production.json instructions below apply to the older multi-service signaling package. For the current single-image package, use TURN_SERVERS above. Its runtime configuration is generated at startup.
TURN Server setup
The default TURN server is defined in the signaling server's configuration file:
\signaling2.0\config\production.jsonbefore starting the TURN image, you have to change the TURN server configuration via docker-compose.yml file
Specify the TURN user, password, and your current TURN server public IP address.
docker-compose.yml
- USERNAME=Your_user
- PASSWORD=Your_password
- REMOTE_IP=Your_current_server_public_ipSignaling server TURN configuration
In the legacy multi-service signaling bundle, edit signaling2.0/signaling2.0/config/production.json and set metadata.turn_server to a string. Separate multiple complete server entries with semicolons:
"turn_server": "user1@password1:your_turn_server1:3478;user2@password2:your_turn_server2:3478"For example:
signaling2.0/signaling2.0/config/production.json
{
"isDev": false,
"server": {
"port": 8888,
"secure": false,
"key": "config/sslcerts/key.pem",
"cert": "config/sslcerts/cert.pem",
"password": null,
"pingTimeout": 10000,
"pingInterval": 4800,
"loglevel": 1
},
"metadata": {
"turn_server": "turnUser@turnPassword:turnservername:3478",
"special_rooms": {
"gateways": { "name": "VTGateways", "role": "gateway" },
"auth": { "name": "Auth", "role": "auth" }
}
},
"auth": {
"vt_auth_user": "default",
"vt_auth_pass": "default"
}
}
The format should follow this pattern: username@password:ip:port
STUN Server Implicitly Included
When you specify a TURN server, you do not need to define a separate STUN server. The specified TURN server will automatically serve as both a STUN and TURN server, as this is standard behavior for TURN infrastructure.
Overriding the TURN Server via SDK
If a TURN server is defined through IMFProps or registry settings, this configuration will override the value set in the signaling serverproduction.json
TURN Server Propagation to Web Clients
When a TURN server is configured in the signalling server's production.json, it is automatically sent to all web clients during the signalling handshake. Web-based applications that connect via the public API endpoint will receive the TURN configuration from the signalling server and apply it as part of their ICE candidate gathering process.
This behaviour ensures that all TURN/STUN settings are consistent and do not require hardcoding in your web client code.
TURN Server Docker Image
Medialooks provides a Docker-based TURN server image for your convenience.
Turn server WebRTC 2.0 docker image download
Build and run the TURN docker image
docker compose build
docker compose up -dOnce deployed, you can reference this TURN server in your production.json as described earlier.
Still have questions?
Tell us what didn’t work or what you’d like clarified.