Skip to content

clkao/hybrid-swarm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Finds peers using webrtc and node.js connections.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%