RelayrtcDocs
Get started
Documentation
React SDK

useMixer

Observe requested and applied program revisions separately from scene editing.

On this page

useMixer(options) is independent of RelayProvider and RelayRoom. Supply stable callbacks to authenticated application endpoints. Keep management keys on the backend.

Options

OptionContract
getMixerRequired; receives AbortSignal and returns MixerResource or null.
activateScene, stopOptional application commands receiving { signal, idempotencyKey }.
pollIntervalMsInteger 1000–60000 milliseconds; default 2500.

Forward command keys to your backend SDK calls. Callbacks must honor AbortSignal. getOperation optionally receives an operation ID and AbortSignal and returns MixerOperation. Command callbacks return MixerCommandResult, not just a mixer. isApplied means a positive desiredVersion matches appliedVersion; a degraded program can still have an applied scene. Saving scenes is a separate backend operation. Bind an immutable saved scene/version to each activation attempt.

Returns

The hook returns mixer, operation, pending, error, isLive, isApplied, activateScene, stop and refresh. pending covers the application request, not completion of asynchronous server work. Errors are sanitized in the snapshot.

Example

The parent supplies memoized options bound to one selected resource.

React
import { useMixer } from '@relayrtc/react'
 
export function MixerPanel({ options }: { options: Parameters<typeof useMixer>[0] }) {
  const studio = useMixer(options)
  return <section>
    <p>Requested {studio.mixer?.desiredVersion ?? 0}; applied {studio.mixer?.appliedVersion ?? 0}</p>
    <button disabled={!options.activateScene || !!studio.pending || studio.operation?.status === 'pending'}
      onClick={() => { void studio.activateScene() }}>Activate saved scene</button>
    {studio.error && <p role="alert">{studio.error.message}</p>}
  </section>
}

Lifecycle and retries

Unmounting stops polling and aborts outstanding callbacks. Status revisions prevent stale polling from overwriting a newer command result. An uncertain command retains its idempotency key; retry the same action/payload rather than reusing it for another resource. HTTP cancellation does not undo committed server work.

See the workflow for backend setup, retention and authorization. The browser SDK exposes the corresponding client without React.