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 🙏

© 2025 – Pkg Stats / Ryan Hefner

p2p-message

v1.0.3

Published

A simple and efficient P2P messaging library for browser-to-browser communication

Downloads

10

Readme

p2p-message

A simple and efficient peer-to-peer messaging library for direct browser-to-browser communication. Any peers using the same network key will automatically discover and connect to each other through configurable tracker servers.

Features

  • 🔒 Secure P2P messaging
  • 🚀 Zero server requirements - pure browser-to-browser communication
  • 🎯 Simple API with event-based architecture
  • 📡 Automatic peer discovery through tracker servers
  • 📊 Connection status monitoring
  • 🛠 Configurable network settings and trackers

Installation

npm install p2p-message

Or include directly in your HTML from CDN:

<script src="https://unpkg.com/[email protected]/dist/messaging.min.js"></script>

Try it Live

Check out our Live Demo to see p2p-message in action! Open the demo in multiple browser windows to test peer-to-peer messaging.

Usage

Key functionality:

  • Initialize P2P messaging with a unique network key (all peers using this key will connect)
  • Configure tracker servers for peer discovery
  • Set up message and connection event handlers
  • Connect to the P2P network
  • Send messages to specific peers
  • Broadcast messages to all connected peers
  • Disconnect and clean up when done
// Initialize with configuration
const config = {
  key: 'unique-network-key',  // All peers using this key will connect
  trackers: [                 // Tracker servers for peer discovery
    'wss://tracker.openwebtorrent.com'
  ],
  onMessage: (peerId, message) => {
    console.log(`Message from ${peerId}: ${message}`);
  },
  onConnect: (peerId) => {
    console.log(`New peer connected: ${peerId}`);
  }
};

// Create instance and connect
const p2p = new P2PMessage(config);
p2p.connect();

// Send message to a specific peer
p2p.send('peer-id-123', 'Hello, peer!');

// Broadcast implementation
const peers = new Set();

// Track connected peers
config.onConnect = (peerId) => {
  peers.add(peerId);
  console.log(`New peer connected: ${peerId}`);
};

// Broadcast to all peers
function broadcast(message) {
  peers.forEach(peerId => {
    p2p.send(peerId, message);
  });
}

// Clean up when done
p2p.disconnect();

API Reference

Constructor options:

  • key (required): String - Unique network identifier. All peers using the same key will automatically connect
  • trackers (optional): Array - List of WebSocket tracker URLs for peer discovery. Defaults to public trackers
  • onMessage (optional): Function(peerId, message) - Called when receiving messages
  • onConnect (optional): Function(peerId) - Called when a new peer connects

Available methods:

  • connect() - Connects to the P2P network through configured trackers
  • send(peerId, message) - Sends a message to a specific peer
  • disconnect() - Disconnects from network and cleans up resources

Browser Support

  • Chrome/Chromium (Desktop & Android)
  • Firefox (Desktop & Android)
  • Safari (Desktop & iOS)
  • Edge (Chromium-based)

Contributing

We welcome contributions! Please see our Contributing Guidelines for more details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

See CHANGELOG.md for release notes.