@geut/discovery-swarm-webrtc
discovery-swarm for WebRTC.
Last updated 7 months ago by tinchoz49 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @geut/discovery-swarm-webrtc 
SYNC missed versions from official npm registry.

discovery-swarm-webrtc

Build Status JavaScript Style Guide

discovery-swarm for webrtc

force-graph

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 and leave only accepts Buffers.
  • leave and close accepts a callback argument or returns a Promise.

Install

$ npm install @geut/discovery-swarm-webrtc

Usage

Server

You can run your own signal server by running:

$ discovery-signal-webrtc --port=4000

Public Servers

Deploy to Heroku

Deploy

Client

const swarm = require('@geut/discovery-swarm-webrtc')

const sw = swarm({
  bootstrap: ['localhost:4000']
})

sw.join(Buffer.from('some-topic'))

sw.on('connection', peer => {
  // connected
})

API

const sw = swarm(opts)

Creates a new Swarm.

opts include:

{
  id: crypto.randomBytes(32), // peer-id for user
  bootstrap: [string], // urls to your socket.io endpoints
  stream: (info) => stream, // stream to replicate across peers
  simplePeer: {}, // options for the simplePeer instances,
  maxPeers: 4, // max connections by peer
  connectionTimeout: 10 * 1000, // defines the time to wait to establish a connection,
  requestTimeout: 5 * 1000 // defines the time to wait for the result of a request to the server
}

sw.join(Buffer)

Join a specific channel. We use behind it simple-signal + simple-peer.

const promise = sw.leave(Buffer)

Leave from specific channel. Destroy all the connections and leave the channel.

const promise = sw.close([callback])

Close the entire swarm. Destroy all the connections and disconnect from the signal.

const arrayOfPeers = sw.getPeers([channel])

Returns the list of peers for a specific channel.

Channel is optional, if you don't pass it you get the entire list of peers.

Events

sw.on('handshaking', function(connection, info) { ... })

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
}

sw.on('connection', function(connection, info) { ... })

Emitted when you have fully connected to another peer. Info is an object that contains info about the connection.

sw.on('connection-closed', function(connection, info) { ... })

Emitted when you've disconnected from a peer. Info is an object that contains info about the connection.

sw.on('leave', function(channel) { ... })

Emitted when you left a channel.

sw.on('close', function() { ... })

Emitted when the swarm was closed.

sw.on('candidates', function(channel, candidates) { ... })

Emitted when the candidates peer for a specific channel was updated. candidates is an array of Buffer id.

Issues

:bug: If you found an issue we encourage you to report it on github. Please specify your OS and the actions to reproduce it.

Contributing

:busts_in_silhouette: Ideas and contributions to the project are welcome. You must follow this guideline.

Sponsored By

Wireline

License

MIT © A GEUT project

Current Tags

  • 2.0.0-alpha.19                                ...           alpha (a year ago)
  • 3.0.0-beta.3                                ...           beta (4 months ago)
  • 2.2.7                                ...           latest (7 months ago)

38 Versions

  • 3.0.0-beta.3                                ...           4 months ago
  • 3.0.0-beta.2                                ...           4 months ago
  • 3.0.0-beta.1                                ...           4 months ago
  • 3.0.0-beta.0                                ...           5 months ago
  • 2.2.7                                ...           7 months ago
  • 2.2.6                                ...           7 months ago
  • 2.2.5                                ...           7 months ago
  • 2.2.4                                ...           10 months ago
  • 2.2.3                                ...           a year ago
  • 2.2.2                                ...           a year ago
  • 2.2.1                                ...           a year ago
  • 2.2.0                                ...           a year ago
  • 2.1.1                                ...           a year ago
  • 2.1.0                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 2.0.0-alpha.19                                ...           a year ago
  • 2.0.0-alpha.18                                ...           a year ago
  • 2.0.0-alpha.17                                ...           a year ago
  • 2.0.0-alpha.16                                ...           a year ago
  • 2.0.0-alpha.15                                ...           a year ago
  • 2.0.0-alpha.14                                ...           a year ago
  • 2.0.0-alpha.13                                ...           a year ago
  • 2.0.0-alpha.12                                ...           a year ago
  • 2.0.0-alpha.11                                ...           a year ago
  • 2.0.0-alpha.10                                ...           a year ago
  • 2.0.0-alpha.9                                ...           a year ago
  • 2.0.0-alpha.7                                ...           a year ago
  • 2.0.0-alpha.6                                ...           a year ago
  • 2.0.0-alpha.5                                ...           a year ago
  • 2.0.0-alpha.4                                ...           a year ago
  • 2.0.0-alpha.3                                ...           a year ago
  • 2.0.0-alpha.2                                ...           a year ago
  • 2.0.0-alpha.1                                ...           a year ago
  • 2.0.0-alpha.0                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago

Copyright 2014 - 2016 © taobao.org |