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

p2p.js

v0.0.2

Published

Build serverless peer to peer webapps powered by auto matchmaking WebRTC

Readme

p2p.js

p2p.js is an open source JavaScript library which provides solution to build peer to peer webapps without hassle powered by auto matchmaking WebRTC. This solve the common issues faced by WebRTC based application developers who need to deploying their own signaling server.

>DEMO<

Benefit

  • ✅ WebRTC auto matchmaking
  • ✅ No server required
  • ✅ Simple API
  • ✅ ESM support

How does it works?

This module manage WebRTC matchmaking automatically via established public WebTorrent protocol as signaling transport then provides video, audio and data channel. Take a look at the signalingserver.js for more information.

Ideas

  • P2P Chat
  • P2P File Transfer
  • P2P Video Call
  • P2P Media Streaming
  • P2P Game Multiplayer
  • P2P Screen Sharing
  • P2P Camera

Install

npm install p2p.js

CDN

<script type="importmap">
{
	"imports": {
		"p2p.js" : "https://esm.sh/p2p.js"
	}
}
</script>

Usage

import {createPeer} from 'p2p.js';

const peers = [];

const config = {
	appid: 'myApp'
}

const peer = createPeer(config);

peer.onPeerConnect((peer_id)=>{
	peers.push(peer_id);
	console.log('connect',peer_id);
});

peer.onPeerDisconnect((peer_id)=>{
	peers.splice(peers.findIndex(item=>item===peer_id),1);
	console.log('disconnect',peer_id);
});

peer.onPeerData((peer_id,data) => {
	console.log(`${peer_id} say : ${new TextDecoder().decode(data)}`);
});

setInterval(()=>{
	const me = peer.getPeerId();
	peers.forEach(peer_id=>peer.sendPeerData(peer_id,`i am ${me}`));
},5000);

API

peer = createPeer(config)

Create a new p2p peer.

config - configuration object :

peer.getPeerId()

Get this peer ID.

peer.getPeers()

Get all peers ID that connected.

peer.destroyPeer()

Destroy and cleanup this peer.

peer.sendPeerData(peer_id,data)

Send data to peer.

peer.addPeerStream(peer_id,stream)

Add a MediaStream to peer.

peer.removePeerStream(peer_id,stream)

Remove a MediaStream from peer.

peer.addPeerTrack(peer_id,track,stream)

Add a MediaStreamTrack to peer.

peer.removePeerTrack(peer_id,track,stream)

Remove a MediaStreamTrack from peer.

peer.replacePeerTrack(peer_id,old_track,new_track,stream)

Replace a MediaStreamTrack with another track.

peer.onPeerConnect((peer_id)=>{})

Listen on new peer connection.

peer.onPeerDisconnect((peer_id)=>{})

Listen on peer disconnection.

peer.onPeerData((peer_id,data)=>{})

Listen on incoming data.

peer.onPeerStream((peer_id,stream)=>{})

Listen on incoming stream.

peer.onPeerTrack((peer_id,track, stream)=>{})

Listen on incoming video/audio track.

peer.onPeerError((peer_id,error)=>{})

Listen on fatal error connection.

TURN

p2p.js works for most WebRTC apps but some network don't allow peer-to-peer connection. The common way to solve this issue is by using TURN for relaying network traffic.

const iceConfiguration = {
    iceServers: [
        {
			urls: 'stun:my-turn-server.mycompany.com:19401'
		},
		{
            urls: 'turn:my-turn-server.mycompany.com:19402',
            username: 'optional-username',
            credential: 'auth-token'
        }
    ]
}

const config = {
	appid: 'myApp',
	rtcconfig : iceConfiguration
}

const peer = createPeer(config);

Services :

License