Skip to content

Replace wrtc and node-pre-gyp with node-datachannel/polyfill#8352

Merged
pubkey merged 5 commits intomasterfrom
copilot/replace-wrtc-module
Apr 14, 2026
Merged

Replace wrtc and node-pre-gyp with node-datachannel/polyfill#8352
pubkey merged 5 commits intomasterfrom
copilot/replace-wrtc-module

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

Summary

The wrtc npm package (v0.4.7) is known to cause many problems (build failures, compatibility issues, unmaintained). This PR removes it entirely and replaces all its usages with node-datachannel/polyfill, which was already a devDependency and is the recommended WebRTC polyfill for Node.js. The node-pre-gyp devDependency, which was only needed for wrtc's native compilation, is also removed.

Because node-datachannel/polyfill's RTCSessionDescription has a read-only sdp property that simple-peer tries to mutate, this PR also adds a createSimplePeerWrtc() wrapper function that returns plain objects from createOffer()/createAnswer() to ensure compatibility.

Changes

  • package.json: Removed wrtc and node-pre-gyp from devDependencies
  • src/plugins/replication-webrtc/connection-handler-simple-peer.ts: Added createSimplePeerWrtc() exported helper that wraps RTCPeerConnection to return plain { type, sdp } objects from createOffer()/createAnswer(), making them compatible with simple-peer
  • test/replication-google-drive.test.ts: Replaced require('wrtc') with node-datachannel/polyfill wrapped via createSimplePeerWrtc()
  • test/replication-microsoft-onedrive.test.ts: Same replacement as above
  • test/unit/replication-webrtc.test.ts: Same replacement as above
  • docs-src/docs/replication-webrtc.md: Updated Node.js polyfill examples to use createSimplePeerWrtc()
  • docs-src/docs/replication-google-drive.md: Updated polyfill example to use createSimplePeerWrtc()
  • docs-src/docs/replication-microsoft-onedrive.md: Same documentation update
  • docs-src/docs/articles/firestore-alternative.md: Updated code example with createSimplePeerWrtc() import and usage
  • docs-src/docs/articles/firebase-realtime-database-alternative.md: Same documentation update

Validation

  • npm run lint passes
  • npm run check-types passes (pre-existing errors only, unrelated to this change)
  • npm run build succeeds
  • npm run test:fast:memory passes (1324 tests)

Remove the problematic 'wrtc' npm package from devDependencies and update
test files (replication-google-drive.test.ts, replication-microsoft-onedrive.test.ts)
to use 'node-datachannel/polyfill' instead. Update documentation to remove
references to the 'wrtc' package alternative.

Agent-Logs-Url: https://github.com/pubkey/rxdb/sessions/7cd4ebe2-2f70-485d-8dda-45031c40d59e

Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com>
@pubkey
Copy link
Copy Markdown
Owner

pubkey commented Apr 13, 2026

@copilot
this fails the google drive tests:

WebRTC signaling

peer error: TypeError: Cannot set property sdp of # which has only a getter
at /home/runner/work/rxdb/rxdb/node_modules/simple-peer/index.js:614:19 {
code: 'ERR_CREATE_OFFER'
}
✔ should emit signaling data
✔ should not throw (57ms)
1) two clients should now about each other

Copilot AI and others added 2 commits April 13, 2026 13:46
Add createSimplePeerWrtc() wrapper that returns plain objects from
createOffer/createAnswer to work around read-only RTCSessionDescription.sdp
in node-datachannel/polyfill. Update all test files and docs.

Agent-Logs-Url: https://github.com/pubkey/rxdb/sessions/8be19412-10ed-4561-ae1a-2e055060d6d2

Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 13, 2026

@copilot
this fails the google drive tests:

...

Fixed in 472d523. The root cause was that node-datachannel/polyfill's RTCSessionDescription has a getter-only sdp property (no setter), but simple-peer tries to mutate offer.sdp after createOffer().

Added a createSimplePeerWrtc() helper that wraps RTCPeerConnection to return plain objects from createOffer()/createAnswer(), making the sdp property mutable. All test files and docs have been updated to use this wrapper.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • stun.l.google.com
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node node -e const Peer = require(&#39;simple-peer&#39;); const wrtc = require(&#39;node-datachannel/polyfill&#39;); console.log(&#39;wrtc has RTCPeerConnection:&#39;, typeof wrtc.RTCPeerConnection); console.log(&#39;wrtc has RTCSessionDescription:&#39;, typeof wrtc.RTCSessionDescription); console. (dns block)
    • Triggering command: `/opt/hostedtoolcache/node/24.14.1/x64/bin/node node -e
      const Peer = require('simple-peer');
      const ndc = require('node-datachannel/polyfill');

const Orig = ndc.RTCPeerConnection;
class Wrapped extends Orig {
createOffer(...args) {
return super.createOffer(...args).then(o => ({ type: o.type, sdp:` (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@pubkey
Copy link
Copy Markdown
Owner

pubkey commented Apr 13, 2026

@copilot ci fails

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 13, 2026

@copilot ci fails

Fixed in 8e2f386. The CI failure was a code block line length check: a comment in docs-src/docs/replication-webrtc.md:150 was 93 chars, exceeding the 86-char limit. Shortened the comment and split the function call across lines.

@pubkey
Copy link
Copy Markdown
Owner

pubkey commented Apr 13, 2026

@copilot can we also remove the node-gyp depedency if we no longer use wrtc?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 13, 2026

@copilot can we also remove the node-gyp depedency if we no longer use wrtc?

node-gyp is not a direct dependency — it's a transitive dep via firebase-tools -> superstatic -> re2. However, node-pre-gyp (v0.17.0) was a direct devDependency that was only needed for wrtc. Removed it in cf8a0a0.

Copilot AI changed the title Replace wrtc with node-datachannel/polyfill Replace wrtc and node-pre-gyp with node-datachannel/polyfill Apr 13, 2026
@pubkey pubkey marked this pull request as ready for review April 14, 2026 05:43
@pubkey pubkey merged commit b7c638f into master Apr 14, 2026
23 of 24 checks passed
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