RelayrtcDocs
Get started
Documentation
React SDK

Types

Public hook results, media snapshots and browser room types.

On this page

Import

React
import type { RoomRemoteTrack, UseTracksOptions } from '@relayrtc/react'
 
const options: UseTracksOptions = { types: ['camera_video'] }
 
function trackLabel(track: RoomRemoteTrack) {
  return `${track.participantId}: ${track.type}`
}

These types are exported from @relayrtc/react. The definitions below use supporting names from the browser SDK, protocol and React. You only need to import the public types your application uses.

RelayParticipant

See useParticipants for behavior, defaults and an example.

TypeScript
export type RelayParticipant = RoomLocalParticipant | RoomRemoteParticipant

RelayProviderProps

See RelayProvider for behavior, defaults and an example.

TypeScript
export interface RelayProviderProps extends RelayClientOptions {
  readonly children?: ReactNode
  readonly messageHistoryLimit?: number
  readonly onError?: (error: RoomError) => void
}

RelayRoomProps

See RelayRoom for behavior, defaults and an example.

TypeScript
export interface RelayRoomProps {
  readonly children?: ReactNode
  readonly token: string | null | undefined
  readonly connect?: boolean
  readonly onConnected?: (room: Room) => void
  readonly onDisconnected?: () => void
  readonly onError?: (error: RoomError) => void
}

UseRoomResult

See useRoom for behavior, defaults and an example.

TypeScript
export interface UseRoomResult {
  readonly room: Room | null
  readonly client: RelayClient | null
  readonly connectionState: RoomConnectionState
  readonly error: RoomError | null
  readonly join: (token: string, options?: JoinOptions) => Promise<Room>
  readonly leave: () => Promise<void>
  readonly clearError: () => void
}

UseParticipantsOptions

See useParticipants for behavior, defaults and an example.

TypeScript
export interface UseParticipantsOptions {
  readonly includeLocal?: boolean
}

UseTracksOptions

See useTracks for behavior, defaults and an example.

TypeScript
export interface UseTracksOptions {
  readonly participantId?: string
  readonly types?: readonly RoomRemoteTrack['type'][]
  readonly subscribedOnly?: boolean
}

UseMessagesResult

See useMessages for behavior, defaults and an example.

TypeScript
export interface UseMessagesResult {
  readonly messages: readonly RoomTextMessage[]
  readonly send: (text: string) => Promise<RoomTextMessage>
  readonly clear: () => void
}

UseConnectionQualityResult

See useConnectionQuality for behavior, defaults and an example.

TypeScript
export interface UseConnectionQualityResult {
  readonly quality: Room['quality']
  readonly stats: Room['qualityStats']
  readonly participantQualities: Room['participantQualities']
}

UseLocalMediaResult

See useLocalMedia for behavior, defaults and an example.

TypeScript
export interface UseLocalMediaResult {
  readonly microphone: RoomInputSnapshot | null
  readonly camera: RoomInputSnapshot | null
  readonly screen: RoomScreenSnapshot | null
}

MediaPlaybackState

See useMediaTrack for behavior, defaults and an example.

TypeScript
export type MediaPlaybackState = 'idle' | 'loading' | 'playing' | 'paused' | 'blocked' | 'failed' | 'ended'

UseMediaTrackOptions

See useMediaTrack for behavior, defaults and an example.

TypeScript
export interface UseMediaTrackOptions {
  readonly enabled?: boolean
  readonly paused?: boolean
}

UseMediaTrackResult

See useMediaTrack for behavior, defaults and an example.

TypeScript
export interface UseMediaTrackResult {
  readonly ref: RefCallback<HTMLMediaElement>
  readonly state: MediaPlaybackState
  readonly isLoading: boolean
  readonly isPaused: boolean
  readonly error: Error | null
  readonly play: () => Promise<void>
}

MediaLoaderProps

See MediaLoader for behavior, defaults and an example.

TypeScript
export interface MediaLoaderProps extends HTMLAttributes<HTMLDivElement> {
  readonly label?: string
}

RtcQualityStats

See useConnectionQuality for behavior, defaults and an example.

TypeScript
export interface RtcQualityStats {
  readonly availableIncomingBitrate: number | null;
  readonly availableOutgoingBitrate: number | null;
  readonly bytesReceived: number;
  readonly bytesSent: number;
  readonly jitter: number | null;
  readonly packetsLost: number;
  readonly packetsReceived: number;
  readonly roundTripTime: number | null;
  readonly timestamp: number;
  readonly incomingBitrate?: number | null;
  readonly outgoingBitrate?: number | null;
  readonly packetLossRatio?: number | null;
  readonly stale?: boolean;
  readonly streams?: readonly RtcStreamStats[];
  readonly selectedCandidatePairId?: string | null;
  readonly localCandidateType?: string | null;
  readonly remoteCandidateType?: string | null;
  readonly candidateProtocol?: string | null;
}

RoomErrorCode

See RoomError for behavior, defaults and an example.

TypeScript
export type RoomErrorCode = "QUALITY_STATS_FAILED" | MediaErrorCode | "MEDIA_OPERATION_PENDING" | "MEDIA_OPERATION_CANCELLED" | "MEDIA_NOT_ENABLED" | "MEDIA_PUBLISH_FAILED" | "MEDIA_SUBSCRIBE_FAILED" | "INVALID_PAYLOAD" | "PAYLOAD_TOO_LARGE" | "TOKEN_REFRESH_FAILED" | "TURN_REFRESH_FAILED" | "TURN_CREDENTIALS_EXPIRED" | "CREDENTIALS_REVOKED" | "RECONNECT_FAILED" | "ICE_CONNECTION_LOST" | "ICE_RECOVERY_FAILED" | "MEDIA_RUNTIME_LOST" | "INVALID_CONFIGURATION" | "INVALID_TOKEN" | "ALREADY_JOINED" | "JOIN_CANCELLED" | "NOT_CONNECTED" | "CONNECTION_FAILED" | "CONNECTION_CLOSED" | "REQUEST_TIMEOUT" | "PROTOCOL_ERROR" | "SERVICE_UNAVAILABLE" | "PERMISSION_DENIED" | "RESOURCE_NOT_FOUND" | "SESSION_CONFLICT" | "RATE_LIMITED" | "AUTHENTICATION_FAILED" | "TOKEN_EXPIRED" | "ROOM_ENDED" | "RTC_STATE_CHANGED" | "POLICY_VIOLATION" | "PARTICIPANT_REMOVED" | "RTC_SETUP_FAILED";

RoomInputSnapshot

See useLocalMedia for behavior, defaults and an example.

TypeScript
export interface RoomInputSnapshot {
  readonly source: MediaSourceKind;
  readonly enabled: boolean;
  readonly pending: boolean;
  readonly muted: boolean;
  readonly deviceId: string | null;
  readonly track: MediaStreamTrack | null;
  readonly publication: Track | null;
}

RoomScreenSnapshot

See useLocalMedia for behavior, defaults and an example.

TypeScript
export interface RoomScreenSnapshot extends ScreenShareSnapshot {
  readonly pending: boolean;
  readonly muted: boolean;
  readonly videoPublication: Track | null;
  readonly audioPublication: Track | null;
}

RoomLocalParticipant

See useLocalParticipant for behavior, defaults and an example.

TypeScript
export interface RoomLocalParticipant extends Participant, RoomLocalMedia {
  updateMetadata(metadata: Metadata): Promise<Participant>;
}

RoomTextMessage

See useMessages for behavior, defaults and an example.

TypeScript
export type RoomTextMessage = TextMessagePayload;

RoomRemoteTrack

See remote-tracks for behavior, defaults and an example.

TypeScript
export interface RoomRemoteTrack {
  readonly id: string;
  readonly info: Track;
  readonly participantId: string;
  readonly type: Track["type"];
  readonly subscriptionState: RemoteTrackSubscriptionState;
  readonly mediaStreamTrack: MediaStreamTrack | null;
  readonly stream: MediaStream | null;
  subscribe(): Promise<MediaStreamTrack>;
  unsubscribe(): Promise<void>;
  setQuality(quality: VideoQualityPreference): Promise<void>;
  attach(element: HTMLMediaElement): Promise<HTMLMediaElement>;
  detach(element?: HTMLMediaElement): void;
}

RoomRemoteParticipant

See useParticipants for behavior, defaults and an example.

TypeScript
export interface RoomRemoteParticipant extends Participant {
  readonly tracks: ReadonlyMap<string, RoomRemoteTrack>;
}

RoomConnectionState

See useRoom for behavior, defaults and an example.

TypeScript
export type RoomConnectionState =
  "connecting" | "connected" | "reconnecting" | "disconnected" | "failed";

MediaTransportStats

One send or receive transport observation from room.getMediaConnectionStats(). Exported by both @relayrtc/client and @relayrtc/react.

TypeScript
export interface MediaTransportStats {
  readonly direction: "send" | "receive";
  readonly state: RTCPeerConnectionState;
  readonly route: "direct" | "relay" | "unknown";
  readonly protocol: string | null;
  readonly relayProtocol: string | null;
  readonly bytesSent: number;
  readonly bytesReceived: number;
}

route reflects the selected ICE pair when connected. protocol is the candidate protocol; relayProtocol describes the browser-to-TURN transport when available. Either protocol can be null. An unknown route or zero byte counter without a selected pair is not proof that no traffic occurred.

MediaConnectionStats

A snapshot for the local client's media transports. Exported by both @relayrtc/client and @relayrtc/react.

TypeScript
export interface MediaConnectionStats {
  readonly observedAt: string;
  readonly transports: readonly MediaTransportStats[];
}

observedAt is the ISO timestamp at which the SDK completed the observation. Snapshots do not update automatically; request another snapshot for a new reading.

RoomEvents

See room for behavior, defaults and an example.

TypeScript
export interface RoomEvents {
  readonly connectionQualityChanged: ConnectionQualityEvent;
  readonly connectionDegraded: ConnectionQualityEvent;
  readonly connectionRecovered: ConnectionQualityEvent;
  readonly qualityStatsUpdated: RtcQualityStats;
  readonly connectionStateChanged: RoomConnectionState;
  readonly error: RoomError;
  readonly messageReceived: RoomTextMessage;
  readonly messageSent: RoomTextMessage;
  readonly customEventReceived: RoomCustomEvent;
  readonly customEventSent: RoomCustomEvent;
  readonly localParticipantUpdated: RoomLocalParticipant;
  readonly presenceChanged: RoomPresenceSnapshot;
  readonly credentialsRefreshed: RoomCredentialSnapshot;
  readonly reconnectAttempt: {
    readonly attempt: number;
    readonly delayMs: number;
    readonly error: RoomError;
  };
  readonly reconnected: { readonly attempts: number; readonly session: ParticipantSession };
  readonly participantJoined: RoomRemoteParticipant;
  readonly participantLeft: RoomRemoteParticipant;
  readonly participantUpdated: RoomRemoteParticipant;
  readonly participantReconnected: {
    readonly participant: RoomRemoteParticipant;
    readonly session: ParticipantSession;
  };
  readonly trackPublished: RoomRemoteTrack;
  readonly trackUnpublished: RoomRemoteTrack;
  readonly trackUpdated: RoomRemoteTrack;
  readonly trackSubscribed: RoomRemoteTrack;
  readonly trackUnsubscribed: RoomRemoteTrack;
  readonly trackSubscriptionFailed: { readonly track: RoomRemoteTrack; readonly error: RoomError };
}

Room

See room for behavior, defaults and an example.

TypeScript
export interface Room extends RoomLocalMedia {
    readonly quality: ConnectionQuality | null;
    readonly qualityStats: RtcQualityStats | null;
    readonly participantQualities: ReadonlyMap<string, ConnectionQualityEvent>;
    readonly id: string;
    readonly info: RoomInfo;
    readonly localParticipant: RoomLocalParticipant;
    readonly session: ParticipantSession;
    readonly connectionState: RoomConnectionState;
    readonly participants: ReadonlyMap<string, RoomRemoteParticipant>;
    readonly remoteTracks: ReadonlyMap<string, RoomRemoteTrack>;
    readonly messages: RoomMessages;
    readonly events: RoomCustomEvents;
    readonly presence: RoomPresenceSnapshot;
    refreshCredentials(): Promise<void>;
    getMediaConnectionStats(): Promise<MediaConnectionStats>;
    on<Event extends keyof RoomEvents>(event: Event, listener: (value: RoomEvents[Event]) => void): () => void;
    leave(): Promise<void>;
}

RelayClientOptions

See RelayProvider for behavior, defaults and an example.

TypeScript
export interface RelayClientOptions extends RoomCredentialOptions {
    readonly signalingUrl: string;
    readonly requestTimeoutMs?: number;
    readonly iceServers?: readonly RTCIceServer[];
    readonly iceTransportPolicy?: RTCIceTransportPolicy;
    readonly autoSubscribe?: boolean;
    /** Default true. Broadcast stages may opt into one full-resolution video layer. */
    readonly videoSimulcast?: boolean;
    readonly reconnect?: false | RoomReconnectOptions;
}

JoinOptions

See useRoom for behavior, defaults and an example.

TypeScript
export interface JoinOptions {
  readonly signal?: AbortSignal;
}

MediaPermissionsSnapshot

See devices for behavior, defaults and an example.

TypeScript
export interface MediaPermissionsSnapshot {
  readonly microphone: MediaPermissionState;
  readonly camera: MediaPermissionState;
}

MediaPermissionRequest

See devices for behavior, defaults and an example.

TypeScript
export interface MediaPermissionRequest {
  readonly microphone?: boolean;
  readonly camera?: boolean;
}

MediaInputDevice

See devices for behavior, defaults and an example.

TypeScript
export interface MediaInputDevice {
  readonly deviceId: string;
  readonly groupId: string;
  readonly kind: MediaInputKind;
  readonly label: string;
}

MediaDeviceSnapshot

See devices for behavior, defaults and an example.

TypeScript
export interface MediaDeviceSnapshot {
  readonly microphones: readonly MediaInputDevice[];
  readonly cameras: readonly MediaInputDevice[];
}

StreamPlaybackReadiness

Matching React SDK builds re-export StreamPlaybackReadiness from the browser client. Its fields are status, publisherConnected, sourceProducing, outputStarting, viewerReady, code and checkedAt. Playback metadata defines each observation.

StreamPlaybackMetadata.sourceState and readiness are optional for application-owned playback callbacks. The API's stream endpoint supplies them, but a callback can return a smaller supported metadata object. They do not require joining an RTC room.

TypeScript
import type { StreamPlaybackMetadata } from '@relayrtc/react'
 
function isViewerReady(playback: StreamPlaybackMetadata) {
  return playback.readiness?.viewerReady ?? false
}
FieldValues
Track typeaudio, camera_video, screen_video, screen_audio; data is reserved and not supported for room media.
Subscription stateunsubscribed, subscribing, subscribed, failed, closed
Receive video preferenceauto, 1080p, 720p, 360p, audio-only
Connection qualityexcellent, good, poor, critical, lost
Permission stategranted, denied, prompt, unsupported

Quality statistics use seconds for round-trip time and jitter, and bits per second for bitrates. Browser-specific values can be null. See connection quality.

Additional public types

The package root also exports the following contracts. Import only the types your application needs. Callback contracts describe application endpoints. Re-exported room and media types come from the browser SDK; they do not grant management authority.

Hls playback config

ExportContract
HlsPlaybackConfiglowLatencyMode, liveSyncMode, backBufferLength, maxBufferLength, maxMaxBufferLength, liveSyncDuration, liveMaxLatencyDuration, and additional fields.
LivePlaybackOptionsliveSyncDuration, liveMaxLatencyDuration, maxLiveSyncPlaybackRate, liveSyncOnStallIncrease.

Broadcast client

See the broadcast client contract for field requirements, defaults and errors.

ExportContract
BroadcastClientOptionsgetBroadcast, getOutputs, getOperation, start, stop, retryOutput, pollIntervalMs.
BroadcastStatusid, streamId, state, version, sourceSessionId, sourceGeneration, lastError.
BroadcastOutputStatusid, broadcastId, kind, destinationId, destinationName, outputSeconds, bytes, and additional fields.
BroadcastOperationStatusid, status, errorCode.
BroadcastSnapshotbroadcast, outputs, operation, pending, pendingOutputId, error.
BroadcastState"created" | "waiting_for_source" | "starting" | "live" | "reconnecting" | "degraded" | "stopping" | "stopped" | "failed"

Broadcast

See the broadcast contract for field requirements, defaults and errors.

ExportContract
BroadcastPlayerPropsmode, source, createHlsEngine, onPlaybackState.

Stream playback

ExportContract
StreamPlaybackOptionsmode, getPlayback, getGrant, pollIntervalMs.
StreamPlaybackGranturl, expiresAt, token.
StreamPlaybackSnapshotplayback, grant, error.
HlsEngineFactory(media: HTMLVideoElement, url: string, onError: () => void, onReady: () => void) => () => void
BroadcastPlaybackState"loading" | "playing" | "paused" | "blocked" | "unavailable" | "unsupported" | "error"

Room credentials

ExportContract
CredentialRefreshContextroomId, participantId, sessionId, expiresAt, reason, signal.

Restream client

See the restream client contract for field requirements, defaults and errors.

ExportContract
RestreamSourceOptionsgetSource, command, pollIntervalMs.
RestreamSourceSnapshotsource, pending, error.

Restream

See the restream contract for field requirements, defaults and errors.

ExportContract
RestreamSourceid, streamId, projectId, environmentId, name, protocol, host, and additional fields.
RestreamDetailsession, health, usage.
RestreamProtocol"hls_pull" | "rtmp_push" | "whip_push"
RestreamState"created" | "probing" | "ready" | "connecting" | "live" | "recovering" | "stopped" | "failed"

Dvr

See the dvr contract for field requirements, defaults and errors.

ExportContract
DvrPlaybackstreamId, broadcastId, windowId, sourceSessionId, generation, state, capture, and additional fields.
DvrPolicyenabled, durationSeconds, maxBytes, endedRetentionSeconds, consentAcknowledged.
DvrPolicyResourcepolicy, version, effective.

Dvr playback

See the dvr playback contract for field requirements, defaults and errors.

ExportContract
DvrPlaybackStatestart, end, position, behindLiveSeconds, isLive, paused, available, and additional fields.

Stream guest client

ExportContract
StreamGuestOptionsgetStatus, command, getJoinGrant, rtcOptions, pollIntervalMs.
StreamGuestSnapshotroster, room, activeGuestId, pending, error.
StreamGuestCommand"invite" | "requestJoin" | "acceptInvite" | "declineInvite" | "cancelInvite" | "approveRequest" | "rejectRequest" | "mute" | "remove" | "leave"

Guest

See the guest contract for field requirements, defaults and errors.

ExportContract
GuestResourceid, kind, state, version, name, media, mutedAudio, and additional fields.
GuestStageenabled, version, maxGuests, occupied, layout, roomId.
GuestRosterdata, nextCursor, stage.
GuestJoinGranttoken, participantId, roomId, expiresAt, version, media, signalingUrl.
GuestMediaaudio, video, screen.

Use live streaming to select the relevant workflow. Exact method inputs and results appear on the resource pages; limits and validation remain authoritative on the API.