Easy signaling for connecting WebRTC peers
🚧 Currently a work in progress! 🚧
As of the current implementation, Easypeers-signal connects all peers together with a partial mesh.
It uses a gossip protocol to relay messages from peer A to peer Z, using a ratio of known peers. Through that, broadcast messages reach all peers, but reduce network load. Direct messaging is then also possible through the gossip protocol.
Clone this repo, then:
npm install
docker build -t easypeers-signal .
docker run -p 80:3000 -p 443:3000 easypeers-signal
npm start
Browse to http://localhost:3000 in multiple tabs
Browse to http://localhost:80 in multiple tabs
From developer tools, send broadcast messages with:
es.send("your message")
Send direct messages with:
es.send("<peer address>", "your message")
import { EasypeersSignal } from "./index.js"
const es = new EasypeersSignal()
es.on('message', (message) => {
console.log('Got message: ', message)
})
es.send('message')
es.send('< peer adddress >', message)
let opts = {
maxPeers: 6, // maximum number of peer connections per peer
fanout: 0.4, // ratio of peers per maxPeers to gossip to
iceConfig: { 'iceServers': [{ 'urls': 'stun:stun.l.google.com:19302' }] },
wsServer: 'ws://localhost:8080', // the websocket server peers connect to for WebRTC signaling
// Low-level configuration options
_GOSSIP_LIFETIME: 60 * 1000, // TTL for messages
debug: false // enable/disable logging
}
Send a broadcast message
Send a direct message
Emit a custom event
Note: this does not emit the event through the swarm. It emits it to the peer that sends it.
Return a list of peers the current peer is connected to
Listen for new events
Listen for an event only once
Remove a listenter for an event
Listens for the given peer's address once Easypeers-signal is initialized
Listens for newly connected peers and returns the peer address
Listens for new direct or broadcast messages from peers
Listeens for newly disconnected peer addresses