Skip to content

feat: evaluate @roamhq/wrtc as alternative to node-datachannel#3356

Open
NiKrause wants to merge 2 commits intolibp2p:mainfrom
NiKrause:feat/evaluate-roamhq-wrtc
Open

feat: evaluate @roamhq/wrtc as alternative to node-datachannel#3356
NiKrause wants to merge 2 commits intolibp2p:mainfrom
NiKrause:feat/evaluate-roamhq-wrtc

Conversation

@NiKrause
Copy link
Copy Markdown

@NiKrause NiKrause commented Nov 20, 2025

This PR evaluates @roamhq/wrtc as a replacement for node-datachannel as requested in #3034.

Implementation

Replaced node-datachannel with two libraries:

  • @roamhq/wrtc for RTCPeerConnection (WebRTC peer connections)
  • stun package for STUN server (WebRTC Direct listener)

Changes

  • Replace node-datachannel RTCPeerConnection with @roamhq/wrtc
  • Implement STUN server using stun package for WebRTC Direct
  • Remove DirectRTCPeerConnection wrapper class
  • Add extractRemoteFingerprint helper for SDP parsing
  • Remove node-datachannel-specific GC workarounds
  • Add TypeScript definitions for stun package

Test Results

  • WebRTC transport functional
  • WebRTC Direct functional
  • Certificate management working
  • SDP manipulation validated

Known Issue

Segmentation fault during test cleanup - Native module crash in @roamhq/wrtc destructor. All tests pass before crash occurs. Does not affect functionality, only test harness cleanup.

Stack trace shows crash in RTCDataChannel::~RefPtr() and RTCPeerConnection::~RTCPeerConnection().

…p#3034)

Replace node-datachannel with @roamhq/wrtc for WebRTC peer connections
and stun package for STUN server functionality in WebRTC Direct.

Changes:
- Replace node-datachannel RTCPeerConnection with @roamhq/wrtc
- Implement STUN server using stun package for WebRTC Direct
- Remove DirectRTCPeerConnection wrapper class
- Add extractRemoteFingerprint helper for SDP parsing
- Remove node-datachannel-specific garbage collection workarounds
- Add TypeScript definitions for stun package

All unit tests pass (33 passing). WebRTC Direct functionality validated.

Relates to libp2p#3034
NiKrause added a commit to NiKrause/test-plans that referenced this pull request Nov 26, 2025
- Added webrtc-roamhq-wrtc implementation variant for performance testing
- Updated runner to support WebRTC Direct multiaddr handling
- Added Hetzner Cloud Terraform configuration as AWS alternative
- Implemented listen address capture via /tmp/webrtc-listen-addrs.txt
- Fixed libp2p v2.10.0 compatibility with exact dependency versions

Performance Results (Hetzner Germany, 1 iteration):
- Upload: WebRTC Direct 194 Mbps vs TCP 840 Mbps
- Download: WebRTC Direct 186 Mbps vs TCP 1,236 Mbps
- Latency: WebRTC Direct 323ms vs TCP 124ms

WebRTC Direct achieves ~186-194 Mbps throughput with @roamhq/wrtc,
demonstrating functional parity with expected WebRTC overhead (~4-6x slower than TCP).

Related: libp2p/js-libp2p#3356, libp2p/js-libp2p#3034, libp2p/js-libp2p#3033
@cristianmadularu
Copy link
Copy Markdown

This is looking very interesting. Any plans on releasing it (maybe as a beta if it is not ready)? I would love to give it a try.
Thanks

@achingbrain
Copy link
Copy Markdown
Member

This is great. One red flag though is that the stun module has several CVEs affecting it. There are PRs open against it that solve some of the issues but the module appears to have been abandoned.

Prior to support for multiple STUN listeners per process being added to libjuice it was used here, but it was ultimately removed largely due to these critical vulnerabilities but also because the functionality was available via node-datachannel.

From what I remember support for UDP multiplexing was also missing so each connection ended up using a different local port in it's ICE candidates during SDP negotiation meaning that hole punching (or UPnP port opening) was required for every inbound/outbound connection rather than everything going via a single port. I haven't looked in detail to see if that is addressed here but if not it needs to be.

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.

3 participants