Registry / http-networking / wrtc
library0.0.0.dev9jsnpmunverified

wrtc provides a standards-compliant WebRTC implementation for Node.js, currently binding to WebRTC M81 (as of v0.4.7). This library leverages N-API (since v0.4.0) to ensure ABI stability across various Node.js releases, significantly enhancing compatibility and reducing issues often associated with native addons and Node.js version updates. The project prioritizes spec-compliance, validating its API behavior against the W3C's web-platform-tests project, making it a reliable choice for server-side WebRTC applications. Releases generally align with new WebRTC M-milestones and Node.js version support, indicating an active and well-maintained project cadence. It differentiates itself by offering a direct, low-level WebRTC API within the Node.js runtime, enabling scenarios like media processing, signaling servers, and peer-to-peer connections outside of a browser environment, and also includes nonstandard APIs for testing purposes. The current stable version is 0.4.7, continuously updated for Node.js compatibility and WebRTC feature parity.

npm install wrtc
INSTALL
IMPORT
SIG · WRTC
W
wrtc
http-networkingjavascriptv0.0.0.dev9
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RTCPeerConnection
✓ import { RTCPeerConnection } from 'wrtc';
✗ const RTCPeerConnection = require('wrtc').RTCPeerConnection;
While CommonJS `require('wrtc')` is possible, direct named imports are preferred in modern Node.js and TypeScript for clarity. Alternatively, `const wrtc = require('wrtc'); const pc = new wrtc.RTCPeerConnection();` is also common.
RTCSessionDescription
✓ import { RTCSessionDescription } from 'wrtc';
✗ const SessionDescription = require('wrtc/sdp').RTCSessionDescription;
WebRTC classes like RTCSessionDescription are exposed directly from the main 'wrtc' package, mirroring browser global availability, not from sub-paths.
RTCICECandidate
✓ import { RTCICECandidate } from 'wrtc';
✗ import { IceCandidate } from 'wrtc';
Ensure correct capitalization and full name as per WebRTC API specification.

Demonstrates setting up two RTCPeerConnections locally in Node.js, exchanging SDP offer/answer, ICE candidates, and establishing a basic RTCDataChannel for message exchange.

import { RTCPeerConnection } from 'wrtc'; async function createPeerConnectionDemo() { const pc1 = new RTCPeerConnection(); const pc2 = new RTCPeerConnection(); // Exchange ICE candidates pc1.onicecandidate = e => { if (e.candidate) { console.log('PC1 ICE Candidate:', e.candidate.candidate); pc2.addIceCandidate(e.candidate).catch(err => console.error('Error adding ICE candidate to PC2:', err)); } }; pc2.onicecandidate = e => { if (e.candidate) { console.log('PC2 ICE Candidate:', e.candidate.candidate); pc1.addIceCandidate(e.candidate).catch(err => console.error('Error adding ICE candidate to PC1:', err)); } }; // Log connection state changes pc1.onconnectionstatechange = () => console.log('PC1 connection state:', pc1.connectionState); pc2.onconnectionstatechange = () => console.log('PC2 connection state:', pc2.connectionState); // Setup DataChannel communication const dc1 = pc1.createDataChannel('chat'); dc1.onopen = () => console.log('PC1 DataChannel open!'); dc1.onmessage = e => console.log('PC1 received:', e.data); dc1.onclose = () => console.log('PC1 DataChannel closed.'); pc2.ondatachannel = e => { const dc2 = e.channel; console.log('PC2 received DataChannel:', dc2.label); dc2.onopen = () => console.log('PC2 DataChannel open!'); dc2.onmessage = e => console.log('PC2 received:', e.data); dc2.onclose = () => console.log('PC2 DataChannel closed.'); dc2.send('Hello from PC2: Initial message!'); }; try { // Create offer from PC1 const offer = await pc1.createOffer(); await pc1.setLocalDescription(offer); console.log('PC1 Local Description (Offer) set.'); // Set offer on PC2 and create answer await pc2.setRemoteDescription(pc1.localDescription); console.log('PC2 Remote Description (Offer) set.'); const answer = await pc2.createAnswer(); await pc2.setLocalDescription(answer); console.log('PC2 Local Description (Answer) set.'); // Set answer on PC1 await pc1.setRemoteDescription(pc2.localDescription); console.log('PC1 Remote Description (Answer) set.'); console.log('Offer/Answer exchange complete. Waiting for ICE candidates and DataChannel open...'); // Send a message from PC1 after channels are likely open setTimeout(() => { if (dc1.readyState === 'open') { dc1.send('Hello from PC1: How are you?'); } else { console.warn('PC1 DataChannel not yet open to send message.'); } }, 5000); } catch (error) { console.error('WebRTC setup failed:', error); } } createPeerConnectionDemo();
Debug
Known issues
breakingWith the update from WebRTC M79 to M81 in `wrtc` v0.4.5, the `dtx`, `ptime`, and `codecPayloadType` parameters to `RTCRtpEncodingParameters` no longer take effect. They have been removed from the WebRTC 1.0 specification and are now ignored.
fix
Remove `dtx`, `ptime`, and `codecPayloadType` from `RTCRtpEncodingParameters` objects. Consult the latest WebRTC 1.0 specification for current valid parameters.
affects: >=0.4.5
gotchaInstalling `wrtc` requires prebuilt binaries or building from source. Incorrect `TARGET_ARCH` environment variable or an unsupported Node.js/Electron version can lead to installation failures or runtime errors due to missing or incompatible binaries.
fix
Ensure your Node.js and Electron versions are within the supported ranges listed in the documentation. For ARM architectures (e.g., Raspberry Pi), set `TARGET_ARCH` to 'arm' or 'arm64' before running `npm install wrtc`. If issues persist, refer to the 'build from source' guide.
affects: >=0.4.0
breaking`wrtc` v0.4.0 transitioned to N-API and dropped support for older Node.js and Electron versions (specifically Node versions earlier than 8.11.2, 10.0.0 and Electron versions earlier than 4).
fix
Upgrade your Node.js environment to a supported version (e.g., Node.js ^8.11.2 || >=10.0.0, up to 14 as of 0.4.7) or use an older version of the `wrtc` package compatible with your environment.
affects: >=0.4.0
gotchaMemory leaks have been reported and fixed in specific scenarios, such as when receiving strings over `RTCDataChannel` in v0.4.0 and earlier. While fixes are applied, large-scale or long-running `RTCDataChannel` usage should be monitored for memory consumption.
fix
Ensure you are using `wrtc` version 0.4.1 or newer to benefit from memory leak fixes related to `RTCDataChannel` string reception. Always test high-volume scenarios carefully.
affects: <0.4.1
Errors
Common errors & fixes
Error: Cannot find module 'wrtc'
The `wrtc` package is not installed, or Node.js cannot locate the module.
fix
Run `npm install wrtc` in your project directory. Verify your `NODE_PATH` environment variable if you're using a non-standard module resolution setup.
Error: Prebuilt binary not found for wrtc@0.4.7 on [platform]-[arch]
There is no prebuilt binary available for your specific operating system, architecture, or Node.js version combination, or the `TARGET_ARCH` was set incorrectly.
fix
Check the `wrtc` documentation for supported platforms and Node.js versions. If using an ARM device, ensure you set `TARGET_ARCH=arm` or `TARGET_ARCH=arm64` before `npm install wrtc`. If a prebuilt binary isn't available, you may need to compile `wrtc` from source (`npm install wrtc --build-from-source`).
TypeError: RTCPeerConnection is not a constructor
The `RTCPeerConnection` class was not correctly imported or accessed from the `wrtc` module.
fix
Ensure you are importing `RTCPeerConnection` correctly: `import { RTCPeerConnection } from 'wrtc';` for ESM, or `const { RTCPeerConnection } = require('wrtc');` for CommonJS. If you imported the whole module as an object, access it like `new wrtc.RTCPeerConnection()`.
Upgrade
Version history
0.0.0.dev9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
38 hits · last 30 days
node
34
OpenAI (training)
1
Resources
wrtc — npm install wrtc · libregistry