RelayrtcDocs
Get started
Documentation
React SDK

RelayRoom

Join with a participant token and leave when the component unmounts.

On this page

Import

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

Requirements

Render inside RelayProvider. Only one RelayRoom owns a provider at a time.

Props

PropTypeDefaultPurpose
tokenstring, null or undefinedRequired propToken issued by your backend. Null/undefined waits without joining.
connectbooleantrueEnable the automatic join.
childrenReactNodeOptionalRoom UI; rendered while connecting too.
onConnected(room: Room) => voidOptionalCalled when a new room becomes available.
onDisconnected() => voidOptionalCalled when the previously available room is removed.
onError(error: RoomError) => voidOptionalObserve room errors.

Example

React
import type { ReactNode } from 'react'
 
export function JoinedRoom({ token, children }: { token: string | null; children: ReactNode }) {
  return <RelayRoom
    token={token}
    onConnected={room => console.log('Joined', room.id)}
    onDisconnected={() => console.log('Left')}
  >{children}</RelayRoom>
}

Token changes

Changing the token starts a new join lifecycle. Unmounting cancels an in-flight join and releases room ownership.

Joining does not enable local capture. Call camera or microphone controls after the room is connected.