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

fastrtc

v1.2.1

Published

Mesh helper for connecting peers and opening data channels

Readme

fastrtc

Browser WebRTC mesh helper. Zero runtime dependencies.

You wire signaling. fastrtc connects peers and opens labeled data channels. Each channel tracks SCTP maxMessageSize and applies send backpressure.

Mental model

You                          fastrtc                         Remote peer
 │                              │                                  │
 │  signal(to, payload) ───────►│ forwards SDP / ICE               │
 │◄──── receive(from, payload) ──│                                  │
 │                              │◄──────── WebRTC ────────────────►│
 │  channel("chat")             │ opens labeled data channels      │
 │  connect("bob")              │ negotiates connection            │
 │  peer.ready                  │ declared channels open           │
 │  send / sendTo / ch.send     │ string or BufferSource           │
  1. Signaling is yours — forward SignalPayload objects. fastrtc never touches your server.
  2. Declare channels before connect() — channel("chat") registers a label for every current and future peer.
  3. peer.ready means go — wait for it (or peer.open(label)) before sending.

Install

pnpm add fastrtc

Quick start

import { FastRTC } from "fastrtc";
import type { SignalPayload } from "fastrtc";

const rtc = new FastRTC({
  id: "alice",
  signal: (to, payload) => {
    ws.send(JSON.stringify({ to, from: "alice", payload }));
  },
});

ws.onmessage = (e) => {
  const { from, payload } = JSON.parse(e.data);
  rtc.receive(from, payload as SignalPayload);
};

rtc.channel("chat", { ordered: true });

rtc.addEventListener("join", ({ peer }) => {
  void peer.ready.then(() => {
    void peer.channels.get("chat")!.send("hello");
  });
});

const bob = rtc.connect("bob");
await bob.ready;
const chat = bob.channels.get("chat")!;
chat.addEventListener("message", ({ data }) => console.log(data));
await chat.send("hi");
await rtc.send("chat", "hello all");
await rtc.sendTo("bob", "chat", "hello bob");

Signaling

type SignalPayload =
  | { type: "description"; description: RTCSessionDescriptionInit }
  | { type: "candidate"; candidate: RTCIceCandidateInit };
  • signal(to, payload) — fastrtc needs to send SDP or ICE to to
  • receive(from, payload) — apply a remote signal (auto-connects, returns Peer)

Offer glare: peer with the lexicographically larger ID is polite and yields on collision. Only the impolite peer creates labeled data channels; the polite peer waits for ondatachannel.

Channels

rtc.channel("chat", { ordered: true });
rtc.channel("files");

const bob = rtc.connect("bob");
await bob.ready;
const chat = bob.channels.get("chat")!;
await chat.send("hello");

Channel.send waits until bufferedAmount is under the watermark (maxMessageSize * 2), then hands the payload to SCTP. Parallel sends on the same channel queue. Payload larger than channel.maxMessageSize throws — caller splits. maxMessageSize comes from pc.sctp.maxMessageSize after the channel opens (fallback 65536).

string | BufferSource only. No framing, no Blob/stream helpers.

Late labels after ready: await bob.open("files").

Broadcast

| Method | Target | | ----------------------------- | ------------------------------- | | send(label, data) | Every peer with that label open | | sendTo(peerId, label, data) | One peer | | channel.send(data) | Channel you already have |

No open targets on send → resolves, does not throw. Both honor { signal?: AbortSignal }.

Events

FastRTC is an EventTarget:

| Event | Payload | | ------- | ------------- | | join | peer | | leave | id | | error | id, error |

Channel events: message (data), close, error.

ICE disconnected does not tear down (can recover). failed / closed emit leave.

Media

No media helpers. Use the raw connection:

bob.connection.addTrack(track, stream);
bob.connection.ontrack = (e) => {
  video.srcObject = e.streams[0];
};

API

FastRTC

new FastRTC({
  id: string;
  signal: (to: string, payload: SignalPayload) => void;
  rtcConfig?: RTCConfiguration; // default: Google STUN
})

| Method | Description | | --------------------------------------- | --------------------------------------------------- | | channel(label, options?) | Register a labeled channel for all peers | | connect(id, { signal? }) | Open connection; idempotent; returns Peer | | receive(id, payload) | Apply remote SDP/ICE; auto-connects; returns Peer | | get(id) | Peer or undefined | | send(label, data, options?) | Broadcast to every open channel on label | | sendTo(peerId, label, data, options?) | Send to one peer | | close(id) | Tear down one peer | | dispose() / [Symbol.dispose]() | Close everything |

| Property | Description | | ----------- | --------------------------- | | id | Local peer ID | | rtcConfig | Active RTC configuration | | peers | ReadonlyMap<string, Peer> |

Peer

| Method / property | Description | | -------------------------- | --------------------------------------------------------------------- | | id | Remote peer ID | | connection | Underlying RTCPeerConnection | | channels | ReadonlyMap<string, Channel> | | ready | Resolves when every declared label is open (or ICE connected if none) | | open(label, { signal? }) | Promise for one open channel | | close() | Tear down this peer |

Channel

| Method / property | Description | | ----------------------------------------- | ---------------------------------------- | | label / readyState / maxMessageSize | Channel state | | raw | Underlying RTCDataChannel | | ready | Resolves when open and SCTP size applied | | send(data, { signal? }) | Backpressured send; throws if oversized | | close() / [Symbol.dispose]() | Close the channel |

Build

pnpm build   # output in dist/

Requirements

  • Browser with RTCPeerConnection and RTCDataChannel
  • A signaling transport you control

Source Code

Since this plugin is MIT licensed, you can also contribute to it at it's repo on GitHub