πΉVideo Calls
This guide will help you set up Cloudflare's TURN service for dynamic video call relay functionality in your phone resource.
This guide will help you set up Cloudflare's TURN service for dynamic video call relay functionality in your phone resource.
What is Cloudflare TURN?
Cloudflare TURN (Traversal Using Relays around NAT) is a service that helps establish reliable video call connections between players, especially when direct peer-to-peer connections are blocked by firewalls or NAT configurations.
Benefits:
β Free tier: 1,000 GB of data per month
β Globally distributed servers for low latency
β Dynamic credentials for enhanced security
β Automatic credential management
Prerequisites
A Cloudflare account (free tier is sufficient)
Access to your FiveM server configuration files
Step-by-Step Setup
Step 1: Create Cloudflare Account
Visit cloudflare.com and sign up for a free account
Complete the account verification process
Step 2: Generate TURN Credentials
Log in to your Cloudflare dashboard
Navigate to Realtime β TURN Server(Search in the search bar for "TURN Server")
Click Create to generate a new TURN key
Copy the following credentials:
Turn Token ID (a long string)
API Token (another long string)
β οΈ Important: Keep these credentials secure and never share them publicly.
Step 3: Configure Server Credentials
Open server/apiKeys.lua and locate the RTCRelaySecrets section:
RTCRelaySecrets = {
token = GetConvar("yseriesRTCRelayToken", nil), -- Turn Token ID from Cloudflare
apiKey = GetConvar("yseriesRTCRelayApiKey", nil) -- API Token from Cloudflare
}Option A: Using Convars (Recommended)
Add these lines to your server.cfg:
set yseriesRTCRelayToken "YOUR_TURN_TOKEN_ID_HERE"
set yseriesRTCRelayApiKey "YOUR_API_TOKEN_HERE"Option B: Direct Configuration
Replace nil with your credentials directly in apiKeys.lua:
RTCRelaySecrets = {
token = "YOUR_TURN_TOKEN_ID_HERE",
apiKey = "YOUR_API_TOKEN_HERE"
}Step 4: Enable RTC Relay
Open config/config.upload.lua and add the following configuration:
Config.RTCRelay = {}
Config.RTCRelay.Enabled = true -- Enable dynamic RTC relay
Config.RTCRelay.Provider = "cloudflare" -- Currently only "cloudflare" is supported
Config.RTCRelay.StripStun = false -- Keep STUN servers (recommended)
Config.RTCRelay.CredentialTTL = 86400 -- Credential lifetime in seconds (24 hours)Step 5: Restart Server
Save all configuration files
Restart your FiveM server
Check server console for confirmation message:
RTC Relay enabled, using Cloudflare as the provider.
Configuration Options
Enabled
boolean
false
Enable/disable dynamic RTC relay
Provider
string
"cloudflare"
TURN service provider (currently only Cloudflare)
StripStun
boolean
false
Remove STUN servers when using relay (not recommended)
CredentialTTL
number
86400
Credential lifetime in seconds (max: 86400 = 24 hours)
How It Works
When a player initiates a video call, the system requests fresh TURN credentials from Cloudflare
Credentials are generated with a configurable expiration time (default: 24 hours)
These credentials are used to establish the WebRTC connection
When the call ends or player disconnects, credentials are automatically revoked
If Cloudflare is unavailable, the system falls back to static TURN servers
Troubleshooting
Video Calls Not Working
Check 1: Verify Configuration
Ensure
Config.RTCRelay.Enabled = trueinconfig.misc.luaVerify credentials are set correctly in
server/apiKeys.lua
Check 2: Server Console
Look for error messages about missing credentials
Check for Cloudflare API errors (status codes other than 201)
Check 3: Credentials
Verify your Turn Token ID and API Token are correct
Ensure they haven't expired or been revoked in Cloudflare dashboard
Common Error Messages
"RTC Relay is enabled but credentials are missing"
Solution: Add your credentials to
server/apiKeys.luaor set convars inserver.cfg
"Failed to get RTC relay credentials from Cloudflare. Status: 401"
Solution: Your API Token is incorrect or expired. Generate a new one in Cloudflare dashboard.
"Failed to get RTC relay credentials from Cloudflare. Status: 404"
Solution: Your Turn Token ID is incorrect. Check it in Cloudflare dashboard.
Fallback Behavior
If Cloudflare TURN is unavailable or disabled, the system automatically uses the default TURN servers(this is unreliable and it will cause issues like black screen, frozen video calls, etc.). Video calls will still work, but may have reduced reliability in restrictive network environments.
Monitoring Usage
Log in to Cloudflare dashboard
Navigate to Realtime β TURN Server
View usage statistics and monitor data consumption
Free tier includes 1,000 GB per month; additional usage costs $0.05 per GB
Security Best Practices
β Never commit credentials to version control
β Use convars in
server.cfginstead of hardcoding in filesβ Rotate credentials periodically
β Monitor usage for unusual activity
β Keep Cloudflare account secure with 2FA enabled
Additional Resources
Support
If you encounter issues not covered in this guide:
Check server console logs for detailed error messages
Enable
Config.DebugPrint = truefor additional debugging informationVerify your Cloudflare account status and TURN key validity
Last updated