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

0.20.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 v16 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 v16) + + +

(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.20.0267latest

Version History

VersionDownloads (Last 7 Days)Published
0.20.0267
0.20.0-alpha.270
0.20.0-alpha.110
0.12.03,437
0.11.04,556
0.10.13,076
0.10.06
0.9.22,948
0.9.1282
0.9.07
0.8.0471
0.7.022
0.6.090
0.5.5598
0.5.47
0.5.3299
0.5.227
0.5.13
0.5.03
0.5.0-dev117
0.4.311,720
0.4.216
0.4.16
0.4.049
0.3.690
0.3.50
0.3.42
0.3.30
0.3.20
0.3.10
0.3.00
0.2.40
0.2.30
0.2.20
0.2.10
0.2.01
0.1.141
0.1.14-dev0
0.1.137
0.1.128
0.1.117
0.1.107
0.1.97
0.1.87
0.1.77
0.1.67
0.1.57
0.1.47
0.1.3-dev7
0.1.37
0.1.27
0.1.17
0.1.07
0.0.28-dev7
0.0.277
0.0.267
0.0.257
0.0.247
0.0.237
0.0.217
0.0.208
0.0.198
0.0.187
0.0.170
0.0.168
0.0.150
0.0.147
0.0.117
0.0.90
0.0.80
0.0.78
0.0.60

Package Sidebar

Install

npm i node-datachannel

Weekly Downloads

23,191

Version

0.20.0

License

MPL 2.0

Unpacked Size

584 kB

Total Files

145

Last publish

Collaborators

  • murat-dogan