0.8.0 • Published 12 days ago

node-datachannel v0.8.0

Weekly downloads
298
License
MPL 2.0
Repository
github
Last release
12 days ago

Easy to use WebRTC data channels and media transport

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

  • Easy to use
  • Lightweight
    • No need to deal with WebRTC stack!
    • Small binary sizes
  • Type infos for Typescript

This project is NodeJS bindings for libdatachannel library.

Please check libdatachannel for Compatibility & WebRTC details.

Install

npm install node-datachannel

Supported Platforms

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

Linux-x64Linux-armv7Linux-arm64(1)Windows-x86Windows-x64Mac (M1 + x64)
Node V16++++++
Node V17++++++
Node V18++++++
Node V19++++++
Node V20++++++
  1. Please note that; For Linux-arm64 platform we need OpenSSL to be installed locally.

Electron

node-datachannel supports Electron.

Please check electron demo

Example Usage

import nodeDataChannel from 'node-datachannel';

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

let dc1 = null;
let dc2 = null;

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

// Set Callbacks
peer1.onLocalDescription((sdp, type) => {
    console.log('Peer1 SDP:', sdp, ' Type:', type);
    peer2.setRemoteDescription(sdp, type);
});
peer1.onLocalCandidate((candidate, mid) => {
    console.log('Peer1 Candidate:', candidate);
    peer2.addRemoteCandidate(candidate, mid);
});

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

// Set Callbacks
peer2.onLocalDescription((sdp, type) => {
    console.log('Peer2 SDP:', sdp, ' Type:', type);
    peer1.setRemoteDescription(sdp, type);
});
peer2.onLocalCandidate((candidate, mid) => {
    console.log('Peer2 Candidate:', candidate);
    peer1.addRemoteCandidate(candidate, mid);
});
peer2.onDataChannel((dc) => {
    console.log('Peer2 Got DataChannel: ', dc.getLabel());
    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);
});

setTimeout(() => {
    dc1.close();
    dc2.close();
    peer1.close();
    peer2.close();
    nodeDataChannel.cleanup();
}, 10 * 1000);

WebRTC Polyfills

Please check here

Test

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

Build

Please check here

Examples

Please check examples folder

API Docs

Please check docs page

Thanks

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

0.8.0

12 days ago

0.7.0

21 days ago

0.6.0

1 month ago

0.5.5

2 months ago

0.5.4

2 months ago

0.5.3

5 months ago

0.5.0

7 months ago

0.5.2

5 months ago

0.5.1

6 months ago

0.5.0-dev

8 months ago

0.4.3

10 months ago

0.4.2

1 year ago

0.4.1

1 year ago

0.4.0

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.4

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.14-dev

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.3-dev

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.28-dev

3 years ago

0.0.26

3 years ago

0.0.27

3 years ago

0.0.25

3 years ago

0.0.24

3 years ago

0.0.23

3 years ago

0.0.21

3 years ago

0.0.20

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.11

3 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago