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

webrtc-phoenix-client

v1.0.0

Published

Browser-only WebRTC peer client for Phoenix Channels (signaling + ordered data messaging)

Downloads

28

Readme

webrtc-phoenix-client

Browser-only WebRTC peer client that uses Phoenix Channels for signaling, and a reliable ordered RTCDataChannel for messaging.

Install

npm i webrtc-phoenix-client

Notes

  • Browser-only: Node is not supported (this library expects browser WebRTC globals like RTCPeerConnection).
  • For real-world NAT traversal, you will likely need STUN/TURN via rtcConfig.iceServers.
  • Send semantics: sendMessage() resolves when the message is queued/sent on the local RTCDataChannel (it does not wait for a remote application-level ACK).

Usage

import { Peers } from "webrtc-phoenix-client";

// 1) Create peers instance
const peers = new Peers({
  url: "wss://your-host.com/webrtc_socket",
  // rtcConfig: { iceServers: [{ urls: "stun:stun.l.google.com:19302" }] },
});

// 2) Create/store identity (publicId + privateId)
const myId = await peers.generateID();
// persist myId.privateId somewhere safe if you want stable identity across reloads

// 3) Init: connects to Phoenix + registers ID
const initRes = await peers.init(myId);
if (initRes !== "ok") throw new Error(`init failed: ${initRes}`);

console.log("My public ID:", myId.publicId);

// 4) Optional: gate inbound connections
peers.onPeerRequest(async (fromId) => {
  // return true to accept, false to reject
  return confirm(`Accept connection from ${fromId}?`);
});

// 5) Peer lifecycle hooks
peers.onPeerConnected((peer) => {
  console.log("connected:", peer.id, peer.pc, peer.dc);
});

peers.onPeerDisconnected((peerId) => {
  console.log("disconnected:", peerId);
});

// 6) Messaging
peers.onMessage((from, msg) => {
  console.log("message from", from, msg);
});

// Start connecting (idempotent per peer; concurrent calls share the same attempt)
const conn = await peers.addPeer("peerPublicIdHere");
if (conn.status !== "connected") {
  console.warn("connect aborted:", conn.reason, conn.error);
} else {
  // Send a JS object. Nested Blobs / Files / ArrayBuffers / TypedArrays are supported.
  const sendRes = await peers.sendMessage(conn.peer.id, {
    hello: "world",
    file: (document.querySelector("#file") as HTMLInputElement).files?.[0],
  });

  console.log("send result:", sendRes);
}

API (high level)

Identity

  • peers.generateID() -> Promise<{ publicId, privateId }>
  • peers.init({ publicId, privateId }) -> Promise<"ok" | "in-use" | "auth failed">

Peering

  • peers.addPeer(peerPublicId) -> Promise<{ status: "connected", peer } | { status: "aborted", reason, error? }>
  • peers.onPeerRequest((peerId) => boolean | Promise<boolean>) — default accepts all
  • peers.onPeerConnected((peer) => void)
  • peers.onPeerDisconnected((peerId) => void)
  • peers.removePeer(peerId) — closes and removes the peer

Messaging

  • peers.sendMessage(to, obj) -> Promise<SendMessageResult> (strict: does not auto-connect)
  • peers.broadcast(obj) -> Promise<Record<peerId, SendMessageResult>>
  • peers.onMessage((from, obj) => void) — receives the reconstructed JS object

Underlying WebRTC

  • addPeer() resolves with peer.pc: RTCPeerConnection and peer.dc: RTCDataChannel
  • Renegotiation is supported via the Perfect Negotiation pattern.