Index of every page on this site: llms.txt
All skills
Run it yourself

Browser-only React SDK for Fishjam — joining rooms, capturing camera/microphone/screen, displaying peers, and acting as a livestream streamer or viewer in a React web app. Use whenever the user is writing a React app in a browser that calls Fishjam APIs, sets up FishjamProvider, or uses any Fishjam React hook. Trigger on: '@fishjam-cloud/react-client', 'FishjamProvider', 'useConnection', 'useCamera', 'useMicrophone', 'useScreenShare', 'usePeers', 'useDataChannel', 'useVAD', 'useLivestreamStreamer', 'useLivestreamViewer', 'useCustomSource', 'useInitializeDevices', 'useUpdatePeerMetadata', 'useSandbox', 'PeerWithTracks', 'joinRoom', 'peerToken', 'fishjamId', 'fishjam react', '@fishjam-cloud/ts-client', 'FishjamClient ts-client'. Covers the provider, the full hook catalog, simulcast configuration, custom sources, data channels, VAD, livestream WHEP playback, device persistence, and reconnection. Briefly notes when to drop down to @fishjam-cloud/ts-client for non-React or worker contexts.

  • 10 files
  • 51.3 KB
  • MIT
  • Updated 6 months ago
  • GitHub
Use this Skill: https://skilld.dev/gh/software-mansion-labs/skills/react-client

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

livestream.md

≈1.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Livestream Hooks

Two hooks, both used outside (not in addition to) the normal useConnection flow:

  • useLivestreamStreamer — broadcast into a livestream room.
  • useLivestreamViewer — consume a livestream via WHEP.

Tokens come from the backend (../js-server-sdk/livestream-and-moq.md → createLivestreamStreamerToken / createLivestreamViewerToken; same for Python in ../python-server-sdk/livestream-and-moq.md), or from the Sandbox API via useSandbox().getSandboxLivestream / getSandboxViewerToken.

useLivestreamStreamer (broadcaster)

Source: @fishjam-cloud/react-client → packages/react-client/src/hooks/useLivestreamStreamer.ts.

import { useLivestreamStreamer, useCamera, useMicrophone } from '@fishjam-cloud/react-client';

const { connect, disconnect, error, isConnected } = useLivestreamStreamer();
const { cameraStream } = useCamera();
const { microphoneStream } = useMicrophone();

const handleStart = async () => {
  await connect({
    inputs: {
      video: cameraStream!,        // MediaStream
      audio: microphoneStream,     // MediaStream | null
    },
    token: streamerToken,           // from backend
  });
};

const handleStop = () => disconnect();

Inputs

type StreamerInputs =
  | { video: MediaStream; audio?: MediaStream | null }
  | { video?: null; audio: MediaStream };

type ConnectStreamerConfig = {
  inputs: StreamerInputs;
  token: string;
};
  • Exactly one video track and exactly one audio track go on the wire — Fishjam picks the first of each from the streams you pass. Extra tracks are silently ignored.
  • Audio-only stream: pass { audio: micStream } without video.
  • You can also publish screen share as the video source: { video: screenShareStream }.

Re-publish

Calling connect again replaces the current publication with the new inputs — useful for switching from camera to screen share without tearing down the connection. Only the latest connect call wins.

Streamer error states

error: LivestreamError | null. The enum (from @fishjam-cloud/ts-client):

  • LivestreamError.UNAUTHORIZED — bad / expired / wrong-role streamer token.
  • LivestreamError.STREAM_NOT_FOUND — the room/stream doesn't exist.
  • LivestreamError.STREAMER_ALREADY_CONNECTED — another streamer is currently publishing into this livestream room.
  • LivestreamError.UNKNOWN_ERROR — fallback for anything else (network, TURN, server).

isConnected flips true once the WebRTC connection state hits connected.

useLivestreamViewer (audience)

Source: @fishjam-cloud/react-client → packages/react-client/src/hooks/useLivestreamViewer.ts.

import { useLivestreamViewer } from '@fishjam-cloud/react-client';

const { stream, connect, disconnect, error, isConnected, getStatistics } = useLivestreamViewer();

// Private livestream — backend-issued viewer token:
await connect({ token: viewerToken });

// Public livestream — just the room ID:
await connect({ streamId: 'room-abc-123' });

ConnectViewerConfig

type ConnectViewerConfig =
  | { token: string;  streamId?: never }
  | { streamId: string; token?: never };

Pass exactly one — TypeScript will complain if you mix.

Rendering

<video
  ref={(el) => { if (el) el.srcObject = stream; }}
  autoPlay
  playsInline
/>

stream populates once the WHEP handshake completes. Until then it's null.

Statistics

const stats: RTCStatsReport | undefined = await getStatistics();

Returns a raw RTCStatsReport from the underlying RTCPeerConnection — use for QoS overlays.

Viewer error states

Same LivestreamError enum as the streamer. Public-livestream-only errors come through error too (e.g. streamId doesn't exist).

Single-track constraint

Livestream rooms accept exactly one video track and one audio track from the streamer. Multiple-camera scenarios aren't supported on livestream — for that, use a conference room.

Public vs private — choosing

Decision lives on the room at creation (fishjam_client.create_room(RoomOptions(room_type='livestream', public=True))). The client side just adapts:

Room is Streamer Viewer
Private (default) streamer token viewer token
Public streamer token room ID

The streamer flow is identical — only the viewer differs.

WHEP / WHIP

Under the hood the streamer uses WHIP (buildLivestreamWhipUrl(fishjamId)) and the viewer uses WHEP (buildLivestreamWhepUrl(fishjamId)). You don't need to know these URLs unless you're integrating with a non-Fishjam WHEP client — in which case the URL is https://<fishjam-host>/api/v1/live/api/whep[/<streamId>] (or .../whip for the streamer). See packages/react-client/src/utils/fishjamUrl.ts for the builder.

Sources

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at 43cde80. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 6 months ago

README badge

README badge for software-mansion-labs/skills/react-client