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

beakon

v0.1.1

Published

A decentralized WebRTC signaling service

Downloads

9

Readme

beakon

A decentralized WebRTC signaling service

Features

  • Partial mesh
  • Self healing
  • Gossip protocol
  • Direct messaging

Todo features

  • Message encyryption
  • Topic subscriptions
  • Video/Audio

Local Development

Install

Node

npm install beakon

Example

import Beakon from "./index.js";
import auth from "./pubnub/auth.js";

import wrtc from "wrtc";

const opts = {
  pubnubConfig: auth,
  simplePeerOpts: { wrtc: wrtc },
  minPeers: 2,
  softCap: 6,
  maxPeers: 9,
  minFanout: 0.33,
  maxFanout: 0.66,
  maxHistory: 10,
  debug: false,
};

const beakon = new Beakon(opts);

beakon.on("peer", (peer) => {
  console.debug("Peer event:", peer.id, peer.state);
  // peer.connection do something with Beakon peer
});

beakon.on("data", (data) => {
  console.log(data.senderId, data.content);
});

process.stdin.on("data", (data) => {
  beakon.send(data.toString().trim());
});

Browser (CDN coming soon)

<script type="module" src=""></script>

Example

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Beakon - WebRTC Signaling</title>
<script type="module">
  // import Beakon from "../index.js" // project root
  // import Beakon from "./index.js" // this folder
  import Beakon from "https://cdn.jsdelivr.net/npm/beakon/index.js" // cdn
  import auth from "./auth.js"
  
  const opts = {
    pubnubConfig: auth,
    simplePeerOpts: {},
    minPeers: 2,
    softCap: 6,
    maxPeers: 9,
    minFanout: 0.33,
    maxFanout: 0.66,
    maxHistory: 10,
    debug: true,
  }
  
  if (document.readyState === "complete" || document.readyState === "interactive") {
    const beakon = new Beakon(opts);
    
    function sendMessage() {
      console.log("Sending...")
      const inputField = document.getElementById('messageInput');
      const message = inputField.value || Math.floor(Math.random() * 1000).toString();
      beakon.send(message);
      inputField.value = '';
    }

    document.getElementById('sendButton').addEventListener('click', sendMessage);
    
    document.getElementById('messageInput').addEventListener('keypress', (event) => {
      if (event.key === 'Enter') {
        sendMessage();
      }
    });

    beakon.on('peer', peer => {
      console.log(peer)
      console.debug("Peer event:", peer.id, peer.state)
      // peer.connection do something with Beakon peers
    })

    beakon.on('data', (data) => {
      displayMessage(data.senderId, data.content, data.date);
    });

    function displayMessage(senderId, message, timestamp) {
      const messageContainer = document.getElementById('messages');
      
      const date = new Date(timestamp);
      const formattedDate = date.getTime();
      
      const senderName = (senderId === beakon.peerId) ? 'You' : senderId;
      
      const messageElement = document.createElement('div');
      messageElement.classList.add('message');
      messageElement.innerHTML = `<b>${senderName}</b> at ${formattedDate}: ${message}`;
      
      // Check if the message container has any child elements
      if (messageContainer.firstChild) {
        // If there's at least one message, insert the new message at the top
        messageContainer.insertBefore(messageElement, messageContainer.firstChild);
      } else {
        // If there are no messages, just append the new message
        messageContainer.appendChild(messageElement);
      }
    }
  };
</script>
</head>
<body>
<h2>Beakon - WebRTC Signaling</h2>
<div id="messages"></div>
<div id="sendSection">
  <input type="text" id="messageInput" placeholder="Enter message or send a random number"/>
  <button id="sendButton">Send</button>
</div>
</body>
<style>
  #messages {
    background-color: #f0f0f0;
    padding: 10px;
    margin-top: 20px;
    height: 300px;
    overflow-y: scroll;
    border: 1px solid #ccc;
  }
  .message {
    margin-bottom: 10px;
  }
  #sendSection {
    margin-top: 20px;
  }
</style>
</html>

Usage

Initialization

const beakon = new Beakon(opts [[object]])

Initialize Beakon with the passed in options.

opts [[object]]
const opts = {
  pubnubConfig: {
    publishKey: "",
    subscribeKey: "",
    userId: "",
  },
  simplePeerOpts: { wrtc: wrtc },
  minPeers: 2,
  softCap: 6,
  maxPeers: 9,
  minFanout: 0.33,
  maxFanout: 0.66,
  maxHistory: 10,
  debug: false,
};

Methods

send(data [[any]], address [[string]])

Send a broadcast message to all peers in the partial mesh network

beakon.connections()

Return the peers in this peer's partial mesh

beakon.on("peer", peer [[object]])

Listens for new peer events

The peer object has the following properties:

peer = {
  id: "", // "peer id"
  state: "", // "connected", "disconnected"
  peer: {}, // the peer instance object
}
beakon.on(event [[any]], data [[any]])

Listen for custom events

beakon.on(event [[any]], data [[any]])

Listen once for custom events

becon.emit(event [[any]], data [[any]])

Emit custom events

becon.off(event [[any]], data [[any]])

Remove custom events

Events (default)

connect

Listen for peer connection events

disconnect

Listen for peer disconnection events

data

Listen for data

DEBUG

Listen for debug events

Properties

beakon.seen

Return the all seen peers in the network

Seen peers are discovered through heartbeats they gossip through the partial mesh

beakon.messages

Return the message history a peer knows about