useTracks
Filter reactive remote track publications.
On this page
Import
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
| Field | Type | Meaning |
|---|---|---|
| Return value | readonly RoomRemoteTrack[] | Remote publications matching the filter. |
Example
export function CameraCount({ participantId }: { participantId: string }) {
const cameras = useTracks({ participantId, types: ['camera_video'], subscribedOnly: false })
return <p>{cameras.length} camera publications</p>
}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.