🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

webrtc-connection

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webrtc-connection

Provides a tool to create pool of WebRTC peer connections using different types of signaling.

3.0.0
latest
Source
npm
Version published
Weekly downloads
11
Maintainers
1
Weekly downloads
 
Created
Source

WebRTC connection

Provides a tool to create pool of WebRTC peer connections using different types of signaling.

Installation

npm install webrtc-connection

Signaling

WebSockets signaling

const signaling = new SocketIoSignaling('https://signaler.local:8881', 'abc');
await signaling.prepare();
const connectionsPool = new WebRtcConnectionsPool();
const connection = connectionsPool.connect(signaling);
connection.addOnOpenCallback(() => {
    // A peer has been connected
});

connectionsPool.sendMessage('Hi!');

Manual signaling

const signaling = new ManualSignaling();
const connectionsPool = new WebRtcConnectionsPool();
const connection = connectionsPool.connect(signaling);
connection.addOnOpenCallback(() => {
    // A peer has been connected
});

signaling.bindOnOutgoingDataCallback((message) => {
    // Send this signaling message manually to any other user
});

// Apply a signaling message which was received from another user
signaling.applyRemoteResponse(remoteMessage);

connectionsPool.sendMessage('Hi!');

Local signaling

Connects several peers on the same page from the same browser

const signaling = new LocalSignaling();
const connectionsPool = new WebRtcConnectionsPool();
connectionsPool.connect(signaling);
signaling.initiate(2); // 2 - connections number
connectionsPool.sendMessage('Hi!');

Using pool

Send to all connected peers

const connectionsPool = new WebRtcConnectionsPool();
connectionsPool.sendMessage('Hi!')

Receive messages

const connectionsPool = new WebRtcConnectionsPool();
connectionsPool.addOnMessageCallback((message, peerId) => {
    // console.log(message)
})

License

The MIT License

Keywords

WebRTC

FAQs

Package last updated on 27 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts