Skip to content

deps(transport-webrtc): replace node-datachannel#3544

Draft
mertushka wants to merge 1 commit into
libp2p:mainfrom
mertushka:deps/replace-node-datachannel
Draft

deps(transport-webrtc): replace node-datachannel#3544
mertushka wants to merge 1 commit into
libp2p:mainfrom
mertushka:deps/replace-node-datachannel

Conversation

@mertushka

@mertushka mertushka commented Jun 16, 2026

Copy link
Copy Markdown

Description

Replaces node-datachannel with @mertushka/webrtc-node in @libp2p/webrtc.

@mertushka/webrtc-node is a Node.js WebRTC binding that exposes a W3C-compatible WebRTC API surface instead of a package-specific polyfill surface. Version 0.2.0 passes 620 strict Web Platform Tests for WebRTC API behavior and provides the standard objects @libp2p/webrtc already uses in browsers, including RTCPeerConnection, RTCDataChannel, RTCSessionDescription, RTCIceCandidate, RTCCertificate, and standard EventTarget behavior.

This is useful here because the existing Node path had to wrap node-datachannel APIs to inject ICE credentials, map ICE servers, import certificates, work around stale data channel state, and force native peer connection cleanup. With @mertushka/webrtc-node, the Node path can use the standard WebRTC-shaped APIs directly, with explicit nonstandard hooks only where WebRTC Direct needs Node-specific control over ICE credentials, certificate import, UDP muxing, fingerprint verification, and remote fingerprint access.

This removes the node-datachannel-specific compatibility layer and related runtime workarounds now that the replacement exposes the required standard WebRTC APIs plus the nonstandard APIs used by the WebRTC Direct path.

Changes include:

  • replace the node-datachannel dependency with @mertushka/webrtc-node
  • wire the new WebRTC implementation through the Node WebRTC entrypoints
  • keep WebRTC Direct support using nonstandard APIs:
    • configurePeerConnection
    • importCertificate
    • setLocalIceCredentials
    • getRemoteFingerprint
    • IceUdpMuxListener
  • remove node-datachannel-specific peer connection wrappers
  • remove stale readyState/send error workarounds
  • remove node-datachannel GC/closed-state workarounds

Related open PRs

Potentially Fixes/Closes:

Likely requires a rebase:

Verification

  • npm run dep-check -w @libp2p/webrtc
  • npm run build -w @libp2p/webrtc
  • npm run test:node -w @libp2p/webrtc -- --exit
  • npm run test:chrome -w @libp2p/webrtc

@mertushka mertushka requested a review from a team as a code owner June 16, 2026 02:21
@dozyio

dozyio commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

Thanks @mertushka for putting this together. I’m hesitant to merge this right now because the replacement dependency is still very new and hasn’t had much time to prove itself in production or across the ecosystem.

For a core dependency like this, I’d prefer we wait until it has more adoption, a clearer maintenance track record, and some time for early issues to shake out. This isn’t a rejection of the approach, but I don’t think we should take on that risk in js-libp2p yet. Happy to revisit once the dependency has matured a bit.

@mertushka

Copy link
Copy Markdown
Author

@dozyio Thanks for the feedback, that makes sense and I agree with the concern.

I opened this PR mostly to share the idea and start a discussion rather than to push for an immediate merge. The main reasons I explored replacing node-datachannel were performance, stability, and having a more standards-aligned WebRTC API surface. @mertushka/webrtc-node currently passes 620 strict WPT tests, which gave me more confidence in the behavior.

I originally built the module because one of my own projects, haxball.js, had several issues with node-datachannel, and I found node-datachannel difficult to work on or adapt when those issues came up.

That said, I completely understand that js-libp2p needs to be conservative with core dependencies.

I’m happy for this PR to stay as an experiment/reference.

@dozyio

dozyio commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Moving to draft as likely won't be merged in the near term

@dozyio dozyio marked this pull request as draft June 22, 2026 07:01
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.

2 participants