node-datachannel
TypeScript icon, indicating that this package has built-in type declarations

0.27.0 • Public • Published

WebRTC For Node.js and Electron ( with WebSocket)

Linux CI Build Windows CI Build Mac x64 CI Build Mac M1 CI Build

  • Lightweight
    • No need to deal with WebRTC stack!
    • Small binary sizes (~8MB for Linux x64)
  • Type infos for Typescript
  • Integrated WebSocket Client & Server Implementation

This project is Node.js bindings for libdatachannel library.

Install

npm install node-datachannel

Supported Platforms

node-datachannel targets N-API version 8 and supports Node.js v18.20 and above. It is tested on Linux, Windows and MacOS. For N-API compatibility please check here.

Linux [x64,armv7,arm64] (1) Windows [x86,x64] Mac [M1,x64]
N-API v8 (>= Node.js v18) + + +

(1) For Linux musl + libc

Electron

node-datachannel supports Electron.

Please check electron demo

WebRTC Polyfills

WebRTC polyfills to be used for libraries like simple-peer.

Please check here for more

web-platform-tests

Please check actual situation here

WebSocket Client & Server

Integrated WebSocket Client & Server is available, which can be used separately or for signaling.

For an example usage, check here

Example Usage

import nodeDataChannel from 'node-datachannel';

// Log Level
nodeDataChannel.initLogger('Debug');

// Integrated WebSocket available and can be used for signaling etc
// const ws = new nodeDataChannel.WebSocket();

let dc1 = null;
let dc2 = null;

let peer1 = new nodeDataChannel.PeerConnection('Peer1', { iceServers: ['stun:stun.l.google.com:19302'] });

peer1.onLocalDescription((sdp, type) => {
    peer2.setRemoteDescription(sdp, type);
});
peer1.onLocalCandidate((candidate, mid) => {
    peer2.addRemoteCandidate(candidate, mid);
});

let peer2 = new nodeDataChannel.PeerConnection('Peer2', { iceServers: ['stun:stun.l.google.com:19302'] });

peer2.onLocalDescription((sdp, type) => {
    peer1.setRemoteDescription(sdp, type);
});
peer2.onLocalCandidate((candidate, mid) => {
    peer1.addRemoteCandidate(candidate, mid);
});
peer2.onDataChannel((dc) => {
    dc2 = dc;
    dc2.onMessage((msg) => {
        console.log('Peer2 Received Msg:', msg);
    });
    dc2.sendMessage('Hello From Peer2');
});

dc1 = peer1.createDataChannel('test');

dc1.onOpen(() => {
    dc1.sendMessage('Hello from Peer1');
});

dc1.onMessage((msg) => {
    console.log('Peer1 Received Msg:', msg);
});

Examples

Please check examples folder

Test

npm run test                  # Unit tests
node test/connectivity.js     # Connectivity

Build

Please check here

API Docs

Please check docs page

Contributing

Contributions are welcome!

Thanks

Thanks to Streamr for supporting this project by being a Sponsor!

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.27.03,933latest

Version History

VersionDownloads (Last 7 Days)Published
0.27.03,933
0.26.0376
0.25.08,933
0.24.0168
0.23.028
0.22.035
0.21.074
0.20.06
0.20.0-alpha.21
0.20.0-alpha.10
0.12.07,342
0.11.01,955
0.10.1622
0.10.00
0.9.2201
0.9.1215
0.9.00
0.8.0101
0.7.0208
0.6.05
0.5.588
0.5.42
0.5.378
0.5.264
0.5.130
0.5.024
0.5.0-dev5
0.4.33,408
0.4.210
0.4.11
0.4.064
0.3.679
0.3.530
0.3.42
0.3.30
0.3.2204
0.3.10
0.3.00
0.2.438
0.2.30
0.2.21
0.2.1174
0.2.00
0.1.142
0.1.14-dev0
0.1.130
0.1.121
0.1.1113
0.1.10159
0.1.90
0.1.80
0.1.70
0.1.62
0.1.5101
0.1.451
0.1.3-dev1
0.1.34
0.1.22
0.1.10
0.1.00
0.0.28-dev1
0.0.270
0.0.260
0.0.250
0.0.240
0.0.231
0.0.211
0.0.204
0.0.191
0.0.180
0.0.170
0.0.165
0.0.151
0.0.141
0.0.110
0.0.91
0.0.81
0.0.71
0.0.60

Package Sidebar

Install

npm i node-datachannel

Weekly Downloads

28,859

Version

0.27.0

License

MPL 2.0

Unpacked Size

593 kB

Total Files

145

Last publish

Collaborators

  • murat-dogan