JS SDK

JS SDK

Use the rstream JavaScript SDK for APIs, tokens, signaling, and webhooks.


The JavaScript SDK provides a typed client for rstream APIs and integration helpers for applications. Typical usage includes minting short-lived tokens from application credentials, listing tunnels and clients for discovery, subscribing to signaling updates, and verifying webhook signatures.

The SDK is written in TypeScript and exposes resource clients for auth, tunnels, clients, and webhooks.

Client initialization

Initialization supports two credential models: a static token, or application credentials (client id and client secret) used to mint short-lived tokens on demand.

Static token credentials:

import { Rstream } from "@rstreamlabs/rstream";
const client = new Rstream({
  engine: process.env.RSTREAM_DEFAULT_ENGINE,
  credentials: { token: process.env.RSTREAM_DEFAULT_AUTHENTICATION_TOKEN! },
});

Application credentials:

import { Rstream } from "@rstreamlabs/rstream";
const client = new Rstream({
  engine: "cluster.example.rstream.io:443",
  credentials: {
    clientId: process.env.RSTREAM_DEFAULT_CLIENT_ID!,
    clientSecret: process.env.RSTREAM_DEFAULT_CLIENT_SECRET!,
  },
});

The SDK can also read default credentials from environment variables when values are not provided explicitly.

Minting a short-lived token

Application credentials can be used to mint a short-lived token explicitly:

const { token } = await client.auth.createAuthToken({ expires_in: 60 });

By default the SDK uses a 60-second TTL when no expiration is provided.

Listing tunnels

The tunnels resource supports typed filters:

const tunnels = await client.tunnels.list({
  filters: { status: "online", protocol: "http" },
});

Watching events

The Watch helper connects to the engine over SSE or WebSocket and dispatches validated events to a callback:

import { Watch } from "@rstreamlabs/rstream";
const watch = new Watch(
  { auth: token, transport: "sse", engine: "cluster.example.rstream.io:443" },
  { onEvent: (event) => console.log(event.type) },
);
await watch.connect();