discovery-swarm for webrtc
This module provides a "similar" API to discovery-swarm but for WebRTC connections.
It has a few differences to discovery-swarm:
- It needs a signaling server. We give you one.
- It uses mmst to minimize the connections. Check the example.
join
andleave
only accepts Buffers.leave
andclose
accepts a callback argument or returns a Promise.
$ npm install @geut/discovery-swarm-webrtc
You can run your own signal server by running:
$ discovery-swarm-webrtc --port=4000
- wss://geut-webrtc-signal-v3.glitch.me
- wss://geut-webrtc-signal-v3.herokuapp.com
const crypto = require('crypto')
const swarm = require('@geut/discovery-swarm-webrtc')
const sw = swarm({
bootstrap: ['ws://localhost:4000']
})
const topic = crypto.createHash('sha256')
.update('my-discovery-swarm-topic')
.digest()
sw.join(topic)
sw.on('connection', peer => {
// connected
})
Creates a new Swarm.
opts
include:
{
id: crypto.randomBytes(32), // peer-id for user
bootstrap: [string], // urls to your websocket endpoints
stream: (info) => stream, // stream to replicate across peers
simplePeer: {}, // options for the simplePeer instances,
maxPeers: 5, // max connections by peer
timeout: 15 * 1000, // defines the time to wait to establish a connection
}
Join a specific channel. We use behind it simple-signal
+ simple-peer
.
Leave from specific channel. Destroy all the connections and leave the channel.
Close the entire swarm. Destroy all the connections and disconnect from the signal.
Returns the list of connected peers for a specific channel.
Channel is optional
, if you don't pass it you get the entire list of peers.
Connect directly to a specific peer.
Emitted when you've connected to a peer and are now initializing the connection's session. Info is an object that contains information about the connection.
info
include:
{
id: Buffer // the remote peer's peer-id.
channel: Buffer // the channel this connection was initiated on.
initiator: Boolean // whether we initiated the connection or someone else did
}
Emitted when you have fully connected to another peer. Info is an object that contains info about the connection.
Emitted when you've disconnected from a peer. Info is an object that contains info about the connection.
Emitted when you left a channel.
Emitted when the swarm was closed.
Emitted when the candidates peer for a specific channel was updated. candidates
is an array of Buffer id.
🐛 If you found an issue we encourage you to report it on github. Please specify your OS and the actions to reproduce it.
👥 Ideas and contributions to the project are welcome. You must follow this guideline.
MIT © A GEUT project