Create and use WebRTC data channels with configurable reliability and ordering

domain: developer.mozilla.org · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. After creating an RTCPeerConnection, call createDataChannel('label', options) on the offering peer before generating an offer; options can include ordered: false for unordered delivery and maxRetransmits: 0 for fully unreliable (useful for game state), or leave defaults for reliable ordered delivery.
  2. The answering peer listens for the RTCPeerConnection 'datachannel' event to receive the remote channel; do not call createDataChannel on the answering side for the same label.
  3. Wait for the channel's 'open' event before sending data; sending before the channel opens silently discards messages in some implementations.
  4. Send binary data (ArrayBuffer or Blob) for efficiency; strings are valid but incur UTF-8 encoding overhead. Keep individual messages below the SCTP PMTU to avoid fragmentation — a common safe size is under 16 KB.
  5. For large transfers, implement your own chunking: break the payload into chunks, send them sequentially, and reassemble on the receiver using a sequence number you include in each chunk.
  6. To negotiate a data channel out-of-band (avoiding the SDP renegotiation for the channel itself), set negotiated: true and id: <same integer on both sides> in the options on both peers before connecting.

Known gotchas

Related routes

choose between WebTransport and WebRTC data channels for realtime browser-to-server data
w3.org · 5 steps · unrated
Enable WebRTC simulcast with VP8 spatial layers in a browser sender using RTCRtpSendParameters
developer.mozilla.org · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans