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.

custom-sources.md

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

Custom Sources & Middleware

Two related features:

  1. useCustomSource — push a MediaStream you created yourself (canvas, file, generated frames) into the room as an additional track.
  2. Track middleware — wrap an existing track (camera / mic / screen share) with a transform before it goes on the wire.

useCustomSource

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

Each call takes a string sourceId — that ID is the identity of one custom source. Use different IDs for different concurrent sources.

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

const { stream, setStream } = useCustomSource('canvas-overlay');

// To publish:
setStream(myCanvasStream);

// To stop:
setStream(null);

setStream is (newStream: MediaStream | null) => Promise<void> — fire-and-forget is fine for most cases, but you can await it if you need to know the previous source's tracks have been removed before continuing.

stream: MediaStream | undefined is the stream you previously set, for read-back.

Generating a stream from a canvas

const canvasRef = useRef<HTMLCanvasElement>(null);
const { setStream } = useCustomSource('canvas-art');

useEffect(() => {
  const stream = canvasRef.current?.captureStream(30); // 30fps
  if (stream) setStream(stream);
  return () => setStream(null);
}, []);

From a <video> element (file playback)

const videoRef = useRef<HTMLVideoElement>(null);
const { setStream } = useCustomSource('intro-clip');

useEffect(() => {
  const v = videoRef.current;
  if (!v) return;
  v.src = '/intro.mp4';
  v.muted = true;
  v.play();
  const stream = (v as any).captureStream?.() ?? (v as any).mozCaptureStream?.();
  setStream(stream);
  return () => setStream(null);
}, []);

Custom-source tracks appear in usePeers() as customVideoTracks / customAudioTracks on the local peer (and remote peers, if others use the same hook). Their metadata.type is 'customVideo' or 'customAudio'.

Track middleware

A middleware wraps a single MediaStreamTrack and returns a transformed one. Used for filters, blur, watermark, color correction.

Types

type TrackMiddleware = ((
  track: MediaStreamTrack,
) => MiddlewareResult | Promise<MiddlewareResult>) | null; // { track: MediaStreamTrack, onClear?: () => void }

type TracksMiddleware = (
  videoTrack: MediaStreamTrack,           // always present for screen share
  audioTrack: MediaStreamTrack | null,    // null when the user didn't share system audio
) => TracksMiddlewareResult | Promise<TracksMiddlewareResult>; // { videoTrack, audioTrack, onClear }

Both signatures may return a Promise — middleware can be async (e.g. waiting for a WebGL context or a worker handshake).

Use TrackMiddleware for camera/mic (one track). Use TracksMiddleware for screen share (which has a video + optional audio together).

Camera blur example

import { useCamera, type TrackMiddleware } from '@fishjam-cloud/react-client';

function applyBlur(track: MediaStreamTrack) {
  // Use a worker or MediaPipe — here as a sketch:
  const blurred = createBlurredTrack(track);   // your impl
  return {
    track: blurred,
    onClear: () => blurred.stop(),
  };
}

const { setCameraTrackMiddleware } = useCamera();

// Turn blur on:
setCameraTrackMiddleware(applyBlur);

// Turn blur off:
setCameraTrackMiddleware(null);

The provider applies the middleware before the track goes on the wire — remote peers see the blurred stream. onClear is called when the middleware is removed or the track changes.

Screen-share middleware

const { setTracksMiddleware } = useScreenShare();

setTracksMiddleware((video, audio) => {
  // `video` is always a MediaStreamTrack; `audio` may be null.
  return { videoTrack: video, audioTrack: audio, onClear: () => {} };
});

// Remove:
setTracksMiddleware(null);

Combining: custom source + middleware

These are orthogonal:

  • Use useCustomSource when the track is yours — you generate the frames.
  • Use middleware when you want to transform an existing track (the SDK's camera/mic/screen share).

For a blur-camera effect, prefer middleware (cleaner; the SDK still owns the track lifecycle). For a "show this animated character instead of my camera", use useCustomSource with a canvas.

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