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

@graffiti-garden/tracker-client

v1.1.0

Published

client for the tracker server

Downloads

9

Readme

Graffiti Tracker

This client javascript library interacts with the tracker server.

Usage

First, install the client into your project with:

npm install @graffiti-garden/tracker-client

To connect to the client you need a "peer proof" and a list of tracker URIs.

Your peer ID is the hash of your peer proof - connecting via the proof rather than the hash itself prevents basic peer forgery. The peer proof must be a 256 bit random hex string.

If no tracker list is included, the client will automatically connect to the global tracker at wss://tracker.graffiti.garden.

import TrackerClient from @graffiti-garden/tracker-client

// Generate the peer proof
const peerProof =
 [...crypto.getRandomValues(new Uint8Array(32))]
 .map(b => b.toString(16).padStart(2, '0')).join('');

// List of trackers
const myTrackers = ['ws://localhost:8000', 'wss://tracker.my.website']

const trackerClient = new TrackerClient(peerProof, myTrackers)

To announce or unannounce, simply pass a list of URIs into the appropriate function:

await trackerClient.announce(
  'urn:fdc:example.com',
  'urn:isan:0000-0000-2CEA-0000-1-0000-0000-Y'
)

const myURIs = [
  'urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66',
  'ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi'
]
await trackerClient.unannounce(...myURIs)

Subscription is done with an asyncronous generator. Like, fetch, it uses an AbortSignal to stop running requests.

For example, to timeout after 5 seconds:

const signal = AbortSignal.timeout(5000) 

for await (const { action, peer } in trackerClient.subscribe('uri:fdc:graffiti.garden', signal)) {
  if (action == 'announce') {
    // Do something
  } else if (action == 'unannounce') {
    // Do something else
  }
}

Testing

The tests will connect to the global server at wss://tracker.graffiti.garden as well as a local server at ws://localhost:8000. To start the local server, clone the tracker server and start it with docker compose.

git clone https://github.com/graffiti-garden/tracker-server/
cd tracker-server
sudo docker compose up --build

You can verify the server is up by going navigating to http://localhost:8000/.

Then, to start the client tests simply run:

npm test