Docs
React SDK

useTracks

Filter reactive remote track publications.

Import

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

Requirements

Call this hook inside RelayProvider, in a React function component or custom hook. A joined room is needed for live data and actions.

Returns

FieldTypeMeaning
Return valuereadonly RoomRemoteTrack[]Remote publications matching the filter.

Example

React
const cameras = useTracks({
  participantId,
  types: ['camera_video'],
  subscribedOnly: false,
})

Options and behavior

Options: participantId filters by participant; types filters by track type; subscribedOnly defaults to false. Available runtime media types are audio, camera_video, screen_video and screen_audio. This hook does not return your local capture tracks. Keeping unsubscribed tracks in the list lets a playback component show its loading state.