npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webrtc-tree-overlay

v1.0.13

Published

Dynamically maintain a tree overlay with WebRTC

Downloads

20

Readme

Build Status

webrtc-tree-overlay

Dynamically maintain a tree overlay topology from nodes connected by WebRTC as they join and leave. Each node accepts a maximum number of new connections after which the newer connection requests are delegated to children.

Requires a publicly accessible server for bootstrapping the connections, provided by webrtc-bootstrap-server.

Usage

// On the root node

var bootstrap = require('webrtc-bootstrap')('server hostname or ip:port')
var Node = require('webrtc-tree-overlay')

var root = new Node(bootstrap).becomeRoot('secret')
root.on('child-connect', function (channel) {
  channel.send('ping')        
  channel.on('data', function (data) {
    console.log(data)
  })
})


// On a child node

var boostrap = ...
var Node = ...

var node = new Node(bootstrap).join()
node.on('parent-connect', function (channel) {
  channel.on('data', function (data) {
    console.log(data)
    channel.send('pong')      
  })
})
node.on('child-connect', function (channel) {
  channel.send('ping')        
})

API

Node(bootstrap, [opts])

bootstrap is a webrtc-bootstrap connected client.

opts has the following defaults:

{ peerOpts: {}, maxDegree: 10, requestTimeoutInMs: 30 * 1000 }

where

  • opts.peerOpts are options passed to SimplePeer
  • opts.maxDegree is the maximum number of children a node will keep
  • opts.requestTimeoutInMs the upper bound on the time a candidate will be considered for joining. If the connection handshake has not been successfully before the end of the interval, the candidate is rejected.

Node.children

The current dictionary of children channels.

Node.childrenNb

The current number of children.

Node.maxDegree

The maximum number of children and candidates that are kept. If a join request arrives while it will either be passed to one of the children, or kept until one a candidate has become a connected child.

Node.parent

The parent channel, null if the node has not joined yet or is the root.

Node.becomeRoot(secret)

Become root (through the bootstrap client), after which the node will automatically handle join requests.

Node.join()

Join an existing tree (through the bootstrap client).

Node.close()

Close the node and all associated channels.

Node.on('data', function (data, channel, isParent))

  • data received from of the direct neighbours, either parent or children;
  • channel: on which it was received;
  • isParent whether the channel is from our parent (true) or one of our children (false).

Node.on('parent-connect', function (channel))

When the node is ready to communicate with its parent through channel.

Node.on('parent-close', function (channel))

When the parent channel has closed.

Node.on('parent-error', function (channel, err))

When the parent channel has failed become of an error err.

Node.on('child-connect', function (channel))

When the node is ready to communicate with new child through channel.

Node.on('child-close', function (channel))

When the child channel has closed.

Node.on('child-error', function (channel, err))

When then child channel has failed because of err.

Channel

Abstracts the underlying WebRTC channel to multiplex the tree join protocol with application-level messages. Lightweight messages can be sent on the topology on those channels. However, for any heavy data traffic a dedicated SimplePeer connection should be established. The channel can be used for that purpose.

The constructor is called internally by a Node during the joining process and it is not available publicly.

Channel.id

Identifier of the channel, different from the Node.id on either side. From the point of view of a child, the id of its parent is always null. From the point of view of a parent, each child has a non-null unique id.

Channel.destroy()

Closes the channel.

Channel.isParent()

Return true if the channel is used to communicate with the Node's parent.

Channel.send(data)

Sends data to the neighbour (parent or child) through the channel.

Channel.on('close', function ())

Fires when the channel has closed.

Channel.on('data', function (data))

Fires when data has arrived.

Channel.on('error', function (err))

Fires an error aborted the channel.

Channel.on('join-request', function (req))

Used internally. Fires when a join request has arrived. An application should not need to bother with those.