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

upeerjs

v0.0.3

Published

Serverless P2P communication library using MQTT signaling with E2E encryption

Downloads

395

Readme

uPeerJS

Serverless P2P communication library for the browser. Inspired by PeerJS, but no dedicated signaling server required — just connect to any existing MQTT broker and start communicating peer-to-peer.

Why uPeerJS?

PeerJS requires you to deploy and maintain a dedicated PeerServer for signaling. uPeerJS eliminates this dependency entirely by using MQTT as the signaling transport. Any public or private MQTT-over-WebSocket broker (EMQX, Mosquitto, HiveMQ, etc.) can serve as the signaling layer — zero backend code, zero server deployment.

| | PeerJS | uPeerJS | |---|---|---| | Signaling | Requires dedicated PeerServer | Any MQTT broker — no custom server | | Encryption | None on signaling | AES-GCM E2E | | DataChannel | Basic send/receive | Streaming + backpressure + MessagePack | | Transport | Hardcoded WebSocket | Pluggable (MQTT default) |

Install

npm install upeerjs

Quick Start

Video Call

import { Peer } from 'upeerjs';

const peer = new Peer('alice', { securityKey: 'shared-secret' });
peer.start();

// Make a call
const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
const session = peer.call('bob', stream);

// Receive remote stream
peer.on('stream', ({ peerId, stream: remote }) => {
  video.srcObject = remote;
});

// Receive a call
peer.on('call', ({ peerId, call }) => {
  // call is an RtcSession — remote stream arrives via the 'stream' event on Peer
});

Data Only

const session = peer.connect('bob');

peer.on('dataConnection', ({ peerId, conn }) => {
  conn.on('data', (data) => console.log(data));
});

// Send data to a specific peer
peer.send('bob', { hello: 'world' });

Features

  • Serverless — MQTT broker for signaling, no custom server needed
  • E2E Encrypted — AES-GCM encryption on signaling (SDP, ICE candidates)
  • Streaming DataChannel — Web Streams API with backpressure and 32KB chunking
  • MessagePack — Binary serialization, ~30% smaller than JSON
  • Single Connection — Media + DataChannel over one RTCPeerConnection
  • Pluggable — Swap codec (JSON → custom) or encryption (AES-GCM → custom)
  • TypeScript — Full type safety with typed events

Architecture

Application (RPC, state sync, business logic)
    │
    ▼
Peer (connection orchestrator)
    ├── RtcSession (RTCPeerConnection lifecycle)
    ├── DataConnection (DataChannel + streaming)
    ├── SignalingBatcher (signal pass-through)
    ├── MqttTransport (MQTT-over-WebSocket signaling)
    └── AesGcmEncryption (E2E encryption)

API

new Peer(id?, options)

Create a peer instance. Options:

| Option | Type | Default | Description | |---|---|---|---| | brokerUrl | string | 'wss://broker.emqx.io:8084/mqtt' | MQTT broker URL | | mqttOptions | IClientOptions | — | Additional MQTT client options | | securityKey | string | — | E2E encryption key (AES-GCM) | | rtcConfig | RTCConfiguration | Google STUN + Cloudflare STUN + PeerJS TURN | WebRTC configuration | | codec | ICodec | JsonCodec | Custom codec for signaling | | encryption | IEncryption | — | Custom encryption implementation | | debug | boolean | false | Enable debug logging |

peer.start()

Connect to the MQTT signaling broker. Emits 'open' when connected.

peer.call(peerId, stream?)RtcSession

Initiate a media + data call to a peer.

peer.connect(peerId)RtcSession

Open a data-only connection.

peer.send(peerId, data)

Send data to a specific peer via DataChannel.

peer.broadcast(data, options?)

Send data to all connected peers.

peer.replaceTrack(peerId, stream)

Replace media tracks for a specific peer (takes a full MediaStream).

peer.setLocalStream(stream)

Set local stream and update all active sessions.

peer.hangup(peerId) / peer.dataDisconnect(peerId)

Close a specific peer connection.

peer.destroy()

Close all connections and signaling.

Events

| Event | Payload | |---|---| | open | peerId: string | | call | { peerId, call: RtcSession } | | stream | { peerId, stream: MediaStream, call: RtcSession } | | hangup | { peerId, call: RtcSession } | | dataConnection | { peerId, conn: DataConnection } | | data | { peerId, data, conn: DataConnection } | | dataDisconnect | { peerId, conn: DataConnection } | | iceConnectionStateChange | { peerId, iceConnectionState, peerConnection } | | close | — | | error | Error |

Design Document

See docs/design.md for full architecture, interfaces, protocol specs, and usage examples.

License

MIT