LocalTrack

Updated at:

LocalTrack is the base class for local audio and video tracks in the Electron software development kit (SDK). This class is used for local playback and publishing. The SDK creates various LocalTrack objects and returns the corresponding derived class objects.

Properties

Property

Type

Description

Minimum supported version

deviceId

string

Gets the device ID.

1.0.0

isPlaying

boolean

Indicates whether the media track is playing.

1.0.0

API List

Interface

Description

Minimum supported version

getTrackId()

Gets the stream track ID.

1.0.0

getTrackLabel()

Gets the track name.

1.0.0

setDevice()

Updates the media device that the track uses.

1.0.0

setMuted()

Sends or stops sending media data for the track.

If the track is published, calling setMuted(true) triggers the user-unpublished event on the remote end. Calling setMuted(false) then triggers the user-published event.

1.0.0

off()

Removes a listener for a specified event.

1.0.0

on()

Registers a listener for a specified event.

1.0.0

once()

Registers a one-time listener for a specified event. The listener is removed after the event is triggered.

1.0.0

removeAllListeners()

Removes listeners for a specified event or all events.

1.0.0

Events

Event

Event parameters

Description

Minimum supported version

"track-ended"

() => void

The audio or video track is stopped. Possible reasons include the following:

- The camera is unplugged.

- The microphone is 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.

1.0.0

Method details

getTrackId()

Retrieves the stream track ID.

Type Signature

getTrackId(): string;

Returns

string

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) The DOM element where the SDK will create a <video> element to play the track. You can specify this in two ways:

- string: The ID of the DOM element.

- HTMLElement: Specifies a DOM element object.

config

VideoPlayerConfig

(Optional) The video media playback parameters.

Returns

void

stop()

Stops playback.

Type Signature

stop(): void;

Returns

void

getTrackLabel()

Retrieves the source description of the local track.

Type Signature

getTrackLabel(): string;

Returns

string

The description of the audio or video track.

setDevice()

Updates the media device that the track uses.

Type Signature

setDevice(deviceId: string): Promise<void>;

Parameters

Parameter

Parameters

Description

deviceId

string

The device ID.

Returns

Promise<void>

setMuted()

Sends or stops sending the media data of the track.

If the track is published, calling this method triggers the user-info-updated event on the remote end.

Type Signature

setMuted(muted: boolean): Promise<void>;

Parameters

Parameter

Parameter

Description

muted

boolean

Specifies whether to send (true) or pause sending (false) media data for the track.

Returns

Promise<void>

on()

Registers a listener for a specified event and sets the corresponding callback function.

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.

Returns

void

off()

Removes 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 that is executed when the event is triggered.

Back

void

once()

Registers a one-time listener for a specified event. The listener is removed after the callback function is triggered.

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.

Returns

void

removeAllListeners()

Removes listeners for a specified event or for all events on the object.

Type Signature

removeAllListeners(event?: string): void;

Parameters

Parameter

Type

Description

event

string

(Optional) The event for which to remove listeners. If you do not specify this parameter, all listeners for all events on the object are removed.

Returns

void

Event list

"track-ended"

Indicates that the audio or video track has stopped. Possible reasons include the following:

- The camera is unplugged.

- The microphone is 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.

Signature:

'track-ended': () => void;