LocalTrack is the base class for local audio and video tracks in the Web software development kit (SDK). It is used for local playback and publishing.
The SDK creates various LocalTrack objects and returns instances of its derived classes.
Properties
Property | Type | Description | Minimum supported version |
isPlaying | boolean | Indicates whether the media track is playing. | 3.0.0 |
trackMediaType | The media track type. | 3.0.0 | |
enabled | boolean | The current enabled state of the local track. | 3.0.0 |
muted | boolean | Mute | 3.0.0 |
Methods
API | Description | Minimum supported version |
Gets the media track. | 3.0.0 | |
Gets the stream track ID. | 3.0.0 | |
Plays the media track on the page. | 3.0.0 | |
Replaces the audio or video track. | 3.0.0 | |
Stops playback. | 3.0.0 | |
Destroys the track. | 3.0.0 | |
Removes a listener for a specified event. | 3.0.0 | |
Adds a listener for a specified event. | 3.0.0 | |
Adds a one-time listener for a specified event. The listener is removed after the event is triggered. | 3.0.0 | |
Removes all listeners for a specified event or for all events. | 3.0.0 |
Events
Event | Event parameter | Description | Minimum supported version |
() => void | Triggered when an audio or video track is terminated. This can happen for several reasons: - The camera was unplugged. - The microphone was unplugged. - The user stopped screen sharing. - The user closed the underlying MediaStreamTrack. - A media device failed. - The permission for a media device in use was revoked. | 3.0.0 |
API details
getMediaStreamTrack()
Retrieves the media track.
Type signature
getMediaStreamTrack(): MediaStreamTrack;
Returns
MediaStreamTrack
The media track.
getTrackId()
Retrieves the stream track ID.
Type signature
getTrackId(): string;
Back
string
The stream track ID.
play()
Plays the media track on the page.
Type signature
play(element?: string | HTMLElement, config?: VideoPlayerConfig): void;
Parameters
Parameter | Type | Description |
element | string | HTMLElement | (Optional) Specifies a DOM element where the SDK creates a video element to play the video track. Two types are supported: - string: The ID of the DOM element. - HTMLElement: Pass a DOM element directly. |
config | (Optional) The video media playback parameters. |
Returns
void
replaceTrack()
Replaces the audio or video track.
Type signature
replaceTrack(track: MediaStreamTrack, stopOldTrack?: boolean): void;
Parameter | Type | Description |
track | MediaStreamTrack | Audio and video tracks |
stopOldTrack | boolean | (Optional) Specifies whether to stop the previous track. |
Back
void
stop()
Stops playback.
Type signature
stop(): void;
Returns
void
close()
Closes the local track and releases the associated capture devices.
Once a local track is closed, it cannot be reused. To use it again, you must create a new local track.
Type signature
close(): void;
Returns
void
getTrackLabel()
Retrieves the source description of the local track.
Type signature
getTrackLabel(): string;
Returns
string
The audio or video track description.
setDevice()
Updates the media device used by the track.
Type signature
setDevice(deviceId: string): Promise<void>;
Parameters
Parameter | Parameter | Description |
deviceId | string | The device ID. |
Returns
Promise<void>
setEnabled()
Enables or disables the track.
When a track is disabled, playback and publishing stop. If the track is already published, calling `setEnabled` triggers the `user-info-updated` event on the remote client.
Type signature
setEnabled(enabled: boolean): Promise<void>;
Parameters
Parameter | Parameter | Description |
enabled | boolean | Specifies whether to enable the track. - true: Enable the track. - false: Disable the track. |
Returns
Promise<void>
setMuted()
Send or pause the media data for the track.
If the track is already published, calling `setMuted` triggers the `user-info-updated` event on the remote client.
Type signature
setMuted(muted: boolean): Promise<void>;
Parameters
Parameter | Parameter | Description |
muted | boolean | Specifies whether to mute the track's media data. - true: Stop sending media data. - false: Resume sending media data. |
Returns
Promise<void>
on()
You can add a listener for a specified event.
Type signature
on(event: string, fn: Function): void;
Parameters
Parameter | Type | Description |
event | string | The event to listen for. |
fn | Function | The callback function to run when the event is triggered. |
Back
void
off()
You can remove a listener for a specified event.
Type signature
off(event: string, fn: Function): void;
Parameters
Parameter | Type | Description |
event | string | The event to listen for. |
fn | Function | The callback function to run when the event is triggered. |
Returns
void
once()
Adds a listener that is triggered only once for a specified event.
Type signature
once(event: string, fn: Function): void;
Parameters
Parameter | Type | Description |
event | string | The event to listen for. |
fn | Function | The callback function to run when the event is triggered. |
Back
void
removeAllListeners()
Removes all listeners for a specified event or all events.
Type signature
removeAllListeners(event?: string): void;
Parameters
Parameter | Type | Description |
event | string | (Optional) The event for which to remove listeners. If you specify an event, all listeners for that event are removed. If you omit this parameter, all listeners for all events on the object are removed. |
Back
void
Events
"track-ended"
Occurs when an audio or video track is terminated. This can happen for several reasons:
- The camera is unplugged.
- The microphone was unplugged.
- The user stopped screen sharing.
- The user has closed the underlying MediaStreamTrack.
- A media device has failed.
- The permission for a media device was revoked while it was in use.
Type signature:
'track-ended': () => void;