Docs
React SDK

RelayProvider

Own the room client and make reactive state available to child hooks.

Import

React
import { RelayProvider } from '@relayrtc/react'

Requirements

Use one provider for each independent room client. Put all room hooks inside it. In Next.js, render the call from a client module.

Props

PropTypeDefaultPurpose
signalingUrlstringRequiredws:// or wss:// URL. No credentials, query or fragment.
childrenReactNodeOptionalYour room and UI.
autoSubscribebooleantrueSubscribe to remote media automatically.
requestTimeoutMsnumber10,000Signaling request timeout, 1–60,000 ms.
iceServersreadonly RTCIceServer[]OptionalAdditional/custom ICE configuration.
iceTransportPolicy'all' or 'relay'allAllow all candidates or require relay.
turnCredentialsTurnCredentialsOptionalInitial TURN response with expiresAt and iceServers.
refreshTurnCredentialsasync callbackOptionalFetch server-issued TURN credentials for the active session.
refreshTokenasync callbackOptionalReturn an identity-preserving replacement token. See expiry limits below.
credentialRefreshMarginMsnumber60,000Refresh margin, 1,000–300,000 ms.
reconnectfalse or objectEnabledSee reconnect options below.
messageHistoryLimitnumber100Integer 0–10,000. Zero disables local history.
onError(error: RoomError) => voidOptionalObserve SDK failures.

Reconnect options

OptionDefaultLimits
maxAttempts6Integer 1–20.
timeoutMs25,000Overall deadline, 1,000–120,000 ms.
initialDelayMs250Nonnegative; no greater than maxDelayMs.
maxDelayMs4,0001–30,000 ms.

Example

React
<RelayProvider
  signalingUrl="ws://localhost:8081/v1/connect"
  autoSubscribe
  messageHistoryLimit={200}
  reconnect={{ maxAttempts: 6, timeoutMs: 25000 }}
  onError={(error) => console.error(error.code, error.message)}
>
  <YourRoom />
</RelayProvider>

YourRoom is your component rendering RelayRoom or calling useRoom().join().

Credential callbacks

Callbacks receive roomId, participantId, sessionId, expiresAt, reason and an AbortSignal. Reason is initial, expiring or manual.

Return credentials from an authenticated backend. Do not expose the management key.

The public token creation API creates a new participant. It cannot supply an identity-preserving refresh token for an ongoing call. See connection recovery.

Lifecycle

Unmounting the provider disposes its store and leaves the room. Treat connection options as configuration for the active client; leave and join again to apply different connection settings.