Skip to main content

Overview

The JitsiLocalTrack class represents a single local media track (either audio or video). One JitsiLocalTrack corresponds to one WebRTC MediaStreamTrack captured from the user’s device.

Constructor

constructor(trackInfo: ITrackInfo)
trackInfo
ITrackInfo
required
Object containing track configuration:
  • constraints: The constraints used for creating the track
  • rtcId: The ID assigned by the RTC module
  • stream: The WebRTC MediaStream (parent of the track)
  • track: The underlying WebRTC MediaStreamTrack
  • mediaType: The MediaType (‘audio’ or ‘video’)
  • videoType: The VideoType (‘camera’ or ‘desktop’)
  • effects: Array of effects to be applied
  • deviceId: The ID of the local device
  • facingMode: The camera facing mode (mobile only)
  • sourceId: The Chrome media source ID for desktop sharing
  • sourceType: The type of source the track originates from

Methods

mute()

Asynchronously mutes this track.
mute(): Promise<void>
Promise<void>
Promise
Resolves when the track is successfully muted

unmute()

Asynchronously unmutes this track.
unmute(): Promise<void>
Promise<void>
Promise
Resolves when the track is successfully unmuted

dispose()

Stops sending the media track and removes it from the HTML.
dispose(): Promise<void>
Promise<void>
Promise
Resolves when disposal is complete

isLocal()

Returns true for local tracks.
isLocal(): boolean
isLocal
boolean
Always returns true

isMuted()

Checks if the stream is muted.
isMuted(): boolean
muted
boolean
True if the stream is muted, false otherwise

isEnded()

Returns if the associated MediaStreamTrack is in the ‘ended’ state.
isEnded(): boolean
ended
boolean
True if the track has ended

isReceivingData()

Checks whether the attached MediaStream is receiving data from source.
isReceivingData(): boolean
receiving
boolean
True if the stream is receiving data, false otherwise

getCameraFacingMode()

Returns the camera facing mode for video tracks from camera.
getCameraFacingMode(): CameraFacingMode | undefined
facingMode
CameraFacingMode | undefined
‘user’ or ‘environment’ for camera tracks, undefined for other types

getCaptureResolution()

Returns the capture resolution of the video track.
getCaptureResolution(): number
resolution
number
The capture resolution in pixels

getDeviceId()

Returns the device ID associated with the track.
getDeviceId(): string
deviceId
string
The device identifier

getDuration()

Returns the duration of the track.
getDuration(): number
duration
number
The duration of the track in seconds

getParticipantId()

Returns the participant ID which owns the track.
getParticipantId(): string
participantId
string
The ID of the participant (corresponds to Colibri endpoint ID/MUC nickname)

getSourceName()

Returns the source name associated with the track.
getSourceName(): string | null
sourceName
string | null
The source name identifier

getSsrc()

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

setConference()

Sets the JitsiConference object associated with the track.
setConference(conference: JitsiConference): void
conference
JitsiConference
required
The JitsiConference object to associate with the track

setEffect()

Sets the effect and switches between the modified stream and original one.
setEffect(effect?: IStreamEffect): Promise<void>
effect
IStreamEffect
The effect instance to be used. Pass undefined to remove the current effect
Promise<void>
Promise
Resolves when the effect is successfully applied

setSourceName()

Sets the source name to be used for signaling the track.
setSourceName(name: string): void
name
string
required
The source name to assign

setSsrc()

Sets the primary SSRC for the track.
setSsrc(ssrc: number): void
ssrc
number
required
The SSRC to assign to the track

stopStream()

Stops the associated MediaStream.
stopStream(): void

toString()

Creates a text representation of this local track instance.
toString(): string
string
string
String representation in format: LocalTrack[rtcId,mediaType]

applyConstraints()

Applies media constraints to the current MediaStreamTrack.
applyConstraints(constraints: IAudioConstraints): Promise<void>
constraints
IAudioConstraints
required
Media constraints to apply:
  • autoGainControl: Enable/disable automatic gain control
  • echoCancellation: Enable/disable echo cancellation
  • noiseSuppression: Enable/disable noise suppression
  • channelCount: Number of audio channels
Promise<void>
Promise
Resolves when constraints are successfully applied

onByteSentStatsReceived()

Handles bytes sent statistics (used only for audio tracks to detect audio issues).
onByteSentStatsReceived(tpc: TraceablePeerConnection, bytesSent: number): void
tpc
TraceablePeerConnection
required
The peer connection reporting the bytes sent stat
bytesSent
number
required
The new bytes sent value

Properties

rtcId
number
The ID assigned by the RTC module on instance creation
deviceId
string
The ID of the local device for this track
sourceId
string | undefined
The Chrome media source ID for desktop sharing tracks
sourceType
string | undefined
The type of source the track originates from
resolution
number | undefined
The capture resolution for video tracks
maxEnabledResolution
number | undefined
The maximum enabled resolution for video tracks
metadata
ITrackMetadata
Track metadata including timestamp and display surface information

Events

JitsiLocalTrack extends JitsiTrack and emits additional events:
  • LOCAL_TRACK_STOPPED - Fired when the track stops
  • TRACK_MUTE_CHANGED - Fired when the mute status changes
  • NO_DATA_FROM_SOURCE - Fired when no data is received from the source
  • NO_AUDIO_INPUT - Fired when no audio input is detected

Example Usage

// Mute a local audio track
await localAudioTrack.mute();

// Unmute the track
await localAudioTrack.unmute();

// Apply audio constraints
await localAudioTrack.applyConstraints({
  autoGainControl: true,
  echoCancellation: true,
  noiseSuppression: true
});

// Apply a video effect
await localVideoTrack.setEffect(myVideoEffect);

// Stop and dispose the track
await localVideoTrack.dispose();

Build docs developers (and LLMs) love