Skip to content

React SDK

Embed Rhombus camera streams in React applications with the official SDK, featuring DASH buffered playback and real-time H.264 WebSocket players via WebCodecs.

On this page

The official @rhombussystems/react package provides drop-in React components for streaming Rhombus cameras. Two player modes are available:

  • RhombusBufferedPlayer — MPEG-DASH live streaming via Dash.js (buffered, reliable)
  • RhombusRealtimePlayer — Low-latency H.264 over WebSocket via WebCodecs (near real-time)
Info

Requires React 18+ and a backend endpoint that generates federated session tokens. Your Rhombus API key must never be exposed to the browser.

Install

bash
npm install @rhombussystems/react

Peer dependencies: react and react-dom >= 18. The dashjs library is included automatically for DASH playback.

Quick start

tsx
import { RhombusBufferedPlayer } from "@rhombussystems/react";

export function CameraView() {
  return <RhombusBufferedPlayer cameraUuid="YOUR_CAMERA_UUID" />;
}

This renders a DASH-based buffered video player. The component automatically:

  1. Requests a federated session token from your backend (POST /api/federated-token)
  2. Fetches media URIs from the Rhombus API
  3. Initializes Dash.js playback
Warning

Your backend must implement a POST /api/federated-token endpoint (or configure a custom path via the paths.federatedToken prop). See Backend Setup below.

Buffered player (DASH)

The RhombusBufferedPlayer streams MPEG-DASH live video with configurable quality levels.

tsx
import { RhombusBufferedPlayer } from "@rhombussystems/react";

export function BufferedCamera() {
  return (
    <RhombusBufferedPlayer
      cameraUuid="YOUR_CAMERA_UUID"
      bufferedStreamQuality="HIGH"
    />
  );
}

Stream quality

Control server-side downscaling with the bufferedStreamQuality prop:

ValueDescription
"HIGH"Full resolution (default)
"MEDIUM"Medium downscale
"LOW"Low resolution, lowest bandwidth

Changing quality does not re-fetch the manifest or token — the Dash.js RequestModifier applies the change on the next segment request.

tsx
import { useState } from "react";
import {
  RhombusBufferedPlayer,
  type RhombusBufferedStreamQuality,
} from "@rhombussystems/react";

export function CameraWithQuality() {
  const [quality, setQuality] = useState<RhombusBufferedStreamQuality>("HIGH");

  return (
    <>
      <select
        value={quality}
        onChange={(e) => setQuality(e.target.value as RhombusBufferedStreamQuality)}
      >
        <option value="HIGH">High</option>
        <option value="MEDIUM">Medium</option>
        <option value="LOW">Low</option>
      </select>
      <RhombusBufferedPlayer
        cameraUuid="YOUR_CAMERA_UUID"
        bufferedStreamQuality={quality}
      />
    </>
  );
}

Realtime player (WebSocket)

The RhombusRealtimePlayer decodes H.264 frames over WebSocket using the browser's WebCodecs API and renders to a <canvas>. This provides lower latency than DASH.

tsx
import { RhombusRealtimePlayer } from "@rhombussystems/react";

export function RealtimeCamera() {
  return (
    <RhombusRealtimePlayer
      cameraUuid="YOUR_CAMERA_UUID"
      connectionMode="wan"
    />
  );
}

Connection modes

ModeDescription
"wan"Uses the WAN H.264 WebSocket URI with federated token auth appended to the URL
"lan"Uses the LAN H.264 WebSocket URI. Federated token auth is appended to the URL the same way as WAN (x-auth-scheme=federated-token and x-auth-ft query parameters)

Stream quality

ValueDescription
"HD"Full resolution (default)
"SD"Lower resolution via /wsl path — changing this prop reconnects the WebSocket

LAN mode considerations

In LAN mode, the SDK appends the federated token to the WebSocket URL as query parameters (x-auth-scheme=federated-token and x-auth-ft), the same way it does for WAN. This works from any origin, including localhost.

The practical requirement for LAN mode is network reachability: the browser must be able to reach the camera/NVR host directly (routing, firewall, and HTTPS-vs-HTTP mixed-content rules all apply). See Streaming over LAN for how LAN authentication works and why devices accept only federated tokens.

Backend setup

The SDK requires a server-side endpoint to generate federated session tokens. Your Rhombus API key stays on the server — it is never sent to the browser.

Token endpoint

Your backend must expose a POST endpoint (default path: /api/federated-token):

javascript
const express = require("express");
const app = express();
app.use(express.json());

// The exact origin your pages are served from, such as https://app.example.com
const APP_ORIGIN = process.env.APP_ORIGIN;

app.post("/api/federated-token", async (req, res) => {
  // At most 24 hours; 1 hour if the request doesn't say
  const durationSec = Math.min(Number(req.body.durationSec) || 3600, 86400);
  const response = await fetch(
    "https://api2.rhombussystems.com/api/org/generateFederatedSessionToken",
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "x-auth-scheme": "api-token",
        "x-auth-apikey": process.env.RHOMBUS_API_KEY,
      },
      body: JSON.stringify({ durationSec, domain: APP_ORIGIN }),
    }
  );
  if (!response.ok) return res.status(502).json({ error: "Could not mint a token" });
  // Return the whole response: the SDK reads expiresAtMs and renews the token before it expires
  res.json(await response.json());
});
Warning

Set domain to your app's exact origin: an absolute origin with scheme, host and any non-default port, and no path, such as https://app.example.com (or http://localhost:5173 in development). The browser fetches media URIs from api2.rhombussystems.com directly, and without a domain that matches your app's origin those requests fail with CORS errors. Rhombus accepts a token with domain only on requests whose Origin (or, without one, Referer) matches it, and answers any other with 403 DOMAIN_NOT_ALLOWED. A value that isn't an absolute origin fails the mint with 400.

The SDK asks your endpoint for a lifetime (tokenDurationSec, 86400 by default) and fetches a new token shortly before the expiresAtMs your endpoint returns, so return the mint response unchanged. Rhombus caps federated tokens at 24 hours and uses one hour when durationSec is left out.

Override mode (proxy all requests)

If you prefer to keep all Rhombus traffic server-side (the browser never talks to Rhombus directly), use apiOverrideBaseUrl:

tsx
<RhombusBufferedPlayer
  cameraUuid="YOUR_CAMERA_UUID"
  apiOverrideBaseUrl="https://your-api.example.com"
/>

In this mode, your backend must also expose a POST /api/media-uris endpoint that proxies to Rhombus's POST /camera/getMediaUris.

Props reference

Shared props

PropTypeDefaultDescription
cameraUuidstringrequiredCamera UUID to stream
apiOverrideBaseUrlstring—Route both token and media requests through your server
rhombusApiBaseUrlstringhttps://api2.rhombussystems.com/apiRhombus API base URL (when not using override)
paths.federatedTokenstring/api/federated-tokenPath to your token endpoint
paths.mediaUrisstring/camera/getMediaUris or /api/media-urisPath for media URI resolution
federatedSessionTokenstring—Skip token fetch; use this token directly
tokenDurationSecnumber86400Token lifetime, in seconds, the SDK requests from your token endpoint; at most 86400
headersobject—Extra headers merged into the token request
getRequestHeaders() => object—Dynamic headers for each request
onError(error: Error) => void—Error callback

RhombusBufferedPlayer props

PropTypeDefaultDescription
bufferedStreamQuality"HIGH" | "MEDIUM" | "LOW""HIGH"Server-side downscale level
applyBufferedStreamQualitybooleantrueSet false to disable quality parameter

RhombusRealtimePlayer props

PropTypeDefaultDescription
connectionMode"wan" | "lan"requiredWAN or LAN media URIs; both append the token as URL query parameters
realtimeStreamQuality"HD" | "SD""HD"Stream resolution; changing reconnects the WebSocket

Troubleshooting

404 on /api/federated-token

Your backend does not have a token endpoint at the expected path. Either implement POST /api/federated-token or set the paths.federatedToken prop to match your route.

CORS errors fetching media URIs

The federated token was generated without a domain matching your app's origin. Pass your app's exact origin (such as https://app.example.com) as the domain parameter when calling generateFederatedSessionToken on your backend.

403 DOMAIN_NOT_ALLOWED, or 401 after the page has been open a while

A 403 DOMAIN_NOT_ALLOWED means the page's origin isn't the token's domain (check scheme, host and port). A 401 means the token expired or was revoked: make sure your endpoint returns expiresAtMs so the SDK renews the token in time.

Realtime player shows nothing

Check browser compatibility — WebCodecs H.264 requires Chrome, Edge, or Safari 16.4+. Check the browser console for [RhombusRealtimePlayer] messages.

LAN mode not authenticating

LAN mode appends the federated token to the WebSocket URL as query parameters (the same as WAN), so it works from any origin including localhost. If LAN mode fails, confirm the browser can reach the camera/NVR host directly (routing, firewall, and HTTPS-vs-HTTP mixed-content rules). If the LAN host is unreachable from the browser, use connectionMode="wan" or proxy through your backend.

Resources