useRecording
Observe recording capture and finalization through application callbacks.
On this page
useRecording(options) is independent of RelayProvider and RelayRoom. Supply stable callbacks to authenticated application endpoints. Keep management keys on the backend.
Options
| Option | Contract |
|---|---|
getRecording | Required; receives AbortSignal and returns RecordingResource or null. |
start, stop, delete | Optional application commands receiving { signal, idempotencyKey }. |
pollIntervalMs | Integer 1000–60000 milliseconds; default 2500. |
Forward command keys to your backend SDK calls. Callbacks must honor AbortSignal. isRecording is true only for observed recording state; isProcessing indicates finalizing. RecordingIndicator displays state and does not obtain consent. getRecording identity selects the resource; command closures can update without resetting its observed state. Obtain consent before enabling a start action.
Returns
The hook returns recording, pending, error, isRecording, isProcessing, start, stop, delete 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.
import { useRecording, RecordingIndicator } from '@relayrtc/react'
export function RecordingPanel({ options, consent }: {
options: Parameters<typeof useRecording>[0]; consent: boolean
}) {
const capture = useRecording(options)
return <section>
<RecordingIndicator state={capture.recording?.state} />
<button disabled={!consent || !options.start || !!capture.pending}
onClick={() => { void capture.start() }}>Record</button>
<button disabled={!options.stop || !!capture.pending}
onClick={() => { void capture.stop() }}>Stop and finalize</button>
{capture.error && <p role="alert">{capture.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.