Skip to main content

A WebRTC voice review with TURN and video cost gates

WebRTC avoids carrying media through the Java API, but browsers still need connectivity, NAT traversal, and sometimes relay infrastructure. An example service therefore keeps the text room as the source of truth and tre…

5 viewsAbout 3 min read
Table of contents

WebRTC avoids carrying media through the Java API, but browsers still need connectivity, NAT traversal, and sometimes relay infrastructure. An example service therefore keeps the text room as the source of truth and treats voice review as an opt-in P2P supplement.

A connection flow led by the cost gate

Check capability

The server returns enablement and session limits.

Block cost

When disabled, do not request permission, signal, or gather ICE.

Try P2P

Only an enabled audio-only session attempts a direct connection.

Fall back to TURN

Use an approved relay only after direct failure and measure traffic.

Why the default matters

With WEBRTC_VOICE_ENABLED=false, /api/rooms/{roomId}/voice/config returns enabled=false, videoEnabled=false, and disabledReason=cost_guard. The client checks this before requesting a microphone, opening WebSocket signaling, or gathering ICE candidates. ICE servers and TURN credentials are empty by default and are emitted only when all required values are explicitly configured.

Even when voice is enabled, the contract is audio-only, capped at eight participants and a 30-minute session by default. Signaling limits payload size, SDP/ICE length, and messages per minute; SDP and ICE are not stored or logged. Video, SFU, MCU, and coturn remain closed until cost approval and relay-traffic measurement exist.

Evidence from five perspectives

  • Product: name the owner of the monthly fixed cost, relay GB, and peak concurrent-session budget.
  • Design: show the lock reason and “text remains available” before requesting permission.
  • Engineering: validate the room and anonymous identity at handshake and expose only an ephemeral peer ID.
  • User: permission denial, NAT failure, and expiry must not lose text history.
  • Operations: inspect enabled/TURN state, session cap, and relay ratio before changing environment values.

The current default deployment has no fixed media service and opens no media sessions. When TURN is introduced, do not add coturn to the default Compose stack; inject an external TURN service only after cost approval, traffic measurement, and rollback criteria are in place.

Cost approval table

Item Default Measure before enabling Stop condition
P2P audio OFF Concurrent sessions and duration Session cap exceeded
TURN relay Unconfigured Relay ratio and cost per GB Monthly traffic budget exceeded
Video OFF Bitrate × peers × duration Always blocked without approval
SFU/MCU Not deployed Instance and egress fixed cost No cost owner
monthly relay cost ≈ sessions × seconds × bitrate × relay ratio × price per GB

Even a peer-to-peer path can fall back to TURN, so “P2P is free” is not a budget. With no measurements, use OFF rather than an optimistic zero-cost assumption.

Related course: Close gRPC and WebRTC boundaries with cost guards

Terms in this content

More in backend

All in this category →

Was this article helpful?