hybrid-swarm

1.2.0 • Public • Published

hybrid-swarm

Finds peers using client-side browser webrtc connections and node.js.

Usage

var hybrid = require('hybrid-swarm')
 
 
// see npmjs.org/webrtc-swarm
var signalhub = 'https://signalhub.mafintosh.com'
 
// see npmjs.org/discovery-swarm
var discovery = { ... }
 
var swarm = hybrid({
  signalhub: signalhub,
  discovery: discovery
})
 
swarm.on('connection', function (conn) {
  if (conn.type === 'webrtc-swarm') {
    console.log('connected to webrtc-swarm')
  }
  if (conn.type === 'discovery-swarm') {
    console.log('connected to discovery swarm')
  }
  console.log(swarm.hybrid.connections, 'total connections')
})

API

HybridSwarm(opts)

Takes options for signalhub and discovery. See example for more information.

HybridSwarm.connections

The number of total connections.

HybridSwarm._connection(conn, opts)

Called when the swarm has found a new connection (or peer).

Arguments:

  • conn: connection object
  • opts: contains metadata, such as the module/connection type: 'webrtc-swarm' or 'discovery-swarm'
HybridSwarm._listening()

Called when the node swarm is listening.

Example

Used in

Package Sidebar

Install

npm i hybrid-swarm

Weekly Downloads

3

Version

1.2.0

License

BSD-2-Clause

Last publish

Collaborators

  • clkao
  • juliangruber
  • karissa
  • laurengarcia
  • mafintosh
  • maxogden