项目作者: Dletta

项目描述 :
Library to Mesh webRTC clients
高级语言: JavaScript
项目地址: git://github.com/Dletta/webrtc-mesh.git
创建时间: 2020-11-08T04:06:54Z
项目社区:https://github.com/Dletta/webrtc-mesh

开源协议:

下载


webrtc-mesh

BETA Release API in the work, Subject to Change

What does it do??

Prerequisite Disclaimer

WebRTC allows direct communication between RTC capable Peers (usually browser to browser), thanks to the modern Robinhood Style of
Coding (aka take from the geniuses and give to the masses) we can make node talk to webRTC peers. (Shoutout to my dependency contributors @theturtle32, @markandrus and @modeswitch)

The sauce

Using your websocket signaling server (echo server to all connected peers for sdp exchange) do automagically connect all clients running this lib with a network of datachannels

API - Beta

Initialize

  1. const Mesh = require('webrtc-mesh').Mesh;
  2. var config = {
  3. url: 'wss:websocket.url.server:port/',
  4. key: 'appKey or Token for message filtering', //optional, default is 'mesh'
  5. debug: false, //optional, default is false
  6. }
  7. var mesh = Mesh(config);
  8. mesh.pipe( (ev) => { //handle incoming data
  9. console.log('we got some data from another peer', ev.data)
  10. });
  11. mesh.sendToAll( arrayBuffer(12) ) // or even just 'string of Json'

Initialize as Stream

  1. var Mesh = require('webrtc-mesh').Mesh;
  2. var config = {
  3. url: 'wss:websocket.url.server:port/',
  4. key: 'appKey or Token for message filtering', //optional, default is 'mesh'
  5. debug: false, //optional, default is false
  6. }
  7. var mesh = Mesh(config)
  8. var meshedStream = mesh.getStream();
  9. mesh.pipe(meshedStream.push.bind(meshedStream));
  10. process.stdin.pipe(meshedStream).pipe(process.stdout);

Utilities

  1. mesh.getPeerList() // returns a map of connected Peers with KEY: peerID Value: object with {status:connectionStatus, conn:reference to Peer Connection, channel: reference to data channel}
  2. mesh.getPeer(peerId) // returns a specific peer from the map
  3. mesh.getPeerId() //return your peerId
  4. mesh.printPeers() // console print for quick check against connection status
  5. mesh.sendToAll(buffer || blob || string) //send to all peers
  6. mesh.onNewPeer( function ) // register a function to receive the 'onOpen' event of a new data channel