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

hyper-presence

v1.1.3

Published

Detect who's actively online using gossip over hypercore-protocol

Downloads

9

Readme

hyper-presence

Detect who's actively online using gossip over hypercore-protocol

Usage

npm i --save hyper-presence
const HypercorePresence = require('hyper-presence')

const feed = getHypercoreFromSomewhere()

const presence = new HypercorePresence(feed)

presence.setData({
	"hello": "world"
})

presence.on('online', (list) => {
	for(let id of list) {
		const peerData = presence.getPeerData(id)
		console.log('Online peer:', id, peerData)
	}
})

API

const presence = new HypercorePresence(feed, {extension, data, encoding, id})

Initialize a hypercore presence instance attached to a hypercore.

  • feed: A hypercore instance to attach to. Make sure the hypercore is ready before attaching to it.
  • extension: The extension message name to use over the replication stream. Default: hyper-presence
  • encoding: The encoding for peers' data. Default: json
  • id: The id for this peer in the network. Should be the same as the replication public key
  • data: The default data to advertise on the network. Default {}.

presence.on('bootstrapped')

Emitted when you have bootstrapped with a peer in the network.

presence.on('online', list)

Emitted whenever something in the network changes and there's a list of people online.

  • list: A list of IDs of peers that are currently online in the network. You might not be connected to some of them directly.

presence.on('peer-data', data, id)

Emitted whenever a peer updates their state.

  • data is an object representing the peer's state
  • id is the id of the peer in the network

presence.on('peer-add', id)

Emitted whenever a peer has been connected to.

  • id is the id of the peer in the network

presence.on('peer-remove', id)

Emitted when you lose a connection to a peer.

  • id is the id of the peer in the network.

`presence.on('peer-add-seen', source, destination)

Emitted when you get notified that a peer in the network has connected to someone.

`presence.on('peer-remove-seen', source, destination)

Emitted when you get notified that a peer in the network has disconnected from someone.

presence.online

The current list of known online peers. This gets updated every time we get network events.

presence.data

Get the current data being sent over to other peers.

presence.setData(data)

Update the data being advertised to the rest of the network.

  • data: An object that other peers in the network will see for this user.

const data = presence.getPeerData(id)

Get the data being advertised by a specific peer.

  • id: The ID of the peer you want to get data from
  • data: An object with the data the peer id advertising. null if it's an invalid peer.

How it works

  • Peers keep an internal graph with the state of other peers
  • Communication is facilitatied with flooding broadcasts over the hypercore replicaiton protocol
  • When peers first boot up, they will ask their first peer for a copy of their graph to bootstrap
  • From there, peers will broadcast whenever they've connected or disconnected from somebody.
  • Other peers will listen to these messages and update their local graphs
  • The data tracked per peer is their list of outgoing connections
  • A peer is considered online if there are connections going from the current peer to them
  • This should be calculated every time the connections change
  • Peers that are no longer online will be pruned from the graph

Credits

Ce logiciel a été créé dans le cadre du projet de plateforme virtuelle de création autochtone P2P Natakanu. Une réalisation de Wapikoni Mobile, Uhu Labos Nomades et du Bureau de l'engagement communautaire de l'université Concordia. Projet financé dans le cadre de l'Entente sur le développement culturel de Montréal conclue entre la Ville de Montréal et gouvernement du Québec.


This software was created as part of Natakanu, a P2P indigenous platform produced by Wapikoni Mobile, Uhu Labos Nomades and the Office of Community Engagement at Concordia University. Project funded under the Montreal cultural development agreement between the city of Montreal and the government of Quebec.