TRTCCloud

TRTCCloud

Tencent Cloud Audio & Video Call interface.

Constructor

new TRTCCloud()

Example
// Create TRTCCloud object
import TRTCCloud from 'trtc-electron-sdk';
const rtcCloud = new TRTCCloud();
// Get the SDK version number
const version = rtcCloud.getSDKVersion();

Methods

(static) getTRTCShareInstance() → {TRTCCloud}

Create TRTCCloud instance (singleton mode)

Returns:
Type
TRTCCloud

(static) destroyTRTCShareInstance()

Terminate TRTCCloud instance (singleton mode)

getConfigObject() → {TRTCConfig}

Get TRTCConfig object

TRTCConfig object can be used to open debug mode

Example
// Enable debug mode
const TRTCCloud = require('trtc-electron-sdk');
const rtcCloud = new TRTCCloud();
rtcCloud.getConfigObject().setDebugMode(true);
Returns:
Type
TRTCConfig

destroy()

Terminate current TRTCCloud instance

enterRoom(params, scene)

1.1 Enter Room

After calling this API, you will receive the onEnterRoom(result) event notification:

  • If room entry succeeded, the result parameter will be a positive number (result > 0), indicating the time in milliseconds (ms) between function call and room entry.
  • If room entry failed, the result parameter will be a negative number (result < 0), indicating the error code for room entry failure.

Parameter "scene" can be one of the following value:

  • TRTCAppScene.TRTCAppSceneVideoCall:
    Video call scenario. Use cases: [one-to-one video call], [video conferencing with up to 300 participants], [online medical diagnosis], [small class], [video interview], etc. In this scenario, each room supports up to 300 concurrent online users, and up to 50 of them can speak simultaneously.
  • TRTCAppScene.TRTCAppSceneAudioCall:
    Audio call scenario. Use cases: [one-to-one audio call], [audio conferencing with up to 300 participants], [audio chat], [online Werewolf], etc. In this scenario, each room supports up to 300 concurrent online users, and up to 50 of them can speak simultaneously.
  • TRTCAppScene.TRTCAppSceneLIVE:
    Live streaming scenario. Use cases: [low-latency video live streaming], [interactive classroom for up to 100,000 participants], [live video competition], [video dating room], [remote training], [large-scale conferencing], etc. In this scenario, each room supports up to 100,000 concurrent online users, but you should specify the user roles: anchor (TRTCRoleAnchor) or audience (TRTCRoleAudience).
  • TRTCAppScene.TRTCAppSceneVoiceChatRoom:
    Audio chat room scenario. Use cases: [Clubhouse], [online karaoke room], [music live room], [FM radio], etc. In this scenario, each room supports up to 100,000 concurrent online users, but you should specify the user roles: anchor (TRTCRoleAnchor) or audience (TRTCRoleAudience).

Notice:

  1. If scene is specified as TRTCAppScene.TRTCAppSceneLIVE or TRTCAppScene.TRTCAppSceneVoiceChatRoom, you must use the role field in TRTCParams to specify the role of the current user in the room.
  2. The same scene should be configured for all users in the same room.
  3. Please try to ensure that TRTCCloud.enterRoom and TRTCCloud.exitRoom are used in pair; that is, please make sure that "the previous room is exited before the next room is entered"; otherwise, many issues may occur.
Parameters:
Name Type Description
params TRTCParams

Room entry parameter

Properties
Name Type Description
sdkAppId Number

Required, application ID (required)

userId String

User ID (required)

userSig String

User signature (required)

roomId Number

Numeric room ID, roomId and strRoomId are mutually exclusive. If you decide to use strRoomId, then roomId should be entered as 0. If both are entered, roomId will be used.

strRoomId String

Optional, String-type room ID. Users (userId) in the same room can see one another and make audio/video calls.

role TRTCRoleType

role in the live streaming scenario, which is applicable only to the live streaming scenario (TRTCAppSceneLIVE or TRTCAppSceneVoiceChatRoom) but doesn't take effect in the call scenario. Default value: TRTCRoleAnchor

  • TRTCRoleAnchor: An anchor can publish their audio/video streams. There is a limit on the number of anchors. Up to 50 anchors are allowed to publish streams at the same time in one room.
  • TRTCRoleAudience: Audience can only listen to or watch audio/video streams of anchors in the room. If they want to publish their streams, they need to switch to the "anchor" role first through switchRole. One room can sustain up to 100,000 concurrent.
privateMapKey String

Optional, permission credential used for permission control. If you want only users with the specified userId values to enter a room, you need to use privateMapKey to restrict the permission.

businessInfo String

Optional, business data. This field is needed only by some advanced features.

streamId String

Specified streamId in Tencent Cloud CSS, which is optional. After setting this field, you can play back the user's audio/video stream on Tencent Cloud CSS CDN through a standard pull scheme (FLV or HLS).

userDefineRecordId String

On-cloud recording field, which is optional and used to specify whether to record the user's audio/video stream in the cloud.

scene TRTCAppScene

Application scenario,current supported scenes:VideoCall, Live, AudioCall, VoiceChatRoom.

exitRoom()

1.2 Exit room

Calling this API will allow the user to leave the current audio or video room and release the camera, mic, speaker, and other device resources. After resources are released, the SDK will emit the onExitRoom() event to notify you. If you need to call enterRoom again or switch to the SDK of another provider, we recommend you wait until you receive the onExitRoom() event, so as to avoid the problem of the camera or microphine being occupied.

switchRoom(params)

1.3 Switch room

This API is used to quickly switch a user from one room to another.

  • If the user's role is "audience", calling this API is equivalent to exitRoom (current room) + enterRoom (new room).
  • If the user's role is "anchor", the API will retain the current audio/video publishing status while switching the room; therefore, during the room switch, camera preview and sound capturing will not be interrupted. This API is suitable for the online education scenario where the supervising teacher can perform fast room switch across multiple rooms. In this scenario, using switchRoom can get better smoothness and use less code than exitRoom + enterRoom. After calling this API, an onSwitchRoom(errCode, errMsg) event will be emitted.
Parameters:
Name Type Description
params TRTCSwitchRoomParam

Room parameter. For more information, please see TRTCSwitchRoomConfig.

switchRole(role)

1.4 Switch role

This API is used to switch the user role between "anchor" and "audience". As video live rooms and audio chat rooms need to support an audience of up to 100,000 concurrent online users, the rule "only anchors can publish their audio/video streams" has been set. Therefore, when some users want to publish their streams (so that they can interact with anchors), they need to switch their role to "anchor" first. You can use the role field in TRTCParams during room entry to specify the user role in advance or use the switchRole API to switch roles after room entry.

Notice:

  1. This API is only applicable to two scenarios: live streaming (TRTCAppSceneLIVE) and audio chat room (TRTCAppSceneVoiceChatRoom).
  2. If the scene you specify in enterRoom is TRTCAppSceneVideoCall or TRTCAppSceneAudioCall, call this API will not work.
Parameters:
Name Type Description
role TRTCRoleType

Role, which is "anchor" by default:

  • TRTCRoleAnchor: anchor, who can publish their audio/video streams. Up to 50 anchors are allowed to publish streams at the same time in one room.
  • TRTCRoleAudience: audience, who cannot publish their audio/video streams, but can only watch streams of anchors in the room. If they want to publish their streams, they need to switch to the "anchor" role first through switchRole. One room supports an audience of up to 100,000 concurrent online users.

connectOtherRoom(params)

1.5 Request cross-room call

By default, only users in the same room can make audio/video calls with each other, and the audio/video streams in different rooms are isolated from each other. However, you can publish the audio/video streams of an anchor in another room to the current room by calling this API. At the same time, this API will also publish the local audio/video streams to the target anchor's room. In other words, you can use this API to share the audio/video streams of two anchors in two different rooms, so that the audience in each room can watch the streams of these two anchors. This feature can be used to implement anchor competition. The result of requesting cross-room call will be returned through the onConnectOtherRoom() event. For example, after anchor A in room "101" uses connectOtherRoom() to successfully call anchor B in room "102":

  • All users in room "101" will receive the onRemoteUserEnterRoom(B) and onUserVideoAvailable(B,1) event of anchor B; that is, all users in room "101" can subscribe to the audio/video streams of anchor B.
  • All users in room "102" will receive the onRemoteUserEnterRoom(A) and onUserVideoAvailable(A,1) event of anchor A; that is, all users in room "102" can subscribe to the audio/video streams of anchor A.

For short, with connectOtherRoom, tow anchor in two different room can connect together, and all users in the room can see both anchor.

                                  Room 101                          Room 102
                            ---------------------               ---------------------
 Before cross-room call:   | Anchor:     A       |             | Anchor:     B       |
                           | Users :   U, V, W   |             | Users:   X, Y, Z    |
                            ---------------------               ---------------------

                                  Room 101                           Room 102
                            ---------------------               ---------------------
 After cross-room call:    | Anchors: A and B    |             | Anchors: B and A    |
                           | Users  : U, V, W    |             | Users  : X, Y, Z    |
                            ---------------------               ---------------------

For compatibility with subsequent extended fields for cross-room call, parameters in JSON format are used currently. If anchor A in room "101" wants to co-anchor with anchor B in room "102", then anchor A needs to pass in {"roomId": 102, "userId": "userB"} when calling this API.

After calling this API, the result will be returned through the onConnectOtherRoom event notification.

Example
let json = JSON.stringify({roomId: 2, userId: "userB"});
rtcCloud.connectOtherRoom(json);
Parameters:
Name Type Description
params String

You need to pass in a string parameter in JSON format: roomId represents the room ID in numeric format, strRoomId represents the room ID in string format, and userId represents the user ID of the target anchor.

disconnectOtherRoom()

1.6 Exit cross-room call

The result will be returned through the onDisconnectOtherRoom event notification.

setDefaultStreamRecvMode(autoRecvAudio, autoRecvVideo)

1.7 Set subscription mode

You can switch between the "automatic subscription" and "manual subscription" modes through this API:

  • Automatic subscription: this is the default mode, where the user will immediately receive the audio/video streams in the room after room entry, so that the audio will be automatically played back, and the video will be automatically decoded (you still need to bind the rendering control through the startRemoteView API).
  • Manual subscription: after room entry, the user needs to manually call the {@startRemoteView} API to start subscribing to and decoding the video stream and call the {@muteRemoteAudio} (false) API to start playing back the audio stream. In most scenarios, users will subscribe to the audio/video streams of all anchors in the room after room entry. Therefore, TRTC adopts the automatic subscription mode by default in order to achieve the best "instant streaming experience". In your application scenario, if there are many audio/video streams being published at the same time in each room, and each user only wants to subscribe to 1–2 streams of them, we recommend you use the "manual subscription" mode to reduce the traffic costs.

Notice: Must be set before room entry for it to take effect. YES: automatic subscription to audio; NO: manual subscription to audio by calling muteRemoteAudio(false). Default value: YES

Parameters:
Name Type Description
autoRecvAudio Boolean

true: automatic subscription to audio; false:need manual subscription to audio by calling muteRemoteAudio. Default value: true

autoRecvVideo Boolean

true: automatic subscription to video; false:need manual subscription to video by calling startRemoteView/stopRemoteView. Default value: false

startPublishing(streamId, type)

2.1 Start publishing audio/video streams to Tencent Cloud CSS CDN

This API sends a command to the TRTC server, requesting it to relay the current user's audio/video streams to CSS CDN. You can set the StreamId of the live stream through the streamId parameter, so as to specify the playback address of the user's audio/video streams on CSS CDN. For example, if you specify the current user's live stream ID as user_stream_001 through this API, then the corresponding CDN playback address is: "http://yourdomain/live/user_stream_001.flv", where yourdomain is your playback domain name with an ICP filing.

You can configure your playback domain name in the CSS console. Tencent Cloud does not provide a default playback domain name.

You can also specify the streamId when setting the TRTCParams parameter of enterRoom, which is the recommended approach.

Notice: You need to enable the "Enable Relayed Push" option on the "Function Configuration" page in the TRTC console in advance.

  • If you select "Specified stream for relayed push", you can use this API to push the corresponding audio/video stream to Tencent Cloud CDN and specify the entered stream ID.
  • If you select "Global auto-relayed push", you can use this API to adjust the default stream ID.
Example
const trtcCloud = TRTCCloud.getTRTCShareInstance();
trtcCloud.enterRoom(params, TRTCAppScene.TRTCAppSceneLIVE);
trtcCloud.startLocalPreview(view);
trtcCloud.startLocalAudio(TRTCAudioQuality.TRTCAudioQualityDefault);
trtcCloud.startPublishing("user_stream_001", TRTCVideoStreamType.TRTCVideoStreamTypeBig);
Parameters:
Name Type Description
streamId String

Custom stream ID.

type TRTCVideoStreamType

Only TRTCVideoStreamTypeBig and TRTCVideoStreamTypeSub are supported.

stopPublishing()

2.2 Stop publishing audio/video streams to Tencent Cloud CSS CDN

startPublishCDNStream(param)

2.3 Start publishing audio/video streams to non-Tencent Cloud CDN

This API is similar to the startPublishing API. The difference is that startPublishing can only publish audio/video streams to Tencent Cloud CDN, while this API can relay streams to live streaming CDN services of other cloud providers.

Notice:

  • Using the startPublishing API to publish audio/video streams to Tencent Cloud CSS CDN does not incur additional fees.
  • Using the startPublishCDNStream API to publish audio/video streams to non-Tencent Cloud CDN incurs additional relaying bandwidth fees.
Parameters:
Name Type Description
param TRTCPublishCDNParam

CDN relaying parameter.

Properties
Name Type Description
appId Number

appId of Tencent Cloud CSS

bizId Number

bizId of Tencent Cloud CSS

url String

specify the push address (in RTMP format) of this audio/video stream at the third-party live streaming service provider

stopPublishCDNStream()

2.4 Stop publishing audio/video streams to non-Tencent Cloud CDN

setMixTranscodingConfig(config)

2.5 Set the layout and transcoding parameters of On-Cloud MixTranscoding

In a live room, there may be multiple anchors publishing their audio/video streams at the same time, but for audience on CSS CDN, they only need to watch one video stream in HTTP-FLV or HLS format. When you call this API, the SDK will send a command to the TRTC mixtranscoding server to combine multiple audio/video streams in the room into one stream. You can use the TRTCTranscodingConfig parameter to set the layout of each channel of image. You can also set the encoding parameters of the mixed audio/video streams. For more information, please see On-Cloud MixTranscoding.

    **Image 1** => decoding ====> \\
                                   \\
    **Image 2** => decoding => image mixing => encoding => **mixed image**
                                   //
    **Image 3** => decoding ====> //

    **Audio 1** => decoding ====> \\
                                   \\
    **Audio 2** => decoding => audio mixing => encoding => **mixed audio**
                                   //
    **Audio 3** => decoding ====> //
Parameters:
Name Type Description
config TRTCTranscodingConfig

If config is not empty, On-Cloud MixTranscoding will be started; otherwise, it will be stopped. For more information, please see TRTCTranscodingConfig.

Properties
Name Type Description
mode TRTCTranscodingConfigMode

layout mode

appId Number

appId of Tencent Cloud CSS

bizId Number

bizId of Tencent Cloud CSS

videoWidth Number

specify the target resolution (width) of On-Cloud MixTranscoding(px)

videoHeight Number

specify the target resolution (height) of On-Cloud MixTranscoding(px)

videoBitrate Number

specify the target video bitrate (Kbps) of On-Cloud MixTranscoding

videoFramerate Number

specify the target video frame rate (fps) of On-Cloud MixTranscoding

videoGOP Number

specify the target video keyframe interval (GOP) of On-Cloud MixTranscoding

audioSampleRate Number

specify the target audio sample rate of On-Cloud MixTranscoding

audioBitrate Number

specify the target audio bitrate (Kbps) of On-Cloud MixTranscoding

audioChannels Number

specify the number of sound channels of On-Cloud MixTranscoding

backgroundColor String

specify the background color of the mixed video image

backgroundImage String

specify the background image of the mixed video image

streamId String

ID of the live stream output to CDN

mixUsersArray Array.<TRTCMixUser>

specify the position, size, layer, and stream type of each video image in On-Cloud MixTranscoding

Properties
Name Type Description
userId String

user ID

roomId String

ID of the room where this audio/video stream is located. An empty value indicates the local room ID. If connectOtherRoom called with other room anchor, can pass the connected room ID.

rect Rect

specify the coordinate area of this video image in px

Properties
Name Type Description
left Number

left coordinate of this video image

top Number

top coordinate of this video image

right Number

right coordinate of this video image

bottom Number

bottom coordinate of this video image

zOrder Number

specify the level of this video image (value range: 1–15; the value must be unique)

pureAudio Boolean

specify whether this stream mixes audio only

streamType TRTCVideoStreamType

specify whether this video image is the primary stream image (TRTCVideoStreamTypeBig) or substream image (TRTCVideoStreamTypeSub).

startLocalPreview(view)

3.1 Enable the preview image of local camera

If this API is called before enterRoom, the SDK will only enable the camera and wait until enterRoom is called before starting push. If it is called after enterRoom, the SDK will enable the camera and automatically start pushing the video stream.

When the first camera video frame starts to be rendered, you will receive the onFirstVideoFrame event.

This API will start system default camera, if you want to change camera devce, you can use setCurrentCameraDevice() to choose other camera device.

Parameters:
Name Type Description
view HTMLElement

HTML Element that will carry the video image

stopLocalPreview()

3.2 Stop camera preview

muteLocalVideo(mute, streamType)

3.3 Pause/Resume publishing local video stream

This API can pause (or resume) publishing the local video image. After the pause, other users in the same room will not be able to see the local image. This API is equivalent to the two APIs of startLocalPreview/stopLocalPreview when TRTCVideoStreamTypeBig is specified, but has higher performance and response speed. The startLocalPreview/stopLocalPreview APIs need to enable/disable the camera, which are hardware device-related operations, so they are very time-consuming. In contrast, muteLocalVideo only needs to pause or allow the data stream at the software level, so it is more efficient and more suitable for scenarios where frequent enabling/disabling are needed. After local video publishing is paused, other members in the same room will receive the onUserVideoAvailable(userId, 0) event notification. After local video publishing is resumed, other members in the same room will receive the onUserVideoAvailable(userId, 1) event notification.

Parameters:
Name Type Description
mute Boolean

true: pause; false: resume, default value: false

streamType TRTCVideoStreamType

Video stream type to be paused or resumed

startRemoteView(userId, view, streamType)

3.4 Subscribe to a remote user's video stream and bind it to a video rendering control

If you call this API, the SDK will pull the video stream of the specified userId and render it to the rendering control specified by the view parameter. You can set the display mode of the video image using setRemoteRenderParams.

  • If you already know the userId of the user who is publishing video in the room, you can call startRemoteView to subscribe to the user's video.
  • If you don't know who is publishing video in the room, you can wait for the onUserVideoAvailable event after a remote user calls enterRoom.

If you receive the onUserVideoAvailable(userId, 1) event from the SDK, it indicates that the remote user has enabled video. After receiving this event, call startRemoteView(userId) to load the user’s video. You can use a loading animation to improve user experience during the waiting period. When the first video frame of this user is displayed, you will receive the onFirstVideoFrame(userId) event.

Notes:

  1. The SDK supports playing a user’s big/small image and substream image at the same time, but does not support playing the big and small images at the same time.
  2. The small image of a user can be played only if the user has called enableSmallVideoStream to enable the dual-stream mode.
  3. If the small image of the specified user does not exist, the SDK will switch to the big image.
Parameters:
Name Type Description
userId String

The ID of the remote user whose video is to be played.

view HTMLElement

The HTML element that will carry the video image.

streamType TRTCVideoStreamType

Which stream of the user to play:

  • HD big image: TRTCVideoStreamTypeBig
  • Smooth small image: TRTCVideoStreamTypeSmall. This value is valid only if the remote user has called enableSmallVideoStream to enable the dual-stream mode.
  • Substream image (usually used for screen sharing): TRTCVideoStreamTypeSub

stopRemoteView(userId, streamType)

3.5 Stop subscribing to remote user's video stream and release rendering control

Calling this API will cause the SDK to stop receiving the user's video stream and release the decoding and rendering resources for the stream.

Parameters:
Name Type Description
userId String

D of the specified remote user

streamType TRTCVideoStreamType

Video stream type of the userId specified for watching:

  • HD big image: TRTCVideoStreamTypeBig
  • Smooth small image: TRTCVideoStreamTypeSmall
  • Substream image (usually used for screen sharing): TRTCVideoStreamTypeSub

stopAllRemoteView()

3.6 Stop subscribing to all remote users' video streams and release all rendering resources

Calling this API will cause the SDK to stop receiving all remote video streams and release all decoding and rendering resources. Notice: If a substream image (screen sharing) is being displayed, it will also be stopped.

muteRemoteVideoStream(userId, mute, streamType)

3.7 Pause/Resume subscribing to remote user's video stream

This API only pauses/resumes receiving the specified user's video stream but does not release displaying resources; therefore, the video image will freeze at the last frame before it is called. Notice: This API can be called before room entry (enterRoom), and the pause status will be reset after room exit (exitRoom).

Parameters:
Name Type Description
userId String

ID of the specified remote user

mute Boolean

Whether to pause receiving

streamType TRTCVideoStreamType

Video stream type

muteAllRemoteVideoStreams(mute)

3.8 Pause/Resume subscribing to all remote users' video streams

This API only pauses/resumes receiving all users' video streams but does not release displaying resources; therefore, the video image will freeze at the last frame before it is called. Notice: This API can be called before room entry (enterRoom), and the pause status will be reset after room exit (exitRoom).

Parameters:
Name Type Description
mute Boolean

Whether to pause receiving

setVideoEncoderParam(params)

3.9 Set the encoding parameters of video encoder

This setting can determine the quality of image viewed by remote users, which is also the image quality of on-cloud recording files.

Parameters:
Name Type Description
params TRTCVideoEncParam

Video encoding parameters

Properties
Name Type Description
videoResolution TRTCVideoResolution

video resolution

resMode TRTCVideoResolutionMode

resolution mode (landscape/portrait)

  • TRTCVideoResolutionModeLandscape: Landscape resolution
  • TRTCVideoResolutionModePortrait : Portrait resolution
videoFps Number

video capturing frame rate

videoBitrate Number

target video bitrate. The SDK encodes streams at the target video bitrate and will actively reduce the bitrate only in weak network environments.

minVideoBitrate Number

minimum video bitrate. The SDK will reduce the bitrate to as low as the value specified by minVideoBitrate to ensure the smoothness only if the network conditions are poor.

setNetworkQosParam(params)

3.10 Set network quality control parameters

This setting determines the quality control policy in a poor network environment, such as "image quality preferred" or "smoothness preferred".

Parameters:
Name Type Description
params TRTCNetworkQosParam

Parameters for network quality control

Properties
Name Type Description
preference TRTCVideoQosPreference

whether to ensure smoothness or clarity

  • TRTCVideoQosPreferenceSmooth: In this mode, when the current network is unable to transfer a clear and smooth video image, the smoothness of the image will be given priority, but there will be blurs.
  • TRTCVideoQosPreferenceClear : It is default value. in this mode, when the current network is unable to transfer a clear and smooth video image, the clarity of the image will be given priority, but there will be lags.
controlMode TRTCQosControlMode

QoS control mode

  • TRTCQosControlModeClient: Client-based control, which is for internal debugging of SDK and shall not be used by users.
  • TRTCQosControlModeServer: On-cloud control, which is the default and recommended mode.

setLocalRenderParams(params)

3.11 Set the rendering parameters of local video image

The parameters that can be set include video image rotation angle, fill mode, and mirror mode.

Parameters:
Name Type Description
params TRTCRenderParams

Video image rendering parameters.

Properties
Name Type Description
rotation TRTCVideoRotation

clockwise image rotation angle

fillMode TRTCVideoFillMode

image fill mode

mirrorType TRTCVideoMirrorType

image mirror mode

setLocalViewFillMode(mode)

3.12. Set the rendering mode of the local image (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use `setLocalRenderParams` instead.
Parameters:
Name Type Description
mode TRTCVideoFillMode

Fill (the image may be stretched or cropped) or fit (there may be black bars). Default value: TRTCVideoFillMode_Fit.

  • TRTCVideoFillMode_Fill: The image fills the entire screen, and the excess parts are cropped. The image may not be displayed in whole.
  • TRTCVideoFillMode_Fit: The image is stretched as large as the long side can go, and the blank area is filled with black bars. The image is displayed in whole.

setRemoteRenderParams(userId, streamType, params)

3.13 Set the rendering mode of remote video image

Parameters:
Name Type Description
userId String

ID of the specified remote user

streamType TRTCVideoStreamType

It can be set to the primary stream image (TRTCVideoStreamTypeBig) or substream image (TRTCVideoStreamTypeSub).

params TRTCRenderParams

Video image rendering parameters.

Properties
Name Type Description
rotation TRTCVideoRotation

clockwise image rotation angle

fillMode TRTCVideoFillMode

image fill mode

mirrorType TRTCVideoMirrorType

image mirror mode

setRemoteViewFillMode(userID, mode)

3.14. Set the rendering mode of a remote image (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use `setRemoteRenderParams` instead.
Parameters:
Name Type Description
userID String

The ID of the remote user.

mode TRTCVideoFillMode

Fill (the image may be stretched or cropped) or fit (there may be black bars). Default value: TRTCVideoFillMode_Fit.

  • TRTCVideoFillMode_Fill: The image fills the entire screen, and the excess parts are cropped. The image may not be displayed in whole.
  • TRTCVideoFillMode_Fit: The image is stretched as large as the long side can go, and the blank area is filled with black bars. The image is displayed in whole.

setLocalViewRotation(rotation)

3.15 Set the rotation of the local image (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use `setLocalRenderParams` instead.
Parameters:
Name Type Description
rotation TRTCVideoRotation

Valid values: TRTCVideoRotation90, TRTCVideoRotation180, TRTCVideoRotation270, TRTCVideoRotation0 (default).

  • TRTCVideoRotation0 : No rotation.
  • TRTCVideoRotation90 :Rotate 90 degrees clockwise.
  • TRTCVideoRotation180: Rotate 180 degree clockwise.
  • TRTCVideoRotation270: Rotate 270 degree clockwise.

setRemoteViewRotation(userID, rotation)

3.16 Set the rotation of a remote image (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use `setRemoteRenderParams` instead.
Parameters:
Name Type Description
userID String

The ID of the remote user.

rotation TRTCVideoRotation

Valid values: TRTCVideoRotation90, TRTCVideoRotation180, TRTCVideoRotation270, TRTCVideoRotation0 (default).

  • TRTCVideoRotation0 : No rotation.
  • TRTCVideoRotation90 :Rotate 90 degrees clockwise.
  • TRTCVideoRotation180: Rotate 180 degree clockwise.
  • TRTCVideoRotation270: Rotate 270 degree clockwise.

setVideoEncoderRotation(rotation)

3.17 Set the direction of image output by video encoder

This setting does not affect the preview direction of the local video image, but affects the direction of the image viewed by other users in the room (and on-cloud recording files). When a phone or tablet is rotated upside down, as the capturing direction of the camera does not change, the video image viewed by other users in the room will become upside-down. In this case, you can call this API to rotate the image encoded by the SDK 180 degrees, so that other users in the room can view the image in the normal direction. If you want to achieve the aforementioned user-friendly interactive experience, we recommend you directly call setGSensorMode to implement smarter direction adaptation, with no need to call this API manually.

Parameters:
Name Type Description
rotation TRTCVideoRotation

Currently, rotation angles of 0 and 180 degrees are supported. Default value: TRTCVideoRotation0 (no rotation)

  • TRTCVideoRotation0 : No rotation
  • TRTCVideoRotation180: Clockwise rotation by 180 degrees

setLocalViewMirror(mirror)

3.18 Turn on/off the mirror mode for the local camera preview (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use `setLocalRenderParams` instead.
Parameters:
Name Type Description
mirror Boolean

Whether to turn on the mirror mode. Default value for Windows: false (off); default value for macOS: true (on).

setVideoEncoderMirror(mirror)

3.19 Set the mirror mode of image output by encoder

This setting does not affect the mirror mode of the local video image, but affects the mirror mode of the image viewed by other users in the room (and on-cloud recording files).

Parameters:
Name Type Description
mirror Boolean

Whether to enable remote mirror mode. true: yes; false: no. Default value: false

enableSmallVideoStream(enable, params)

3.20 Enable dual-channel encoding mode with big and small images

In this mode, the current user's encoder will output two channels of video streams, i.e., HD big image and Smooth small image, at the same time (only one channel of audio stream will be output though). In this way, other users in the room can choose to subscribe to the HD big image or Smooth small image according to their own network conditions or screen size.

Notice: Dual-channel encoding will consume more CPU resources and network bandwidth; therefore, this feature can be enabled on macOS, Windows, or high-spec tablets, but is not recommended for phones.

Parameters:
Name Type Description
enable Boolean

Whether to enable small image encoding. Default value: false

params TRTCVideoEncParam

Video parameters of small image stream

Properties
Name Type Description
videoResolution TRTCVideoResolution

video resolution

resMode TRTCVideoResolutionMode

resolution mode (landscape/portrait)

  • TRTCVideoResolutionModeLandscape: Landscape resolution
  • TRTCVideoResolutionModePortrait : Portrait resolution
videoFps Number

video capturing frame rate

videoBitrate Number

target video bitrate. The SDK encodes streams at the target video bitrate and will actively reduce the bitrate only in weak network environments.

minVideoBitrate Number

minimum video bitrate. The SDK will reduce the bitrate to as low as the value specified by minVideoBitrate to ensure the smoothness only if the network conditions are poor.

setRemoteVideoStreamType(userId, type)

3.21 Switch the big/small image of specified remote user

After an anchor in a room enables dual-channel encoding, the video image that other users in the room subscribe to through startRemoteView will be HD big image by default. You can use this API to select whether the image subscribed to is the big image or small image. The API can take effect before or after startRemoteView is called.

Notice: To implement this feature, the target user must have enabled the dual-channel encoding mode through enableEncSmallVideoStream; otherwise, this API will not work.

Parameters:
Name Type Description
userId String

ID of the specified remote user

type TRTCVideoStreamType

Video stream type, i.e., big image or small image. Default value: HD big image

  • TRTCVideoStreamTypeBig : HD big image
  • TRTCVideoStreamTypeSmall: small image

snapshotVideo(userId, streamType)

3.22 Video snapshot

You can use this API to take snapshot of the local video image or the primary stream image and substream (screen sharing) image of a remote user. After calling this API, an onSnapshotComplete event will be emitted.

Parameters:
Name Type Description
userId String

User ID. A null value indicates to take snapshot of the local video.

streamType TRTCVideoStreamType

Video stream type, which can be the primary stream image (TRTCVideoStreamTypeBig, generally for camera) or substream image (TRTCVideoStreamTypeSub, generally for screen sharing)

setPriorRemoteVideoStreamType(type)

3.23 Set video references for playback (deprecated)

For low-end devices, we recommend you set the parameter to TRTCVideoStreamTypeSmall (small image). This API will not work if a remote user hasn’t enabled the dual-stream mode.

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use `startRemoteView` instead.
Parameters:
Name Type Description
type TRTCVideoStreamType

Whether to play the big or small image by default. Default value: TRTCVideoStreamTypeBig.

  • TRTCVideoStreamTypeBig: Big video stream
  • TRTCVideoStreamTypeSmall: Small video stream

startLocalAudio(quality)

4.1 Enable local audio capturing and publishing

The SDK does not enable the microphone by default. When a user wants to publish the local audio, the user needs to call this API to enable microphone capturing and encode and publish the audio to the current room. After local audio capturing and publishing is enabled, other users in the room will receive the onUserAudioAvailable(userId, 1) notification.

Parameters:
Name Type Description
quality TRTCAudioQuality

Sound quality

  • TRTCAudioQualitySpeech: sample rate: 16 kHz; mono channel; audio bitrate: 16 Kbps. This is suitable for audio call scenarios, such as online meeting and audio call.
  • TRTCAudioQualityDefault: sample rate: 48 kHz; mono channel; audio bitrate: 50 Kbps. This is the default sound quality of the SDK and recommended if there are no special requirements.
  • TRTCAudioQualityMusic: sample rate: 48 kHz; dual channel + full band; audio bitrate: 128 Kbps. This is suitable for scenarios where Hi-Fi music transfer is required, such as online karaoke and music live streaming.

stopLocalAudio()

4.2 Stop local audio capturing and publishing

After local audio capturing and publishing is stopped, other users in the room will receive the onUserAudioAvailable(userId, false) event notification.

muteLocalAudio(mute)

4.3 Pause/Resume publishing local audio stream

After local audio publishing is paused, other users in the room will receive the onUserAudioAvailable(userId, false) notification. After local audio publishing is resumed, other users in the room will receive the onUserAudioAvailable(userId, true) notification. Different from stopLocalAudio, muteLocalAudio(true) does not release the mic permission; instead, it continues to send mute packets with extremely low bitrate. This is very suitable for scenarios that require on-cloud recording, as video file formats such as MP4 have a high requirement for audio continuity, while an MP4 recording file cannot be played back smoothly if stopLocalAudio is used. Therefore, muteLocalAudio instead of stopLocalAudio is recommended in scenarios where the requirement for recording file quality is high.

Parameters:
Name Type Description
mute Boolean

true: mute; false: unmute, default value: false

muteRemoteAudio(userId, mute)

4.4 Pause/Resume playing back remote audio stream

When you mute the remote audio of a specified user, the SDK will stop playing back the user's audio and pulling the user's audio data.

Notice: This API works when called either before or after room entry (enterRoom), and the mute status will be reset to false after room exit (exitRoom).

Parameters:
Name Type Description
userId String

ID of the specified remote user

mute Boolean

true: mute; false: unmute

muteAllRemoteAudio(mute)

4.5 Pause/Resume playing back all remote users' audio streams

When you mute the audio of all remote users, the SDK will stop playing back all their audio streams and pulling all their audio data.

Notice: This API works when called either before or after room entry (enterRoom), and the mute status will be reset to false after room exit (exitRoom).

Parameters:
Name Type Description
mute Boolean

true: mute; false: unmute

setRemoteAudioVolume(userId, volume)

4.6 Set the audio playback volume of remote user

You can mute the audio of a remote user through setRemoteAudioVolume(userId, 0).

Notice: If 100 is still not loud enough for you, you can set the volume to up to 150, but there may be side effects.

Parameters:
Name Type Description
userId String

ID of the specified remote user

volume Number

Volume. 100 is the original volume. Value range: [0,150]. Default value: 100

setAudioCaptureVolume(volume)

4.7 Set the capturing volume of local audio

Notice: If 100 is still not loud enough for you, you can set the volume to up to 150, but there may be side effects.

Parameters:
Name Type Description
volume Number

Volume. 100 is the original volume. Value range: [0,150]. Default value: 100

getAudioCaptureVolume() → {Number}

4.8 Get the capturing volume of local audio

Returns:
  • Capture volume
Type
Number

setAudioPlayoutVolume(volume)

4.9 Set the playback volume of remote audio

This API controls the volume of the sound ultimately delivered by the SDK to the system for playback. It affects the volume of the recorded local audio file but not the volume of in-ear monitoring.

Notice: If 100 is still not loud enough for you, you can set the volume to up to 150, but there may be side effects.

Parameters:
Name Type Description
volume Number

Volume. 100 is the original volume. Value range: [0,150]. Default value: 100

getAudioPlayoutVolume() → {Number}

4.10 Get the playback volume of remote audio

Returns:
  • Capture volume
Type
Number

enableAudioVolumeEvaluation(interval)

4.11 Enable volume reminder

After this feature is enabled, the SDK will return the remote audio volume in the onUserVoiceVolume event notification.

Parameters:
Name Type Description
interval Number

Set the interval in ms for emitting the onUserVoiceVolume event. The minimum interval is 100 ms. If the value is smaller than or equal to 0, the event notification will be disabled. We recommend you set this parameter to 300 ms.

startAudioRecording(params) → {Number}

4.12 Start audio recording

After this API is called, the SDK will record all audios of a call, including the local audio, remote audios, background music, and audio effects, into a file. This API works both before and after room entry. Recording will stop automatically after room exit, even if stopAudioRecording is not called.

Notes:

  • The path must contain the filename and extension. The extension determines the format of the recording file. Supported formats include PCM, WAV, and AAC. For example, if you set the path to mypath/record/audio.aac, the SDK will generate an audio recording file in AAC format. Please specify a valid path with read/write permissions; otherwise, the system will fail to generate audio recording files.
  • In versions earlier than 9.3, params (required), which indicates the path to save recording files, must be a string. In v9.3 and later versions, the parameter can be a string or TRTCAudioRecordingParams.
Parameters:
Name Type Description
params TRTCAudioRecordingParams | String

Audio recording parameters.

Properties
Name Type Description
filePath String

The storage path of the audio recording file, which is required. Make sure you have write access to the path.

recordingContent TRTCAudioRecordingContent

The audio recording content type.

Returns:

0: successful; -1: Audio recording has started; -2: Failed to create the file or directory; -3: The audio format specified is not supported.

Type
Number

stopAudioRecording()

4.13 Stop audio recording

If a recording task has not been stopped through this API before room exit, it will be automatically stopped after room exit.

setAudioQuality(quality)

4.14 Set audio quality (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use startLocalAudio instead. Notice: 1. This API should be called before `startLocalAudio`, otherwise it will not take effect. 2. The higher sound quality will bring better listening experience, but need more bandwidth. It will be more likely to get stuck in weak network scenario.
Parameters:
Name Type Description
quality TRTCAudioQuality

Sound quality

  • TRTCAudioQualitySpeech: ample rate: 16 kHz; mono channel; audio bitrate: 16 Kbps. This is suitable for audio call scenarios, such as online meeting and audio call.
  • TRTCAudioQualityDefault: sample rate: 48 kHz; mono channel; audio bitrate: 50 Kbps. This is the default sound quality of the SDK and recommended if there are no special requirements.
  • TRTCAudioQualityMusic: sample rate: 48 kHz; dual channel + full band; audio bitrate: 128 Kbps. This is suitable for scenarios where Hi-Fi music transfer is required, such as online karaoke and music live streaming.

setMicVolumeOnMixing(volume)

4.15 Set microphone volume (deprecated)

Deprecated:
Parameters:
Name Type Description
volume Number

Volume value. Value range: 0 - 200; default: 100

getCameraDevicesList() → {Array.<TRTCDeviceInfo>}

5.1 Get the list of cameras

Example
var cameralist = rtcCloud.getCameraDevicesList();
for (i=0;i<cameralist.length;i++) {
   var camera = cameralist[i];
   console.info("camera deviceName: " + camera.deviceName + " deviceId:" + camera.deviceId);
}
Returns:
  • Camera List
Type
Array.<TRTCDeviceInfo>

setCurrentCameraDevice(deviceId)

5.2 Set the camera to be used

Parameters:
Name Type Description
deviceId String

deviceId from getCameraDevicesList return values

getCurrentCameraDevice() → {TRTCDeviceInfo}

5.3 Get the camera currently in use

Returns:

Camera device information

Type
TRTCDeviceInfo

getMicDevicesList() → {Array.<TRTCDeviceInfo>}

6.1 Get the list of microphones

Example
var miclist = rtcCloud.getMicDevicesList();
  for (i=0;i<miclist.length;i++) {
    var mic = miclist[i];
    console.info("mic deviceName: " + mic.deviceName + " deviceId:" + mic.deviceId);
  }
Returns:

microphone device list

Type
Array.<TRTCDeviceInfo>

getCurrentMicDevice() → {TRTCDeviceInfo}

6.2 Get the microphone currently in use

Returns:

device information with device ID and name

Type
TRTCDeviceInfo

setCurrentMicDevice(micId)

6.3 Set the mic to use

This API is used to set the mic to use. If you do not call this API, the mic whose index is 0 that returned from getMicDevicesList will be used.

Parameters:
Name Type Description
micId String

The ID of the mic to use. You can call getMicDevicesList to get mic IDs.

getCurrentMicDeviceVolume() → {Number}

6.4 Get the current mic volume

This API is used to get the capturing volume of the mic. Note: This API returns the audio volume of the hardware.

Returns:

: The mic volume. Value range: 0-100.

Type
Number

setCurrentMicDeviceVolume(:)

6.5 Set the current mic volume

This API is used to set the capturing volume of the mic. Note: This API sets the system capturing volume. If the user adjusts the system capturing volume manually, the volume set by the API will be overwritten.

Parameters:
Name Type Description
: Number

The volume to use. Value range: 0-100.

setCurrentMicDeviceMute(mute)

6.6 Set the mute status of the microphone currently in use

Parameters:
Name Type Description
mute Boolean

true: mute, false: unmute

getCurrentMicDeviceMute() → {Boolean}

6.7 Get the mute status of the microphone currently in use

Returns:

Mute state

Type
Boolean

getSpeakerDevicesList() → {Array.<TRTCDeviceInfo>}

6.8 Get the list of speakers

Example
var speakerlist = rtcCloud.getSpeakerDevicesList();
  for (i=0;i<speakerlist.length;i++) {
    var speaker = speakerlist[i];
    console.info("mic deviceName: " + speaker.deviceName + " deviceId:" + speaker.deviceId);
  }
Returns:

Speaker device list

Type
Array.<TRTCDeviceInfo>

getCurrentSpeakerDevice() → {TRTCDeviceInfo}

6.9 Get the speaker currently in use

Returns:

device information with device ID and name

Type
TRTCDeviceInfo

setCurrentSpeakerDevice(speakerId)

6.10 Set the speaker currently in use

Parameters:
Name Type Description
speakerId String

deviceId from getSpeakerDevicesList return values

getCurrentSpeakerVolume() → {Number}

6.11 Get the current speaker volume

This API is used to get the playback volume of the speaker.

Returns:

: The speaker volume. Value range: 0-100.

Type
Number

setCurrentSpeakerVolume(:)

6.12 Set the current speaker volume

This API is used to set the playback volume of the speaker.

Note: This API sets the system playback volume. If the user adjusts the system playback volume manually, the volume set by the API will be overwritten.

Parameters:
Name Type Description
: Number

The volume to use. Value range: 0-100.

setCurrentSpeakerDeviceMute(mute)

6.13 Set the mute status of the speaker currently in use

Parameters:
Name Type Description
mute Boolean

true: mute, false: unmute

getCurrentSpeakerDeviceMute() → {Boolean}

6.14 Get the mute status of the speaker currently in use

Returns:

true: muted, false: unmuted

Type
Boolean

setBeautyStyle(style, beauty, white, ruddiness)

7.1 Set special effects such as beauty, brightening, and rosy skin filters

The SDK is integrated with two skin smoothing algorithms of different styles:

  • "Smooth" style, which uses a more radical algorithm for more obvious effect and is suitable for show live streaming.
  • "Natural" style, which retains more facial details for more natural effect and is suitable for most live streaming use cases.
Parameters:
Name Type Description
style TRTCBeautyStyle

Skin smoothening algorithm ("smooth" or "natural")

  • TRTCBeautyStyleSmooth: Smooth style
  • TRTCBeautyStyleNature: Natural style
beauty Number

Strength of the beauty filter. Value range: 0–9; 0 indicates that the filter is disabled, and the greater the value, the more obvious the effect.

white Number

Strength of the brightening filter. Value range: 0–9; 0 indicates that the filter is disabled, and the greater the value, the more obvious the effect.

ruddiness Number

Strength of the rosy skin filter. Value range: 0–9; 0 indicates that the filter is disabled, and the greater the value, the more obvious the effect.

setWaterMark(streamType, srcData, srcType, nWidth, nHeight, xOffset, yOffset, fWidthRatio)

7.2 Add watermark

The watermark position is determined by the xOffset, yOffset, and fWidthRatio parameters.

  • xOffset: X coordinate of watermark, which is a floating-point number between 0 and 1.
  • yOffset: Y coordinate of watermark, which is a floating-point number between 0 and 1.
  • fWidthRatio: watermark dimensions ratio, which is a floating-point number between 0 and 1.

Notice:

  1. Only supports MacOS, Windows OS not supported.
  2. Only supports adding an image watermark to the primary stream
Parameters:
Name Type Description
streamType TRTCVideoStreamType

Stream type of the watermark to be set (TRTCVideoStreamTypeBig or TRTCVideoStreamTypeSub)

srcData ArrayBuffer

Source data of watermark image (if null is passed in, the watermark will be removed)

srcType TRTCWaterMarkSrcType

Source data type of watermark image

  • TRTCWaterMarkSrcTypeFile : Not supported with Electron platform
  • TRTCWaterMarkSrcTypeBGRA32: Memory block in BGRA32 format
  • TRTCWaterMarkSrcTypeRGBA32: Memory block in RGBA32 format
nWidth Number

Pixel width of watermark image (this parameter will be ignored if the source data is a file path)

nHeight Number

Pixel height of watermark image (this parameter will be ignored if the source data is a file path)

xOffset Number

Top-left offset on the X axis of watermark

yOffset Number

Top-left offset on the Y axis of watermark

fWidthRatio Number

Ratio of watermark width to image width (the watermark will be scaled according to this parameter)

startRemoteSubStreamView(userId, view)

8.1 Start displaying the substream image of remote user (deprecated)

  • startRemoteView used to display big stream image (TRTCVideoStreamTypeBig, commonly used for camera).
  • This API is used to display substream image (TRTCVideoStreamTypeSub, commonly used for screen sharing).
Deprecated:
Parameters:
Name Type Description
userId String

remote user ID

view HTMLElement

HTML Element where to display substream image

stopRemoteSubStreamView(userId)

8.2 Stop displaying the substream image of remote user (deprecated)

Substream (TRTCVideoStreamTypeSub, commonly used for screen sharing).

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use stopRemoteView instead.
Parameters:
Name Type Description
userId String

remote user ID

setRemoteSubStreamViewFillMode(userId, mode)

8.3 Set the fill mode of substream image (deprecated)

  • setRemoteViewFillMode used to set big image fill-mode (TRTCVideoStreamTypeBig, commonly used for camera).
  • This API is used to set substream fill-mode (TRTCVideoStreamTypeSub, commonly used for screen sharing).
Deprecated:
Parameters:
Name Type Description
userId String

remote user ID

mode TRTCVideoFillMode

Video image fill mode. Default value: TRTCVideoFillMode_Fit

  • TRTCVideoFillMode_Fill: Fill mode: the video image will be centered and scaled to fill the entire display area, where parts that exceed the area will be cropped. The displayed image may be incomplete in this mode.
  • TRTCVideoFillMode_Fit: Fit mode: the video image will be scaled based on its long side to fit the display area, where the short side will be filled with black bars. The displayed image is complete in this mode, but there may be black bars.

setRemoteSubStreamViewRotation(userId, rotation)

8.4 Set the clockwise rotation angle of substream image (deprecated)

  • TRTCCloud#setRemoteViewRotation used to set the clockwise rotation angle of big stream (TRTCVideoStreamTypeBig, commonly used for camera)
  • This API is used to set the clockwise rotation angle of substream image (TRTCVideoStreamTypeSub, commonly used for screen sharing)
Deprecated:
Parameters:
Name Type Description
userId String

remote user ID

rotation TRTCVideoRotation

supported angle: 90, 180, 270

getScreenCaptureSources(thumbWidth, thumbHeight, iconWidth, iconHeight) → {Array.<TRTCScreenCaptureSourceInfo>}

8.5 Enumerate shareable screens and windows

When you integrate the screen sharing feature of a desktop system, you generally need to display a UI for selecting the sharing target, so that users can use the UI to choose whether to share the entire screen or a certain window. Through this API, you can query the IDs, names, and thumbnails of sharable windows on the current system. We provide a default UI implementation in the demo for your reference. Notice: The returned list contains the screen and the application windows. The screen is the first element in the list. If the user has multiple displays, then each display is a sharing target.

Parameters:
Name Type Description
thumbWidth Number

Specify the thumbnail width of the window to be obtained. The thumbnail can be drawn on the window selection UI.

thumbHeight Number

Specify the thumbnail height of the window to be obtained. The thumbnail can be drawn on the window selection UI.

iconWidth Number

Specify the icon width of the window to be obtained.

iconHeight Number

Specify the icon height of the window to be obtained.

Returns:

List of windows (including the screen)

Type
Array.<TRTCScreenCaptureSourceInfo>

selectScreenCaptureTarget(source, captureRect, property)

8.6 Select the screen or window to share

After you get the sharable screens and windows through getScreenCaptureSources, you can call this API to select the target screen or window you want to share. During the screen sharing process, you can also call this API at any time to switch the sharing target.

The following four sharing modes are supported:

  • Sharing the entire screen: for source whose type is Screen in sourceInfoList, set captureRect to { 0, 0, 0, 0 }.
  • Sharing a specified area: for source whose type is Screen in sourceInfoList, set captureRect to a non-nullptr value, e.g., { 100, 100, 300, 300 }.
  • Sharing an entire window: for source whose type is Window in sourceInfoList, set captureRect to { 0, 0, 0, 0 }.
  • Sharing a specified window area: for source whose type is Window in sourceInfoList, set captureRect to a non-nullptr value, e.g., { 100, 100, 300, 300 }.
Parameters:
Name Type Description
source TRTCScreenCaptureSourceInfo

Specify sharing source. For more information, please see the definition of TRTCScreenCaptureSourceInfo.

captureRect Rect

Specify the area to be captured

property TRTCScreenCaptureProperty

Specify the attributes of the screen sharing target, such as capturing the cursor and highlighting the captured window. For more information, please see the definition of TRTCScreenCaptureProperty.

startScreenCapture(view, type, params)

8.7 Start desktop screen sharing

This API can capture the screen content of the entire macOS system or a specified application and share it with other users in the same room.

Notice:

  1. A user can publish at most one primary stream (TRTCVideoStreamTypeBig) and one substream (TRTCVideoStreamTypeSub) at the same time.
  2. By default, screen sharing uses the substream image. If you want to use the primary stream for screen sharing, you need to stop camera capturing (through stopLocalPreview) in advance to avoid conflicts.
  3. Only one user can use the substream for screen sharing in the same room at any time; that is, only one user is allowed to enable the substream in the same room at any time.
  4. When there is already a user in the room using the substream for screen sharing, calling this API will receive the onError(ERR_SERVER_CENTER_ANOTHER_USER_PUSH_SUB_VIDEO) event notification.
Parameters:
Name Type Default Description
view HTMLElement null

HTML Element where to preview the screen sharing effect

type TRTCVideoStreamType

Channel used for screen sharing, which can be the primary stream (TRTCVideoStreamTypeBig) or substream (TRTCVideoStreamTypeSub). Default value: TRTCVideoStreamTypeSub

params TRTCVideoEncParam null

Image encoding parameters used for screen sharing, which can be set to nil, indicating to let the SDK choose the optimal encoding parameters (such as resolution and bitrate).

pauseScreenCapture()

8.8 Pause screen sharing

resumeScreenCapture()

8.9 Resume screen sharing

stopScreenCapture()

8.10 Stop screen sharing

setSubStreamEncoderParam(params)

8.11 Set the video encoding parameters of screen sharing (i.e., substream)

This API can set the image quality of screen sharing (i.e., the substream) viewed by remote users, which is also the image quality of screen sharing in on-cloud recording files. Please note the differences between the following two APIs:

  • setVideoEncoderParam is used to set the video encoding parameters of the primary stream image (TRTCVideoStreamTypeBig, generally for camera).
  • setSubStreamEncoderParam is used to set the video encoding parameters of the substream image (TRTCVideoStreamTypeSub, generally for screen sharing).

Notice: Even if you use the primary stream to transfer screen sharing data (set type=TRTCVideoStreamTypeBig when calling startScreenCapture), you still need to call the setSubStreamEncoderParam API instead of the setVideoEncoderParam API to set the screen sharing encoding parameters.

Parameters:
Name Type Description
params TRTCVideoEncParam

Substream encoding parameters

Properties
Name Type Description
videoResolution TRTCVideoResolution

video resolution

resMode TRTCVideoResolutionMode

resolution mode (landscape/portrait)

  • TRTCVideoResolutionModeLandscape: Landscape resolution
  • TRTCVideoResolutionModePortrait : Portrait resolution
videoFps Number

video capturing frame rate

videoBitrate Number

target video bitrate. The SDK encodes streams at the target video bitrate and will actively reduce the bitrate only in weak network environments.

minVideoBitrate Number

minimum video bitrate. The SDK will reduce the bitrate to as low as the value specified by minVideoBitrate to ensure the smoothness only if the network conditions are poor.

setSubStreamMixVolume(volume)

8.12 Set the audio mixing volume of screen sharing

The greater the value, the larger the ratio of the screen sharing volume to the mic volume. We recommend you not set a high value for this parameter as a high volume will cover the mic sound.

Parameters:
Name Type Description
volume Number

Set audio mixing volume. Value range: 0–100

addExcludedShareWindow(win)

8.13 Add specified windows to the exclusion list of screen sharing

The excluded windows will not be shared. This feature is generally used to add a certain application's window to the exclusion list to avoid privacy issues. You can set the filtered windows before starting screen sharing or dynamically add the filtered windows during screen sharing.

Notice:

  1. This API takes effect only if the type in TRTCScreenCaptureSourceInfo is specified as TRTCScreenCaptureSourceTypeScreen; that is, the feature of excluding specified windows works only when the entire screen is shared.
  2. The windows added to the exclusion list through this API will be automatically cleared by the SDK after room exit.
  3. On macOS, please pass in the window ID (CGWindowID), which can be obtained through the sourceId member in TRTCScreenCaptureSourceInfo.
Parameters:
Name Type Description
win String

Window not to be shared

removeExcludedShareWindow(win)

8.14 Remove specified windows from the exclusion list of screen sharing

Parameters:
Name Type Description
win String

Window to be removed from exclusion list

removeAllExcludedShareWindow()

8.15 Remove all windows from the exclusion list of screen sharing

sendCustomCmdMsg(cmdId, msg, reliable, ordered) → {Boolean}

10.1 Use UDP channel to send custom message to all users in room

This API allows you to use TRTC's UDP channel to broadcast custom data to other users in the current room for signaling transfer. The UDP channel in TRTC was originally designed to transfer audio/video data. This API works by disguising the signaling data you want to send as audio/video data packets and sending them together with the audio/video data to be sent. Other users in the room can receive the message through the onRecvCustomCmdMsg event.

Notice:

  1. Up to 30 messages can be sent per second to all users in the room (this is not supported for web and mini program currently).
  2. A packet can contain up to 1 KB of data; if the threshold is exceeded, the packet is very likely to be discarded by the intermediate router or server.
  3. A client can send up to 8 KB of data in total per second.
  4. reliable and ordered must be set to the same value (true or false) and cannot be set to different values currently.
  5. We strongly recommend you set different cmdID values for messages of different types. This can reduce message delay when orderly sending is required.
Parameters:
Name Type Description
cmdId Number

Message ID. Value range: 1–10

msg String

Message to be sent. The maximum length of one single message is 1 KB.

reliable Boolean

Whether reliable sending is enabled. Reliable sending can achieve a higher success rate but with a longer reception delay than unreliable sending.

ordered Boolean

Whether orderly sending is enabled, i.e., whether the data packets should be received in the same order in which they are sent; if so, a certain delay will be caused.

Returns:

true: sent the message successfully; false: failed to send the message.

Type
Boolean

sendSEIMsg(msg, repeatCount) → {Boolean}

10.2 Use SEI channel to send custom message to all users in room

This API allows you to use TRTC's SEI channel to broadcast custom data to other users in the current room for signaling transfer. The header of a video frame has a header data block called SEI. This API works by embedding the custom signaling data you want to send in the SEI block and sending it together with the video frame. Therefore, the SEI channel has a better compatibility than sendCustomCmdMsg as the signaling data can be transferred to the CSS CDN along with the video frame. However, because the data block of the video frame header cannot be too large, we recommend you limit the size of the signaling data to only a few bytes when using this API. The most common use is to embed the custom timestamp into video frames through this API so as to implement a perfect alignment between the message and video image (such as between the teaching material and video signal in the education scenario). Other users in the room can receive the message through the onRecvSEIMsg event.

Notice: This API has the following restrictions:

    1. The data will not be instantly sent after this API is called; instead, it will be inserted into the next video frame after the API call.
  1. Up to 30 messages can be sent per second to all users in the room (this limit is shared with sendCustomCmdMsg).
  2. Each packet can be up to 1 KB (this limit is shared with sendCustomCmdMsg). If a large amount of data is sent, the video bitrate will increase, which may reduce the video quality or even cause lagging.
  3. Each client can send up to 8 KB of data in total per second (this limit is shared with sendCustomCmdMsg).
  4. If multiple times of sending is required (i.e., repeatCount > 1), the data will be inserted into subsequent repeatCount video frames in a row for sending, which will increase the video bitrate.
  5. If repeatCount is greater than 1, the data will be sent for multiple times, and the same message may be received multiple times in the onRecvSEIMsg event; therefore, deduplication is required.
Parameters:
Name Type Description
msg String

Data to be sent, which can be up to 1 KB (1,000 bytes)

repeatCount Number

Data sending count

Returns:

true: the message is allowed and will be sent with subsequent video frames; false: the message is not allowed to be sent

Type
Boolean

playBGM(path)

11.1 Play background music (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use startPlayMusic instead.
Parameters:
Name Type Description
path String

Path of the music file

stopBGM()

11.2 Stop background music (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use stopPlayMusic instead.

pauseBGM()

11.3 Pause background music (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use pausePlayMusic instead.

resumeBGM()

11.4 Resume background music (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use resumePlayMusic instead.

getBGMDuration(path) → {Number}

11.5 Get the total length of background music in ms (deprecated)

Deprecated:
Parameters:
Name Type Description
path String

Path of the music file

Returns:

The length of the specified music file is returned. -1 indicates failure to get the length.

Type
Number

setBGMPosition(pos)

11.6 Set background music playback progress (deprecated)

Deprecated:
Parameters:
Name Type Description
pos Number

Unit: ms

setBGMVolume(volume)

11.7 Set background music volume (deprecated)

When background music is started. This API is used to set background music volume for both local and remote user.

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use setAllMusicVolume instead.
Parameters:
Name Type Description
volume Number

Volume value. Value range: 0 - 200; default: 100

setBGMPlayoutVolume(volume)

11.8 Set the local playback volume of background music (deprecated)

When background music is started. This API can be used to set the playing volume of background music for local user.

Deprecated:
Parameters:
Name Type Description
volume Number

Volume value. Value range: 0 - 100. Default value: 100

setBGMPublishVolume(volume)

11.9 Set the remote playback volume of background music (deprecated)

When background music is started. This API can be used to set the playing volume of background music for remote user.

Deprecated:
Parameters:
Name Type Description
volume Number

Volume value. Value range: 0 - 100. Default value: 100

startSystemAudioLoopback(path)

11.10 Enable system audio capturing

This API captures audio data from the sound card of the anchor’s computer and mixes it into the current audio stream of the SDK. This ensures that other users in the room hear the audio played back by the anchor’s computer. In online education scenarios, a teacher can use this API to have the SDK capture the audio of instructional videos and broadcast it to students in the room. In live music scenarios, an anchor can use this API to have the SDK capture the music played back by his or her player so as to add background music to the room.

Parameters:
Name Type Description
path String

If this parameter is empty, the audio of the entire system is captured. If path is not empty, the path should be an App whose sound will be captured.

stopSystemAudioLoopback()

11.11 Stop system audio capturing

setSystemAudioLoopbackVolume(volume)

11.12 Set the volume of system audio capturing

Parameters:
Name Type Description
volume Number

Set volume. Value range: [0, 150]. Default value: 100

startPlayMusic(musicParam, callbackMap)

11.13 Starting background music

Example
// Play music
import TRTCCloud, { AudioMusicParam } from 'trtc-electron-sdk';
const rtcCloud = new TRTCCloud();

const params = new AudioMusicParam();
params.id = 1;
params.path = 'path';
params.publish = true;
rtcCloud.startPlayMusic(params, {
     onStart: (id: number, errCode: number) => {
       console.log(`onStart, id: ${id}, errorCode: ${errCode}`);
     },
     onPlayProgress: (id: number, curPtsMS: number, durationMS: number) => {
       console.log(`onPlayProgress, id: ${id}, curPtsMS: ${curPtsMS}, durationMS: ${durationMS}`);
     },
     onComplete: (id: number, errCode: number) => {
         console.log(`onComplete, id: ${id}, errCode: ${errCode}`);
     }
)
Parameters:
Name Type Description
musicParam AudioMusicParam

Music parameter

callbackMap Object

Optional, music play event callback map

Properties
Name Type Description
onStart function

Callback of starting music

onPlayProgress function

Callback of playback progress

onComplete function

Callback of ending music

stopPlayMusic(id)

11.14 Stopping background music

Parameters:
Name Type Description
id Number

Music ID

pausePlayMusic(id)

11.15 Pausing background music

Parameters:
Name Type Description
id Number

Music ID

resumePlayMusic(id)

11.16 Resuming background music

Parameters:
Name Type Description
id Number

Music ID

getMusicDurationInMS(path) → {Number}

11.17 Getting the total length (ms) of background music

Parameters:
Name Type Description
path String

Path of the music file

Returns:

The length of the specified music file is returned. -1 indicates failure to get the length.

Type
Number

seekMusicToPosInTime(id, pts)

11.18 Setting the playback progress (ms) of background music

Notice: Do not call this API frequently as the music file may be read and written to each time the API is called, which can be time-consuming. Wait till users finish dragging the progress bar before you call this API. The progress bar controller on the UI tends to update the progress at a high frequency as users drag the progress bar. This will result in poor user experience unless you limit the frequency.

Parameters:
Name Type Description
id Number

Music ID

pts Number

Unit: millisecond

setAllMusicVolume(volume)

11.19 Setting the local and remote playback volume of background music

This API is used to set the local and remote playback volume of background music.

  • Local volume: the volume of music heard by anchors
  • Remote volume: the volume of music heard by audience

Notice: If 100 is still not loud enough for you, you can set the volume to up to 150, but there may be side effects.

Parameters:
Name Type Description
volume Number

Volume value. Value range: 0 - 200; default: 100

setMusicPlayoutVolume(id, volume)

11.20 Setting the local playback volume of a specific music track

This API is used to control the local playback volume (the volume heard by anchors) of a specific music track.

Parameters:
Name Type Description
id Number

Music ID

volume Number

Volume. Value range: 0-100. default: 100

setMusicPublishVolume(id, volume)

11.21 Setting the remote playback volume of a specific music track

This API is used to control the remote playback volume (the volume heard by audience) of a specific music track.

Notice: If 100 is still not loud enough for you, you can set the volume to up to 150, but there may be side effects.

Parameters:
Name Type Description
id Number

Music ID

volume Number

Volume. Value range: 0-100; default: 100

playAudioEffect(effect)

12.1 Play audio effect (deprecated)

Each audio effect has a unique ID. You can use the ID to start, pause or stop the effect.

If you want to play several effect in the same time, please set different ID for each effect. If you use same ID for different effect, the last one will take effect.

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use startPlayMusic instead.
Parameters:
Name Type Description
effect TRTCAudioEffectParam

Sound effect parameter

Throws:
String

setAudioEffectVolume(effectId, volume)

12.2 Set audio effect volume (deprecated)

Notice: This API will override the volume setting by setAllAudioEffectsVolume.

Deprecated:
Parameters:
Name Type Description
effectId Number

Effect ID

volume Number

Volume value. Value range: 0 - 100. Default value: 100

stopAudioEffect(effectId)

12.3 Stop audio effect (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use stopPlayMusic instead.
Parameters:
Name Type Description
effectId Number

Effect ID

stopAllAudioEffects()

12.4 Stop all audio effects (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0.

setAllAudioEffectsVolume(volume)

12.5 Set all audio effects volume (deprecated)

Notice: This API will override the volume setting by setAudioEffectVolume.

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use setAllMusicVolume instead.
Parameters:
Name Type Description
volume Number

Volume Value. Value range: 0 - 100. Default value: 100

pauseAudioEffect(effectId)

12.6 Pause audio effect (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use pausePlayMusic instead.
Parameters:
Name Type Description
effectId Number

Effect ID

resumeAudioEffect(effectId)

12.7 Resume audio effect (deprecated)

Deprecated:
  • This API has been deprecated since TRTC SDK 8.0. Please use resumePlayMusic instead.
Parameters:
Name Type Description
effectId Number

Effect ID

startSpeedTest(params) → {Number}

13.1 Start network speed test (used before room entry)

As TRTC involves real-time audio/video transfer services very sensitive to the transfer latency, it has high requirements for network stability. For most users, if their network environments are below TRTC's minimum requirements, direct room entry will cause a very poor user experience. The recommended approach is to perform the network speed test before the user enters the room, so that a reminder can be displayed on the UI to prompt the user to switch to a better network (such as from Wi-Fi to 4G) first before room entry if the user's network is poor.

Notice:

  1. The speed measurement process will incur a small amount of basic service fees, See Purchase Guide > Base Services.
  2. Please perform the Network speed test before room entry, because if performed after room entry, the test will affect the normal audio/video transfer, and its result will be inaccurate due to interference in the room.
  3. Only one network speed test task is allowed to run at the same time.
Parameters:
Name Type Description
params TRTCSpeedTestParams

Speed test parameter.

Properties
Name Type Description
sdkAppId Number

Application ID. For more information, please see TRTCParams.

userId String

User ID. For more information, please see TRTCParams.

userSig String

User signature. For more information, please see TRTCParams.

expectedUpBandwidth Number

Expected upstream bandwidth (kbps, value range: 10 to 5000, no upstream bandwidth test when it is 0).

expectedDownBandwidth Number

Expected downstream bandwidth (kbps, value range: 10 to 5000, no downstream bandwidth test when it is 0).

Returns:

interface call result, <0: failure

Type
Number

stopSpeedTest()

13.2 Stop network speed test

startCameraDeviceTest(view)

13.3 Start camera testing

After calling this API, an onFirstVideoFrame event will be emitted.

Notice: You can use the setCurrentCameraDevice API to switch between cameras during testing.

Parameters:
Name Type Description
view HTMLElement

HTML Element the display the camera video image

stopCameraDeviceTest()

13.4 Stop camera testing

startMicDeviceTest(interval)

13.5 Start microphone testing

After calling this API, an onTestMicVolume event will be emitted.

This API is used to test whether the microphone functions properly. The microphone volume detected (value range: 0-100) is returned via onTestMicVolume event notification.

Parameters:
Name Type Description
interval Number

Interval of volume notification. Unit: ms. Better to be great than 200.

stopMicDeviceTest()

13.6 Stop microphone testing

startSpeakerDeviceTest(testAudioFilePath)

13.7 Start speaker testing

After calling this API, an onTestSpeakerVolume event will be emitted.

This API is used to test whether the audio playback device functions properly by playing a specified audio file. If users can hear audio during testing, the device functions properly.

Parameters:
Name Type Description
testAudioFilePath String

Path of the audio file. Path should be UTF-8 encoded. Support format: WAV, MP3.

stopSpeakerDeviceTest()

13.8 Stop speaker testing

getSDKVersion() → {String}

14.1 Get SDK version information

Returns:

UTF-8 encode version string

Type
String

setLogLevel(level)

14.2 Set log output level

Parameters:
Name Type Description
level TRTCLogLevel

Output log level,Default value: TRTCLogLevelNone

  • TRTCLogLevelNone : Do not output any SDK logs
  • TRTCLogLevelVerbose: Output logs at all levels
  • TRTCLogLevelDebug : Output logs at the DEBUG, INFO, WARNING, ERROR, and FATAL levels
  • TRTCLogLevelInfo : Output logs at the INFO, WARNING, ERROR, and FATAL levels
  • TRTCLogLevelWarn : Output logs at the WARNING, ERROR, and FATAL levels
  • TRTCLogLevelError : Output logs at the ERROR and FATAL levels
  • TRTCLogLevelFatal : Output logs at the FATAL level

setConsoleEnabled(enabled)

14.3 Enable/Disable console log printing

Parameters:
Name Type Description
enabled Boolean

Specify whether to enable it, which is disabled by default

setLogCompressEnabled(enabled)

14.4 Enable/Disable local log compression

If compression is enabled, the log size will significantly reduce, but logs can be read only after being decompressed by the Python script provided by Tencent Cloud. If compression is disabled, logs will be stored in plaintext and can be read directly in Notepad, but will take up more storage capacity.

Parameters:
Name Type Description
enabled Boolean

Specify whether to enable it, which is enabled by default

setLogDirPath(path)

14.5 Set local log storage path

You can use this API to change the default storage path of the SDK's local logs, which is as follows:

  • Windows: C:/Users/[username]/AppData/Roaming/liteav/log, i.e., under %appdata%/liteav/log.
  • macOS: under sandbox Documents/log.

Notice: Please be sure to call this API before all other APIs and make sure that the directory you specify exists and your application has read/write permissions of the directory.

Parameters:
Name Type Description
path String

Log storage path, should be UTF-8 encoded string

setLogCallback(callback)

14.6 Set log callback

Parameters:
Name Type Description
callback function

callback function

callExperimentalAPI(jsonStr)

14.7 Call experimental APIs

Notice: This API is used to enable some experimental feature

Parameters:
Name Type Description
jsonStr String

JSON string of experimental interface and parameter configuration

setRenderMode(mode)

Set render mode

Parameters:
Name Type Default Description
mode Number 1
  • 1 webgl
  • 2 yuvcanvs