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

@rtcsvc/server

v1.1.14

Published

Node + browser SDK: register a service channel and answer client requests over WebRTC

Readme

@rtcsvc/server

Node + browser SDK for rtcsvc: register a service channel on the gateway and answer client requests over a peer-to-peer WebRTC DataChannel.

The gateway only authenticates and relays WebRTC signalling — request/response traffic, pub/sub and broadcast flow peer-to-peer, encoded with datapack. This server is the WebRTC offerer and owns the RPC data channel. Servers also form an inter-server mesh so pub/sub and broadcast fan out across every server of a service.

Install

npm install @rtcsvc/server

Runs in Node >= 20 and modern browsers (ES2022, WebSocket, RTCPeerConnection).

In Node, the optional peer dependencies ws and node-rtc-connection are used for the WebSocket control plane and WebRTC data plane respectively. Install them alongside this package:

npm install @rtcsvc/server ws node-rtc-connection

In the browser, the native WebSocket and RTCPeerConnection APIs are used — no additional dependencies are needed.

Usage

import { Event, Request, ServiceServer, Status } from "@rtcsvc/server";
import { STRING } from "datapack";

const server = new ServiceServer({
  gatewayUrl: "wss://gateway.example.com/ws",
  projectId: "proj_...", // from the admin console
  secretKey: "sk_...", // the project's secret key
  serviceName: "chat", // service name within the project (auto-created there if missing)
});

// Request/reply route — payload + response are datapack schemas.
server.use(
  "echo",
  { text: STRING }, // request schema
  { text: STRING }, // response schema
  (req, res) => {
    res.send({ text: req.payload.text });
  },
  { description: "Echo text back to the caller." },
);

// Pub/sub: declare an event type, optionally subscribe.
server.useEvent(
  "chat",
  { text: STRING },
  (payload, publisher) => {
    console.log(`from ${publisher.id} (${publisher.role}):`, payload.text);
  },
  { description: "Chat messages broadcast to subscribers." },
);

server.on("registered", (serviceName, connId) => console.log("registered", serviceName, connId));

await server.start();

// Fan out to topic subscribers across the mesh (data is packed per the
// schema registered with useEvent):
server.publish("chat", { text: "hello" });
// Fan out to every client of every server:
server.broadcast("chat", { text: "hello everyone" });

Decorator-style handlers

You can also register request routes and event subscribers with Nest-style method decorators:

const ReqHello = { name: STRING } as const;
const ResHello = { text: STRING } as const;
const RoomEvent = { text: STRING } as const;

class HelloController {
  @Request("hello", {
    description: "abc",
    requestSchema: ReqHello,
    responseSchema: ResHello,
  })
  hello(req, res) {
    res.send({ text: `hello ${req.payload.name}` });
  }

  @Event("room", {
    description: "Room messages.",
    payloadSchema: RoomEvent,
  })
  onRoom(payload, publisher) {
    console.log(`from ${publisher.id}: ${payload.text}`);
  }
}

server.registerController(new HelloController());

Decorators store route metadata only; pass an already constructed controller instance to registerController() so your own constructor dependencies work normally. The decorator works with TypeScript 5 standard decorators and legacy experimentalDecorators.

API

  • new ServiceServer(options){ gatewayUrl, projectId, secretKey, serviceName, reconnect?, webSocketHeaders?, debug? }. The server registers serviceName inside projectId; the same serviceName may exist in another project. In Node, the SDK sends browser-like WebSocket headers by default; webSocketHeaders can override or extend them.
  • .use(type, requestSchema, responseSchema, handler, metadata?) — register a request route.
  • .registerController(instance) — register methods decorated with @Request(...) or @Event(...).
  • .useEvent(type, payloadSchema, handlerOrMetadata?, metadata?) — register an event type (and optionally subscribe). metadata may be a string or { description }; descriptions are reflected by #schema.
  • .subscribe(topic, cb) / .unsubscribe(topic, cb?) — server-side topic subscription.
  • .publish(type, data) — publish to topic subscribers across the mesh (data packed per the event schema).
  • .broadcast(type, data) — deliver to every client of every server.
  • .sendTo(connId, payload) — directed message to a single connection.
  • .start() / .stop() — connect to / disconnect from the gateway.
  • .on(event, cb) — lifecycle events: registered, peer, connect, disconnect, error, close, reconnecting, reconnect, reconnectfailed.

Inside a handler, res.setStatus(code), res.setSession(patch) and res.send(data) shape the reply; Status holds the common status codes.

License

MIT