Route page and signaling traffic through Cloudflare Tunnel while sending WebRTC media over direct UDP, with optional TURN REST as a fallback. When WebRTC was already offered and then fails, stay in the current session, automatically resume compatibility audio, and keep a Reconnect WebRTC control. A reconnect retries WebRTC only, leaves compatibility running until it succeeds, and stays on compatibility if it fails again. Database schema 14 adds nullable voice override columns and is a one-way boundary: older binaries reject this database. This change is for review, not a production rollout.
3.2 KiB
Cloudflare Tunnel for WebSpeak
Cloudflare Tunnel publishes the WebSpeak HTTPS/WSS entry without opening a
public inbound port. It does not carry WebRTC media UDP, and it does not
make the gateway's 40000–40099/UDP range reachable.
Setup
-
Create a tunnel in the Cloudflare dashboard and copy its UUID and credentials JSON.
-
Copy
config.yml.exampletoconfig.ymland replace the UUID and hostname. Rename the downloaded credentials file toREPLACE_WITH_TUNNEL_UUID.json, or update the credentials path and Compose mount to match its actual name. Pointserviceat the WebSpeak HTTP listener (3040by default). -
Run cloudflared on the host (recommended on Windows/macOS):
cloudflared tunnel --config config.yml runOn Linux,
docker compose up -din this directory can run it in host mode. -
In WebSpeak administration, set Public media address to the gateway's public IP (for example
192.0.2.10), not the Cloudflare hostname. Allow40000–40099/UDPon the host firewall and security group. -
Keep
WEBSPEAK_VOICE_ICE_TRANSPORT_POLICY=allso browsers try direct UDP first.WEBSPEAK_VOICE_PROFILE=autois the default: requests from a trusted Cloudflare hop use the adaptive audio path, while other requests keep the legacy path. The default trusted proxy list contains loopback only; if cloudflared connects from another address, add that IP/CIDR toWEBSPEAK_TRUSTED_PROXIES. Headers injected by a direct untrusted client are ignored. Configure TURN only as the fallback for mobile networks or UDP-blocked clients; seedeploy/coturn. -
Opus over WebSocket is opt-in. It requires an adaptive profile and either the Admin → Voice setting or
WEBSPEAK_VOICE_OPUS_WS=1; without it the browser uses PCM.
Why not use the Cloudflare hostname as the media address?
A Cloudflare-proxied hostname resolves to Cloudflare edge addresses. Those
edges do not forward the gateway's UDP media ports, so using them as ICE
candidates produces a path that looks configured but cannot carry audio.
WebSpeak therefore no longer infers the request Host as an ICE address when
the request arrives through a trusted Cloudflare hop and no media host was
configured. Without a public media address or TURN, the server reports
NO_MEDIA_PATH and, because WebRTC was not advertised, the browser uses the
compatibility transport. If an advertised WebRTC connection later fails, the
browser stays in the session with WEBRTC_FAILED and offers WebRTC reconnect;
it does not silently switch to compatibility transport.
Verify
curl -I https://voice.example.comsucceeds through the tunnel.chrome://webrtc-internalsshows host/srflx candidates to the public IP and, when UDP is available, a direct selected pair.- If the selected pair is
relay, confirm TURN is reachable and that direct UDP is actually blocked; do not switch the global policy torelayjust because the page is behind a Tunnel.
For the full voice rollout and rollback notes, see
docs/CLOUDFLARE_TUNNEL_VOICE.md.
This template has not been exercised end-to-end with a live coturn/Tunnel deployment. Browser Opus fallback, especially on Safari and Firefox, also requires device testing.