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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gossip-protocol

v1.0.0

Published

Gossip-style message propagation over a WebRTC partial mesh (PartialMesh) with UniWRTC signaling

Readme

gossip-protocol

WebRTC peer-to-peer networking (PartialMesh) plus an example “gossip protocol” implementation that re-propagates messages across connected peers.

This package is intentionally small:

  • The library exports PartialMesh (best-effort WebRTC partial mesh connection manager).
  • The library also exports GossipProtocol, a tiny re-propagation helper used by the demo.

Install

npm i gossip-protocol

Notes:

  • Designed for browsers (WebRTC required). Node.js is used for tooling/tests.
  • Signaling uses UniWRTC; by default the demo points at a public server.

Quick start

import { PartialMesh, GossipProtocol } from 'gossip-protocol';

const mesh = new PartialMesh({
	sessionId: 'my-room',
	minPeers: 1,
	maxPeers: 5,
});

const gossip = new GossipProtocol(mesh, { maxHops: 5 });
gossip.on('messageReceived', ({ message, local }) => {
	console.log(local ? 'local' : 'remote', message);
});

mesh.on('signaling:connected', ({ clientId }) => {
	console.log('signaling connected as', clientId);
});

mesh.on('peer:connected', (peerId) => {
	console.log('peer connected', peerId);
});

mesh.on('peer:data', ({ peerId, data }) => {
	console.log('from', peerId, data.toString());
});

await mesh.init();

// Later:
// mesh.broadcast('hello');
// mesh.send(peerId, 'direct message');
// mesh.destroy();

API

new PartialMesh(config?)

Configuration (all optional):

  • minPeers (default 2): minimum number of peer connections to maintain.
  • maxPeers (default 10): maximum number of peer connections to maintain.
  • signalingServer (default wss://signal.peer.ooo): UniWRTC signaling server URL.
  • sessionId (default default-session): room ID used for discovery.
  • autoDiscover (default true): automatically join sessionId on signaling connect.
  • autoConnect (default true): automatically converge to the target connection count.
  • iceServers (default: Google STUN): passed to WebRTC for ICE.
  • connectionTimeoutMs (default 25000): time to wait for a peer to reach connect before retrying.
  • maintenanceIntervalMs (default 2000): how often to run the convergence loop.
  • underConnectedResetMs (default 0 / disabled): if > 0, triggers a periodic hardReset() when the mesh stays below minPeers despite having enough discovered peers.

Methods

  • init(): Promise<void>
    • Connects to signaling, joins the discovery session (if autoDiscover), and starts maintenance (if autoConnect).
  • destroy(): void
    • Tears down peer connections, clears discovered peers, and disconnects signaling.
  • hardReset(reason?: string): void
    • Drops all peer connections but keeps signaling/discovery state; useful to recover from rare stuck negotiation/ICE states.
  • connectToPeer(peerId: string): void
    • Attempts to establish a WebRTC connection to a discovered peer.
  • disconnectFromPeer(peerId: string): void
    • Disconnects from a peer (does not remove it from discovery unless signaling says it left).
  • send(peerId: string, data: string | Buffer | ArrayBuffer): void
    • Sends data to a connected peer. Throws if not connected.
  • broadcast(data: string | Buffer | ArrayBuffer): void
    • Sends data to all connected peers.
  • getConnectedPeers(): string[]
  • getDiscoveredPeers(): string[]
  • getPeerCount(): number
  • getClientId(): string | null
  • on(event, handler): void / off(event, handler): void

Events

  • signaling:connected{ clientId: string, rawClientId?: string }
  • signaling:disconnected
  • signaling:errorany
  • peer:discoveredpeerId: string
  • peer:connectedpeerId: string
  • peer:disconnectedpeerId: string
  • peer:data{ peerId: string, data: any } (typically a Buffer-like payload)
  • peer:error{ peerId: string, error: any }
  • mesh:ready → emitted when connectedPeers.length >= minPeers

Vue 3 demo (gossip)

From the repo root:

npm install
npm run dev

Serves at http://127.0.0.1:5173.

Autostart parameters:

  • autostart=1
  • maxPeers=20
  • minPeers=3
  • sessionId=your-room

Example:

http://127.0.0.1:5173/?autostart=1&maxPeers=10&minPeers=2&sessionId=my-room

Tests (Playwright e2e loop)

npm test runs a Playwright spec in a loop and prints a per-run summary.

Defaults are defined in scripts/run-e2e-loop.mjs:

  • Runs: 5
  • Spec: tests/vue3-15-peers-crossbrowser.spec.ts

Override via env vars:

  • E2E_RUNS
  • E2E_TIMEOUT_MS
  • E2E_SPEC
  • E2E_REPORTER
  • E2E_MAX_RUN_SECONDS

Examples:

E2E_RUNS=10 E2E_TIMEOUT_MS=20000 npm test
E2E_SPEC=tests/vue3-15-peers-crossbrowser.spec.ts npm test

Or run the loop script directly:

node scripts/run-e2e-loop.mjs --runs 5 --timeoutMs 15000 --spec tests/vue3-15-peers-crossbrowser.spec.ts --reporter dot

Notes / risks

  • WebRTC + browser automation is inherently flaky across engines; timeouts are tuned for stability rather than strict guarantees.
  • The default signaling endpoint is a third-party service. Treat room IDs and client IDs as metadata visible to that signaling layer.
  • This is not a security boundary. If you need authz/authn, abuse protection, persistence, or app-layer encryption, add them in your application.