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

@geut/discovery-swarm-webrtc

v4.3.1

Published

discovery-swarm for WebRTC.

Downloads

229

Readme

discovery-swarm-webrtc

Build Status JavaScript Style Guide

discovery-swarm for webrtc

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-swarm-webrtc --port=4000

Public Servers

  • wss://geut-webrtc-signal-v3.glitch.me
  • wss://geut-webrtc-signal-v3.herokuapp.com

Deploy to Heroku

Deploy

Client

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

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

const topic = crypto.createHash('sha256')
  .update('my-discovery-swarm-topic')
  .digest()

sw.join(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 websocket endpoints
  stream: (info) => stream, // stream to replicate across peers
  simplePeer: {}, // options for the simplePeer instances,
  maxPeers: 5, // max connections by peer
  timeout: 15 * 1000, // defines the time to wait to establish a connection
}

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 connected peers for a specific channel.

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

sw.connect(channel: Buffer, peerId: Buffer) -> Promise<SimplePeer>

Connect directly to a specific peer.

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-updated', 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

License

MIT © A GEUT project