Docs
React SDK

Room object

Use the underlying room for events, metadata, media and cleanup.

Access

React
import { useRoom } from '@relayrtc/react'
 
const { room } = useRoom()

Properties

PropertyPurpose
id, infoRoom ID and server room object.
localParticipantLocal identity and controls.
sessionCurrent participant session.
connectionStateConnection lifecycle.
participantsReadonlyMap of remote participants.
remoteTracksReadonlyMap of remote publications.
microphone, camera, screenLocal capture controls.
devices, permissionsDevice enumeration and permission APIs.
messagessend(text) and subscribe(listener).
eventsemit(name, data) and subscribe(listener) for custom events.
presenceLocal and remote participant snapshot.
quality, qualityStats, participantQualitiesNetwork health and statistics.

Methods

MethodPurpose
on(event, listener)Subscribe to a room event; returns cleanup.
refreshCredentials()Run configured credential refresh callbacks. Returns Promise of void.
leave()Leave this participant’s call. Returns Promise of void.

Example

React
useEffect(() => {
  if (!room) return
  return room.on('participantJoined', (participant) => {
    console.log(participant.name)
  })
}, [room])

Import useEffect from React and clean up listeners when the room changes.

Events

EventsPayload
connectionStateChangedRoomConnectionState.
errorRoomError.
participantJoined, participantLeft, participantUpdatedRoomRemoteParticipant.
participantReconnectedparticipant and session.
localParticipantUpdatedRoomLocalParticipant.
presenceChangedRoomPresenceSnapshot.
trackPublished, trackUnpublished, trackUpdated, trackSubscribed, trackUnsubscribedRoomRemoteTrack.
trackSubscriptionFailedtrack and error.
messageReceived, messageSentRoomTextMessage.
customEventReceived, customEventSentRoomCustomEvent.
connectionQualityChanged, connectionDegraded, connectionRecoveredConnectionQualityEvent.
qualityStatsUpdatedRtcQualityStats.
reconnectAttemptattempt, delayMs and error.
reconnectedattempts and session.
credentialsRefreshedtokenExpiresAt and turnExpiresAt.

Leave versus end

Leave affects only this participant. Ending a room for everyone is a privileged REST/Node operation.

refreshCredentials() requires at least one configured refresh callback. Calling it does not create a token renewal API.