Skip to main content

Overview

The JitsiTrack class represents a single media track (either audio or video). It serves as the base class for both JitsiLocalTrack and JitsiRemoteTrack.

Constructor

constructor(
  conference: JitsiConference,
  stream: MediaStream,
  track: MediaStreamTrack,
  streamInactiveHandler: MediaStreamTrackEventHandler,
  trackMediaType: MediaType,
  videoType?: VideoType
)
conference
JitsiConference
required
The conference instance this track belongs to
stream
MediaStream
required
The WebRTC MediaStream instance
track
MediaStreamTrack
required
The WebRTC MediaStreamTrack instance (must be part of the stream)
streamInactiveHandler
Function
required
Handler for onended/oninactive events of the stream
trackMediaType
MediaType
required
The media type of the track (‘audio’ or ‘video’)
videoType
VideoType
The video type for video tracks (‘camera’ or ‘desktop’)

Methods

attach()

Attaches the MediaStream of this track to an HTML container.
attach(container: HTMLElement): Promise<void>
container
HTMLElement
required
The HTML container (‘video’ or ‘audio’ element) to attach to
Promise<void>
Promise
Resolves when the track is successfully attached

detach()

Removes this JitsiTrack from the HTML container.
detach(container?: HTMLElement): void
container
HTMLElement
The HTML container to detach from. If not specified, detaches from all containers

dispose()

Removes attached event listeners and cleans up resources.
dispose(): Promise<void>
Promise<void>
Promise
Resolves when disposal is complete

getId()

Returns the ID of the track.
getId(): string | null
id
string | null
The track ID or null if this is a fake track

getOriginalStream()

Returns the WebRTC MediaStream instance.
getOriginalStream(): MediaStream
stream
MediaStream
The underlying WebRTC MediaStream

getSourceName()

Returns the source name of the track.
getSourceName(): string | undefined
sourceName
string | undefined
The source name identifier

getSsrc()

Returns the primary SSRC associated with the track.
getSsrc(): number | undefined
ssrc
number | undefined
The synchronization source identifier

getStreamId()

Returns the ID of the underlying WebRTC MediaStream.
getStreamId(): string | null
streamId
string | null
The MediaStream ID

getTrack()

Returns the underlying WebRTC MediaStreamTrack.
getTrack(): MediaStreamTrack
track
MediaStreamTrack
The underlying MediaStreamTrack

getTrackId()

Returns the ID of the underlying WebRTC MediaStreamTrack.
getTrackId(): string | null
trackId
string | null
The MediaStreamTrack ID

getTrackLabel()

Returns the label of the underlying WebRTC MediaStreamTrack.
getTrackLabel(): string
label
string
The track label (e.g., device name)

getType()

Returns the type (audio or video) of this track.
getType(): MediaType
type
MediaType
Either ‘audio’ or ‘video’

getUsageLabel()

Returns a meaningful usage label for this track.
getUsageLabel(): string
label
string
‘mic’ for audio tracks, or the video type (‘camera’, ‘desktop’) for video tracks

getVideoType()

Returns the video type of this track.
getVideoType(): VideoType | undefined
videoType
VideoType | undefined
‘camera’ or ‘desktop’ for video tracks, undefined for audio

getHeight()

Returns the height of the track in normalized landscape format.
getHeight(): number
height
number
The minimum of track height and width (normalized)

getWidth()

Returns the width of the track in normalized landscape format.
getWidth(): number
width
number
The maximum of track height and width (normalized)

isActive()

Checks whether the MediaStream is active/not ended.
isActive(): boolean
active
boolean
True if the MediaStream is active, false otherwise

isAudioTrack()

Checks if this is an audio track.
isAudioTrack(): boolean
isAudio
boolean
True if this is an audio track

isVideoTrack()

Checks if this is a video track.
isVideoTrack(): boolean
isVideo
boolean
True if this is a video track

isLocal()

Checks whether this is a local track.
isLocal(): boolean
isLocal
boolean
True if it’s a local track, false otherwise

isLocalAudioTrack()

Checks whether this is a local audio track.
isLocalAudioTrack(): boolean
isLocalAudio
boolean
True if this is a local audio track

isMuted()

Checks whether this track is muted.
isMuted(): boolean
muted
boolean
True if the track is muted

setAudioLevel()

Sets the audio level for the stream.
setAudioLevel(audioLevel: number, tpc?: TraceablePeerConnection): void
audioLevel
number
required
Value between 0 and 1
tpc
TraceablePeerConnection
The peer connection instance which is the source for the audio level

setAudioOutput()

Sets a new audio output device for track’s DOM elements.
setAudioOutput(audioOutputDeviceId: string): Promise<void>
audioOutputDeviceId
string
required
ID of ‘audiooutput’ device from navigator.mediaDevices.enumerateDevices(), or ” for default device
Promise<void>
Promise
Resolves when the audio output device is changed successfully

setSourceName()

Assigns the source name to a track.
setSourceName(name: string): void
name
string
required
The name to be assigned to the track

Properties

disposed
boolean
Indicates whether this JitsiTrack has been disposed. If true, the track is unusable
conference
JitsiConference
The conference instance this track belongs to
videoType
VideoType | undefined
The video type (‘camera’ or ‘desktop’) for video tracks
containers
HTMLElement[]
Array of HTML elements that are displaying the track

Events

JitsiTrack extends the Listenable class and emits various events:
  • TRACK_AUDIO_LEVEL_CHANGED - Fired when audio level changes
  • TRACK_AUDIO_OUTPUT_CHANGED - Fired when audio output device changes
  • NO_AUDIO_INPUT - Fired when no audio input is detected

Build docs developers (and LLMs) love