CameraVideoTrack
Contents
This class represents a local camera video track. It inherits from LocalVideoTrack and lets you change the capture device and adjust encoding parameters.
Properties
Property | Type | Description | Minimum supported version |
isPlaying | boolean | Indicates whether the media track is playing. | 3.0.0 |
trackMediaType | The type of the media track. | 3.0.0 | |
enabled | boolean | The current enabled state of the local track. | 3.0.0 |
muted | boolean | Mute | 3.0.0 |
API list
API | Description | Minimum supported version |
Updates the media device used to capture data for the track. | 3.0.0 | |
Enables or disables the camera track. | 3.0.0 | |
Pauses or resumes the camera track. | 3.0.0 | |
Gets the data of the currently rendered video frame. | 3.0.0 | |
Gets the media track. | 3.0.0 | |
Updates the video track's encoding settings to adjust video quality. | 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 | |
Removes a listener callback function for a specified event. | 3.0.0 | |
Adds a listener for a specified event and sets a callback function. | 3.0.0 | |
Adds a one-time listener for a specified event. The listener is removed after the callback function is triggered. | 3.0.0 | |
Removes the listener callbacks for a specified event or all events on this object. | 3.0.0 |
API details
setDevice()
Updates the media device used to capture data for the track.
Type Signature
setDevice(deviceId: string): Promise<void>; // On mobile, can be set to 'user' or 'environment'
Back
void
getCurrentFrameData()
Call this method only after playback starts. If play() has not been called, this method returns empty data.
Retrieves the data of the currently rendered video frame.
Type signature
getCurrentFrameData(): string;
Returns
A data URL of the 'image/png' type.
setEncoderConfiguration()
For versions earlier than 3.8.0, ensure that the video track is not being published when you call this method. If the track is already published, you must unpublish it, call this method, and then publish it again.
Updates the video track's encoding settings to adjust video quality.
Type Signature
VideoEncoderConfigurationsetEncoderConfiguration(config: <a baseurl="t2584367_v1_0_4.xdita" data-node="4688872" data-root="16740" data-tag="xref" href="t2584362.xdita#bbc425705ddqw" id="c738ebd888ep7">VideoEncoderConfiguration</a>): Promise<void>;
Back
Promise<void>
getMediaStreamTrack()
Retrieves the media track.
Type signature
getMediaStreamTrack(): MediaStreamTrack;
Back
MediaStreamTrack
The media track.
getTrackId()
Retrieves the stream track ID.
Type Signature
getTrackId(): string;
Returns
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. The SDK creates a video element under this DOM 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 an audio or video track.
Type signature
replaceTrack(track: MediaStreamTrack, stopOldTrack?: boolean): void;
Parameter | Type | Description |
track | MediaStreamTrack | The audio or video track. |
stopOldTrack | boolean | (Optional) Specifies whether to stop the previous track. |
Back
void
stop()
You can stop playback.
Type signature
stop(): void;
Returns
void
close()
Closes the local track and releases the associated capture devices.
A closed local track cannot be reused. To use a local track again, you must create a new one.
Signature
close(): void;
Returns
void
getTrackLabel()
Retrieves the source description of the local track.
Type Signature
getTrackLabel(): string;
Returns
string
A description of the audio or video track.
setDevice()
Updates the media device for the track.
Signature
setDevice(deviceId: string): Promise<void>;
Parameters
Parameter | Parameters | Description |
deviceId | string | The device ID. |
Back
Promise<void>
setEnabled()
Enable or disable the track.
Disabling a track stops both playback and publishing. If the track is already published, calling setEnabled triggers the user-info-updated event on the remote end.
Type Signature
setEnabled(enabled: boolean): Promise<void>;
Parameters
Parameter | Parameters | Description |
enabled | boolean | Specifies whether to enable the track. - true: Enable the track. - false: Disable the track. |
Back
Promise<void>
The difference between setEnabled and setMuted is that setMuted responds faster and does not affect the device's capture state. For example, calling setEnabled to disable a camera track turns off the camera's LED indicator, while setMuted does not.
Do not call setEnabled and setMuted at the same time.
setMuted()
Enables or disables sending media data for the track.
Calling setMuted on a published track triggers the user-info-updated event on the remote end.
Type Signature
setMuted(muted: boolean): Promise<void>;
Parameters
Parameter | Parameters | Description |
muted | boolean | Specifies whether to send (`true`) or pause sending (`false`) media data for the track. |
Returns
Promise<void>
on()
Adds a listener for a specified event and sets its 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()
Unregisters a listener callback function for a specified event.
Type Signature
off(event: string, fn: Function): void;
Parameters
Parameter | Type | Description |
event | string | The specified event to listen for. |
fn | Function | The callback function that is triggered when the event occurs. |
Back
void
once()
Adds a one-time listener for a specified event that 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 the listener callbacks for a specified event or for all events from this object.
Type Signature
removeAllListeners(event?: string): void;
Parameters
Parameter | Type | Description |
event | string | (Optional) If you specify an event, the listener callbacks for that event are cleared. If you do not specify this parameter, the listener callbacks for all events on the object are cleared. |
Returns
void