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.

devices.md

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

Devices

Four hooks. All require FishjamProvider higher in the tree.

useInitializeDevices

Call once on app mount (or on first navigation to a page that needs media). Prompts the browser for camera + mic permissions, enumerates devices, and sets up the persisted last-device.

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

function MediaBootstrap() {
  const { initializeDevices } = useInitializeDevices();

  useEffect(() => {
    initializeDevices({
      enableAudio: true,
      enableVideo: true,
    });
  }, []);

  return null;
}

InitializeDevicesSettings:

  • enableAudio?: boolean — request mic
  • enableVideo?: boolean — request camera

Simulcast layers are configured separately via videoConfig on FishjamProvider — not here. See simulcast-and-bandwidth.md.

This hook can batch camera + microphone permission requests into a single browser popup if both are enabled simultaneously.

Returns an InitializeDevicesResult describing what was granted; status enum (InitializeDevicesStatus) shows progress.

Browser permission prompt timing: this is when the user sees the permission dialog. Trigger off a user gesture if you want predictable UX (don't auto-request on mount in a tab the user just opened — Safari sometimes silently denies).

useCamera

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

const {
  cameraStream,            // MediaStream | null
  isCameraOn,              // boolean
  currentCamera,           // MediaDeviceInfo | null (selected device)
  cameraDevices,           // MediaDeviceInfo[]
  cameraDeviceError,       // DeviceError | null
  toggleCamera,            // () => void
  startCamera,             // () => void
  stopCamera,              // () => void
  selectCamera,            // (deviceId: string) => void
  currentCameraMiddleware, // TrackMiddleware | null
  setCameraTrackMiddleware,// (mw: TrackMiddleware | null) => void
} = useCamera();

Render with:

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

Device switching:

<select onChange={(e) => selectCamera(e.target.value)}>
  {cameraDevices.map((d) => <option key={d.deviceId} value={d.deviceId}>{d.label}</option>)}
</select>

Middleware lets you wrap the raw MediaStreamTrack — for filters, blur, watermarks. See custom-sources.md.

useMicrophone

Same API shape as useCamera but for audio:

const {
  microphoneStream,
  isMicrophoneOn,
  currentMicrophone,
  microphoneDevices,
  microphoneDeviceError,
  toggleMicrophone,
  startMicrophone,
  stopMicrophone,
  selectMicrophone,
  currentMicrophoneMiddleware,
  setMicrophoneTrackMiddleware,
  toggleMicrophoneMute,           // () => void          — toggles track.enabled, keeps publish active
  isMicrophoneMuted,              // boolean             — current mute state
} = useMicrophone();

useScreenShare

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

const {
  startStreaming,             // (constraints?) => Promise<void>
  stopStreaming,              // () => Promise<void>
  stream,                     // MediaStream | null     (combined video + audio)
  videoTrack,                 // MediaStreamTrack | null
  audioTrack,                 // MediaStreamTrack | null (system audio, if user opted in)
  currentTracksMiddleware,    // TracksMiddleware | null
  setTracksMiddleware,        // (mw: TracksMiddleware | null) => Promise<void>
} = useScreenShare();

User gesture required. Call startStreaming inside a click handler — browsers reject getDisplayMedia calls that aren't reacting to a user event.

<button onClick={() => startStreaming()}>Share screen</button>

Pass per-kind constraints to override defaults (e.g. preferring tab capture, including system audio):

await startStreaming({
  videoConstraints: { displaySurface: 'browser' },
  audioConstraints: true,     // ask for system audio
});

Both videoConstraints and audioConstraints accept boolean | MediaTrackConstraints.

Render the combined stream by assigning it to a <video> element's srcObject via a ref (same pattern as useCamera — <video ref={(el) => { if (el) el.srcObject = stream; }} autoPlay playsInline />); JSX won't accept srcObject as a prop. Or grab videoTrack / audioTrack individually if you need to layer them separately. Apply filters / transforms with setTracksMiddleware(...) — distinct from camera middleware because screen share carries two tracks at once. See custom-sources.md.

Device persistence

By default FishjamProvider stores the last-used camera and mic in localStorage. After a page reload, useCamera().currentCamera resolves to the previously-used device automatically — but the browser still needs the user to grant the permission.

Override the storage via persistLastDevice on the provider (see provider.md).

Common errors

cameraDeviceError and microphoneDeviceError are DeviceError | null objects shaped as { name: ... }. Compare on .name:

  • cameraDeviceError?.name === 'NotAllowedError' — user denied permission. Show UI explaining how to re-grant.
  • cameraDeviceError?.name === 'NotFoundError' — no camera attached.
  • cameraDeviceError?.name === 'OverconstrainedError' — requested constraints can't be satisfied.
  • cameraDeviceError?.name === 'UNHANDLED_ERROR' — fallback for anything else.

Same set for microphone.

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