Miss any of our Open RFC calls?Watch the recordings here! »

webrtc-connection

3.0.0 • Public • Published

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

Install

npm i webrtc-connection

DownloadsWeekly Downloads

2

Version

3.0.0

License

MIT

Unpacked Size

29.7 kB

Total Files

23

Last publish

Collaborators

  • avatar