Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-datachannel

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-datachannel - npm Package Compare versions

Comparing version 0.1.14 to 0.2.0

examples/media/main.html

11

CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0091 NEW)
project(node_datachannel VERSION 0.1.14)
project(node_datachannel VERSION 0.2.0)

@@ -30,6 +30,6 @@ include_directories(${CMAKE_JS_INC})

GIT_REPOSITORY https://github.com/paullouisageneau/libdatachannel.git
GIT_TAG "v0.16.0"
GIT_TAG "v0.16.2"
)
option(NO_MEDIA "Disable media transport support in libdatachannel" ON)
option(NO_MEDIA "Disable media transport support in libdatachannel" OFF)
option(NO_WEBSOCKET "Disable WebSocket support in libdatachannel" ON)

@@ -46,2 +46,7 @@

src/rtc-wrapper.cpp
src/media-direction.cpp
src/media-rtcpreceivingsession-wrapper.cpp
src/media-track-wrapper.cpp
src/media-audio-wrapper.cpp
src/media-video-wrapper.cpp
src/data-channel-wrapper.cpp

@@ -48,0 +53,0 @@ src/peer-connection-wrapper.cpp

@@ -8,3 +8,3 @@ # Examples

## How to Use?
### How to Use?
* Prepare Project

@@ -22,2 +22,24 @@ * cd examples/client-server

> You can also use [libdatachannel/examples/client](https://github.com/paullouisageneau/libdatachannel/tree/master/examples) project's client & signaling server
> You can also use [libdatachannel/examples/client](https://github.com/paullouisageneau/libdatachannel/tree/master/examples) project's client & signaling server
## media
### Example Webcam from Browser to Port 5000
This is an example copy/paste demo to send your webcam from your browser and out port 5000 through the demo application.
### How to use
Open main.html in your browser (you must open it either as HTTPS or as a domain of http://localhost).
Start the application and copy it's offer into the text box of the web page.
Copy the answer of the webpage back into the application.
You will now see RTP traffic on `localhost:5000` of the computer that the application is running on.
Use the following gstreamer demo pipeline to display the traffic
(you might need to wave your hand in front of your camera to force an I-frame).
```
$ gst-launch-1.0 udpsrc address=127.0.0.1 port=5000 caps="application/x-rtp" ! queue ! rtph264depay ! video/x-h264,stream-format=byte-stream ! queue ! avdec_h264 ! queue ! autovideosink
```

@@ -60,3 +60,5 @@ export as namespace NodeDataChannel;

Offer = 'Offer',
Answer = 'Answer'
Answer = 'Answer',
Pranswer = 'Pranswer',
Rollback = 'Rollback'
}

@@ -91,2 +93,90 @@

// Must be same as rtc enum class Direction
export enum Direction {
SendOnly = 'SendOnly',
RecvOnly = 'RecvOnly',
SendRecv = 'SendRecv',
Inactive = 'Inactive',
Unknown = 'Unknown'
}
export class RtcpReceivingSession {
requestBitrate: (bitRate: Number) => void;
requestKeyframe: () => boolean;
}
export class Audio {
constructor(mid: string, dir: Direction);
addAudioCodec: (payloadType: Number, codec: string, profile?: string) => void;
addOpusCodec: (payloadType: Number, profile?: string) => string;
direction: () => Direction;
generateSdp: (eol: string, addr: string, port: string) => string;
mid: () => string;
setDirection: (dir: Direction) => void;
description: () => string;
removeFormat: (fmt: string) => void;
addSSRC: (ssrc: Number, name?: string, msid?: string, trackID?: string) => void;
removeSSRC: (ssrc: Number) => void;
replaceSSRC: (oldSsrc: Number, ssrc: Number, name?: string, msid?: string, trackID?: string) => void;
hasSSRC: (ssrc: Number) => boolean;
getSSRCs: () => Number[];
getCNameForSsrc: (ssrc: Number) => string;
setBitrate: (bitRate: Number) => void;
getBitrate: () => Number;
hasPayloadType: (payloadType: Number) => boolean;
addRTXCodec: (payloadType: Number, originalPayloadType: Number, clockRate: Number) => void;
addRTPMap: () => void;
parseSdpLine: (line: string) => void;
}
export class Video {
constructor(mid: string, dir: Direction);
addVideoCodec: (payloadType: Number, codec: string, profile?: string) => void;
addH264Codec: (payloadType: Number, profile?: string) => void;
addVP8Codec: (payloadType: Number) => void;
addVP9Codec: (payloadType: Number) => void;
direction: () => Direction;
generateSdp: (eol: string, addr: string, port: string) => string;
mid: () => string;
setDirection: (dir: Direction) => void;
description: () => string;
removeFormat: (fmt: string) => void;
addSSRC: (ssrc: Number, name?: string, msid?: string, trackID?: string) => void;
removeSSRC: (ssrc: Number) => void;
replaceSSRC: (oldSsrc: Number, ssrc: Number, name?: string, msid?: string, trackID?: string) => void;
hasSSRC: (ssrc: Number) => boolean;
getSSRCs: () => Number[];
getCNameForSsrc: (ssrc: Number) => string;
setBitrate: (bitRate: Number) => void;
getBitrate: () => Number;
hasPayloadType: (payloadType: Number) => boolean;
addRTXCodec: (payloadType: Number, originalPayloadType: Number, clockRate: Number) => void;
addRTPMap: () => void;
parseSdpLine: (line: string) => void;
}
export class Track {
direction: () => Direction;
mid: () => string;
close: () => void;
sendMessage: (msg: string) => boolean;
sendMessageBinary: (buffer: Buffer) => boolean;
isOpen: () => boolean;
isClosed: () => boolean;
availableAmount: () => Number;
bufferedAmount: () => Number;
maxMessageSize: () => Number;
setBufferedAmountLowThreshold: (newSize: Number) => void;
requestKeyframe: () => boolean;
setMediaHandler: (handler: RtcpReceivingSession) => void
onOpen: (cb: () => void) => void;
onClosed: (cb: () => void) => void;
onError: (cb: (err: string) => void) => void;
onAvailable: (cb: () => void) => void;
onBufferedAmountLow: (cb: () => void) => void;
onMessage: (cb: (msg: string | Buffer) => void) => void;
}
export class DataChannel {

@@ -113,5 +203,9 @@ close: () => void;

close: () => void;
setLocalDescription: (type: DescriptionType) => void;
setRemoteDescription: (sdp: string, type: DescriptionType) => void;
localDescription: () => { type: string, sdp: string };
addRemoteCandidate: (candidate: string, mid: string) => void;
createDataChannel: (label: string, config?: DataChannelInitConfig) => DataChannel;
addTrack: (media: Video | Audio) => Track;
hasMedia: () => boolean;
onLocalDescription: (cb: (sdp: string, type: DescriptionType) => void) => void;

@@ -122,2 +216,3 @@ onLocalCandidate: (cb: (candidate: string, mid: string) => void) => void;

onDataChannel: (cb: (dc: DataChannel) => void) => void;
onTrack: () => Track;
bytesSent: () => number;

@@ -124,0 +219,0 @@ bytesReceived: () => number;

{
"name": "node-datachannel",
"version": "0.1.14",
"version": "0.2.0",
"description": "libdatachannel node bindings",

@@ -25,3 +25,8 @@ "main": "lib/index.js",

"keywords": [
"libdatachannel"
"libdatachannel",
"webrtc",
"p2p",
"peer-to-peer",
"datachannel",
"data channel"
],

@@ -28,0 +33,0 @@ "contributors": [

@@ -1,12 +0,20 @@

# node-datachannel - libdatachannel node bindings
# Easy to use WebRTC data channels and media transport
![Build CI](https://github.com/murat-dogan/node-datachannel/workflows/Build%20CI/badge.svg)
- Easy to use
- Lightweight
- No need to deal with WebRTC stack!
- Small binary sizes
- Has Prebuilt binaries (Linux,Windows,ARM)
- Type infos for Typescript
> "libdatachannel is a standalone implementation of WebRTC Data Channels, WebRTC Media Transport, and WebSockets in C++17 with C bindings for POSIX platforms (including GNU/Linux, Android, and Apple macOS) and Microsoft Windows. It enables direct connectivity between native applications and web browsers without the pain of importing the entire WebRTC stack. "
NodeJS bindings for [libdatachannel](https://github.com/paullouisageneau/libdatachannel) library.
This project is NodeJS bindings for [libdatachannel](https://github.com/paullouisageneau/libdatachannel) library.
Please check [libdatachannel](https://github.com/paullouisageneau/libdatachannel) for Compatibility & WebRTC details.
## Examples
## Example Usage
```js

@@ -18,42 +26,8 @@ const nodeDataChannel = require('node-datachannel');

// SCTP Settings ( use of nodeDataChannel.setSctpSettings() )
// export interface SctpSettings {
// recvBufferSize?: number;
// sendBufferSize?: number;
// maxChunksOnQueue?: number;
// initialCongestionWindow?: number;
// congestionControlModule?: number;
// delayedSackTime?: number;
// }
let dc1 = null;
let dc2 = null;
// Config options
// export interface RtcConfig {
// iceServers: string[];
// proxyServer?: ProxyServer;
// enableIceTcp?: boolean;
// portRangeBegin?: number;
// portRangeEnd?: number;
// maxMessageSize?: number;
// iceTransportPolicy?: TransportPolicy;
// }
// "iceServers" option is an array of stun/turn server urls
// Examples;
// STUN Server Example : stun:stun.l.google.com:19302
// TURN Server Example : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
// TURN Server Example (TCP) : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT?transport=tcp
// TURN Server Example (TLS) : turns:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
let peer1 = new nodeDataChannel.PeerConnection("Peer1", { iceServers: ["stun:stun.l.google.com:19302"] });
// Set Callbacks
peer1.onStateChange((state) => {
console.log("Peer1 State:", state);
});
peer1.onGatheringStateChange((state) => {
console.log("Peer1 GatheringState:", state);
});
peer1.onLocalDescription((sdp, type) => {

@@ -71,8 +45,2 @@ console.log("Peer1 SDP:", sdp, " Type:", type);

// Set Callbacks
peer2.onStateChange((state) => {
console.log("Peer2 State:", state);
});
peer2.onGatheringStateChange((state) => {
console.log("Peer2 GatheringState:", state);
});
peer2.onLocalDescription((sdp, type) => {

@@ -95,23 +63,8 @@ console.log("Peer2 SDP:", sdp, " Type:", type);

// DataChannel Options
// export interface DataChannelInitConfig {
// protocol?: string;
// negotiated?: boolean;
// id?: number;
// ordered?: boolean;
// maxPacketLifeTime?: number;
// maxRetransmits?: number;
//
// // Deprecated, use ordered, maxPacketLifeTime, and maxRetransmits
// reliability?: {
// type?: ReliabilityType;
// unordered?: boolean;
// rexmit?: number;
// }
// }
dc1 = peer1.createDataChannel("test");
dc1.onOpen(() => {
dc1.sendMessage("Hello from Peer1");
// Binary message: Use sendMessageBinary(Buffer)
});
dc1.onMessage((msg) => {

@@ -126,9 +79,8 @@ console.log('Peer1 Received Msg:', msg);

peer2.close();
dc1 = null;
dc2 = null;
peer1 = null;
peer2 = null;
nodeDataChannel.cleanup();
}, 10 * 1000);
```
> Please check examples/media folder for media usage example
## Install

@@ -145,2 +97,208 @@

## API
### PeerConnection Class
**Constructor**
let pc = new PeerConnection(peerName[,options])
- peerName `<string>` Peer name to use for logs etc..
- options `<Object>` WebRTC Config Options
```
export interface RtcConfig {
iceServers: (string | IceServer)[];
proxyServer?: ProxyServer;
enableIceTcp?: boolean;
portRangeBegin?: number;
portRangeEnd?: number;
maxMessageSize?: number;
iceTransportPolicy?: TransportPolicy;
}
export const enum RelayType {
TurnUdp = 'TurnUdp',
TurnTcp = 'TurnTcp',
TurnTls = 'TurnTls'
}
export interface IceServer {
hostname: string;
port: Number;
username?: string;
password?: string;
relayType?: RelayType;
}
export type TransportPolicy = 'all' | 'relay';
"iceServers" option is an array of stun/turn server urls
Examples;
STUN Server Example : stun:stun.l.google.com:19302
TURN Server Example : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
TURN Server Example (TCP) : turn:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT?transport=tcp
TURN Server Example (TLS) : turns:USERNAME:PASSWORD@TURN_IP_OR_ADDRESS:PORT
```
**close: () => void**
Close Peer Connection
**setRemoteDescription: (sdp: string, type: DescriptionType) => void**
Set Remote Description
```
export const enum DescriptionType {
Unspec = 'Unspec',
Offer = 'Offer',
Answer = 'Answer'
}
```
**addRemoteCandidate: (candidate: string, mid: string) => void**
Add remote candidate info
**createDataChannel: (label: string, config?: DataChannelInitConfig) => DataChannel**
Create new data-channel
* label `<string>` Data channel name
* config `<Object>` Data channel options
```
export interface DataChannelInitConfig {
protocol?: string;
negotiated?: boolean;
id?: number;
ordered?: boolean;
maxPacketLifeTime?: number;
maxRetransmits?: number;
// Deprecated, use ordered, maxPacketLifeTime, and maxRetransmits
reliability?: {
type?: ReliabilityType;
unordered?: boolean;
rexmit?: number;
}
}
export const enum ReliabilityType {
Reliable = 0, Rexmit = 1, Timed = 2
}
```
**onLocalDescription: (cb: (sdp: string, type: DescriptionType) => void) => void**
Local Description Callback
```
export const enum DescriptionType {
Unspec = 'Unspec',
Offer = 'Offer',
Answer = 'Answer'
}
```
**onLocalCandidate: (cb: (candidate: string, mid: string) => void) => void**
Local Candidate Callback
**onStateChange: (cb: (state: string) => void) => void**
State Change Callback
**onGatheringStateChange: (state: (sdp: string) => void) => void**
Gathering State Change Callback
**onDataChannel: (cb: (dc: DataChannel) => void) => void**
New Data Channel Callback
**bytesSent: () => number**
Get bytes sent stat
**bytesReceived: () => number**
Get bytes received stat
**rtt: () => number**
Get rtt stat
**getSelectedCandidatePair: () => { local: SelectedCandidateInfo, remote: SelectedCandidateInfo }**
Get info about selected candidate pair
```
export interface SelectedCandidateInfo {
address: string;
port: number;
type: string;
transportType: string;
}
```
### DataChannel Class
> You can create a new Datachannel instance by calling `PeerConnection.createDataChannel` function.
**close: () => void**
Close data channel
**getLabel: () => string**
Get label of data-channel
**sendMessage: (msg: string) => boolean**
Send Message as string
**sendMessageBinary: (buffer: Buffer) => boolean**
Send Message as binary
**isOpen: () => boolean**
Query data-channel
**availableAmount: () => Number**
Get available data amount
**bufferedAmount: () => Number**
Get current buffered amount level
**maxMessageSize: () => Number**
Get max message size of the data-channel, that could be sent
**setBufferedAmountLowThreshold: (newSize: Number) => void**
Set buffer level of the `onBufferedAmountLow` callback
**onOpen: (cb: () => void) => void**
Open callback
**onClosed: (cb: () => void) => void**
Closed callback
**onError: (cb: (err: string) => void) => void**
Error callback
**onAvailable: (cb: () => void) => void**
Available callback
**onBufferedAmountLow: (cb: () => void) => void**
Buffer level low callback
**onMessage: (cb: (msg: string | Buffer) => void) => void**
New Message callback
## Build

@@ -147,0 +305,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc