Overview
A Track represents a stream of information, whether it's audio, video or custom data. By default, a participant in a room may publish tracks, such as their camera or microphone streams and subscribe to one or more tracks published by other participants. In order to model a track which may not be subscribed to by the local participant, all track objects have a corresponding TrackPublication object:
Track: a wrapper around the native WebRTCMediaStreamTrack, representing a playable track.TrackPublication: a track that's been published to the server. If the track is subscribed to by the local participant and available for playback locally, it has a.trackattribute representing the associatedTrackobject.
You can list and manipulate tracks (via track publications) published by other participants, even if the local participant is not subscribed to them.
TrackPublication fields
A TrackPublication contains information about its associated track:
| Field | Type | Description |
|---|---|---|
| SID | string | A UID for this particular track, generated by LiveKit server. |
| kind | Track. Kind | The type of track, whether it be audio, video or arbitrary data. |
| source | Track. Source | Source of media: Camera, Microphone, ScreenShare, or ScreenShareAudio. |
| name | string | The name given to this particular track when initially published. |
| subscribed | bool | Indicates whether or not this track has been subscribed to by the local participant. |
| track | Track | If the local participant is subscribed, the associated Track object representing a WebRTC track. |
| muted | bool | Whether this track is muted or not by the local participant. While muted, it won't receive new bytes from the server. |
Track subscription
When a participant is subscribed to a track (which hasn't been muted by the publishing participant), they continuously receive its data. If the participant unsubscribes, they stop receiving media for that track and may resubscribe to it at any time.
When a participant creates or joins a room, the autoSubscribe option is set to true by default. This means the participant automatically subscribes to all existing tracks being published and any track published in the future. For more fine-grained control over track subscriptions, you can set autoSubscribe to false and instead use selective subscriptions.
For most use cases, muting a track on the publisher side or unsubscribing from it on the subscriber side is typically recommended over unpublishing it. Publishing a track requires a negotiation phase and consequently has worse time-to-first-byte performance.