Skip to content

feat(transport): WebRTC DataChannel pubsub via Cloudflare Realtime SFU#2048

Draft
spomichter wants to merge 1 commit into
mainfrom
feat/webrtc-transport
Draft

feat(transport): WebRTC DataChannel pubsub via Cloudflare Realtime SFU#2048
spomichter wants to merge 1 commit into
mainfrom
feat/webrtc-transport

Conversation

@spomichter
Copy link
Copy Markdown
Contributor

Problem

DimOS has LCM, SHM, DDS, and ROS transports for local/LAN communication but no transport for internet-scale real-time data (NAT traversal, global edge routing). The hosted teleop system currently requires a dedicated HostedTeleopModule to bridge WebRTC DataChannels to DimOS streams — adding unnecessary complexity.

Solution

Add a WebRTC DataChannel transport backed by Cloudflare Realtime SFU, following the same pubsub abstraction as LCMTransport and SHMTransport.

Architecture

  • CloudflareSession — manages two CF SFU sessions (pub + sub) on a dedicated background asyncio thread. Per-topic DataChannel pairs created lazily. Thread-safe.
  • WebRTCPubSub — thin pubsub facade (same interface as LCM, BytesSharedMemory)
  • WebRTCTransport — DimOS Transport[T] implementation

Benchmark Results (us-east-2 EC2 → CF edge)

Metric Value
Median RTT 2.0ms
Throughput @ 64B 10,004 msgs/s (0% loss)
Throughput @ 1KB 7,422 msgs/s (0% loss)

Breaking Changes

None — new optional transport. Requires pip install dimos[webrtc] for aiortc.

How to Test

cd /home/ubuntu/dimos && git checkout feat/webrtc-transport
source .venv/bin/activate && pip install -e '.[webrtc]'
export CF_TELEOP_APP_ID=<your-cf-app-id>
export CF_TELEOP_APP_SECRET=<your-cf-app-secret>

# Unit tests (7 tests, ~12s)
CI=1 python -m pytest dimos/protocol/pubsub/impl/test_webrtcpubsub.py -v

# Benchmark (throughput + latency)
CI=1 python -m pytest dimos/protocol/pubsub/benchmark/test_benchmark.py -m tool -v -k Webrtc

Contributor License Agreement

  • I have read and approved the CLA

…e SFU

Implements a new pubsub transport backed by WebRTC DataChannels over
Cloudflare's Realtime SFU. Two new classes in
dimos/protocol/pubsub/impl/webrtcpubsub.py:

- CloudflareSession: manages the WebRTC PeerConnection lifecycle.
  Opens two CF sessions (publisher + subscriber) so a single process
  can do loopback pubsub. Runs aiortc on a dedicated background
  asyncio thread with its own ThreadPoolExecutor (so we don't leak
  asyncio_N worker threads). Uses negotiated=True placeholder DCs
  with id=100 during transport establishment to avoid stream-id
  collisions with CF-assigned ids.

- WebRTCPubSub: bytes-on-the-wire pubsub facade matching the
  LCMPubSubBase / BytesSharedMemory interface (string topics, bytes
  payloads). Lazily creates pub/sub DataChannel pairs on first
  publish/subscribe per topic.

Also adds:
- WebRTCTransport in dimos/core/transport.py (mirrors LCMTransport
  pattern, no encoding - bytes only).
- WebRTC benchmark testcase in
  dimos/protocol/pubsub/benchmark/testdata.py, gated on aiortc +
  CF_TELEOP_APP_ID / CF_TELEOP_APP_SECRET env vars.
- Integration test in
  dimos/protocol/pubsub/impl/test_webrtcpubsub.py covering basic
  pub/sub, latency, and throughput (all live tests skip without CF
  credentials).
- aiortc + httpx as new 'webrtc' optional extra in pyproject.toml.

Live benchmark (us-east-2 -> CF edge):
- 64-256B:  ~10K msgs/s, 0% loss
- 1KiB:     ~7K msgs/s, 0% loss
- >= 64KiB: dropped (above SCTP message size)
- Median single-RTT: ~2.5 ms
@spomichter spomichter force-pushed the feat/webrtc-transport branch from e56fd1f to 212450b Compare May 11, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant