@tencent-rtc/mcp 1.0.2 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/resource/doc/rtcengine/faq/web.md +309 -0
- package/resource/doc/rtcengine/web/.gitkeep +0 -0
- package/resource/doc/rtcengine/web/api_RTCEngine.md +2425 -0
- package/resource/doc/rtcengine/web/how_to_integrated_web_rtc_engine.md +492 -0
- package/resource/doc/rtcengine/web/how_to_run_web_rtc_engine_demo.md +63 -0
- package/resource/doc/tuicallkit/react/how_to_integrated_react_callkit.md +84 -55
- package/server.js +30 -0
- package/server.js.map +1 -1
|
@@ -0,0 +1,2425 @@
|
|
|
1
|
+
# TRTC
|
|
2
|
+
|
|
3
|
+
The TRTC object is created using [TRTC.create()](#create) and provides core real-time audio and video capabilities:
|
|
4
|
+
|
|
5
|
+
- Enter an audio and video room [enterRoom()](#enterroom)
|
|
6
|
+
- Exit the current audio and video room [exitRoom()](#exitroom)
|
|
7
|
+
- Preview/publish local video [startLocalVideo()](#startlocalvideo)
|
|
8
|
+
- Capture/publish local audio [startLocalAudio()](#startlocalaudio)
|
|
9
|
+
- Stop previewing/publishing local video [stopLocalVideo()](#stoplocalvideo)
|
|
10
|
+
- Stop capturing/publishing local audio [stopLocalAudio()](#stoplocalaudio)
|
|
11
|
+
- Watch remote video [startRemoteVideo()](#startremotevideo)
|
|
12
|
+
- Stop watching remote video [stopRemoteVideo()](#stopremotevideo)
|
|
13
|
+
- Mute/unmute remote audio [muteRemoteAudio()](#muteremoteaudio)
|
|
14
|
+
|
|
15
|
+
The TRTC lifecycle is shown in the following figure:
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
## Methods
|
|
20
|
+
|
|
21
|
+
### create()
|
|
22
|
+
|
|
23
|
+
Create a TRTC object for implementing functions such as entering a room, previewing, publishing, and subscribing streams.
|
|
24
|
+
|
|
25
|
+
**Note:**
|
|
26
|
+
- You must create a TRTC object first and call its methods and listen to its events to implement various functions required by the business.
|
|
27
|
+
|
|
28
|
+
#### Example
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
// Create a TRTC object
|
|
32
|
+
const trtc = TRTC.create();
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
#### Parameters:
|
|
36
|
+
|
|
37
|
+
| Name | Type | Default | Description |
|
|
38
|
+
|------|------|---------|-------------|
|
|
39
|
+
| `options.plugins` | Array | | List of registered plugins (optional). |
|
|
40
|
+
| `options.enableSEI` | boolean | `false` | Whether to enable SEI sending and receiving function (optional). [Reference document](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/en/TRTC.html#sendSEIMessage) |
|
|
41
|
+
| `options.assetsPath` | string | | The address of the static resource file that the plugin depends on (optional).<br>- Publish the node_modules/trtc-sdk-v5/assets directory to CDN or static resource server.<br>- Set the assetsPath parameter to the CDN address, for example: `TRTC.create({ assetsPath: 'https://xxx/assets' })`, the SDK will load the relevant resource files on demand. |
|
|
42
|
+
| `options.userDefineRecordId` | string | | is used to set the userDefineRecordId of cloud recording (optional).<br>- [Recommended value] The length is limited to 64 bytes, and only uppercase and lowercase English letters (a-zA-Z), numbers (0-9), underscores, and hyphens are allowed.<br>- [Reference document] [Cloud recording](https://trtc.io/document/45169?product=rtcengine&menulabel=serverfeaturesapis). |
|
|
43
|
+
|
|
44
|
+
#### Returns:
|
|
45
|
+
TRTC object
|
|
46
|
+
|
|
47
|
+
**Type:** [TRTC](#)
|
|
48
|
+
|
|
49
|
+
### enterRoom(options)
|
|
50
|
+
|
|
51
|
+
Enter a video call room.
|
|
52
|
+
|
|
53
|
+
- Entering a room means starting a video call session. Only after entering the room successfully can you make audio and video calls with other users in the room.
|
|
54
|
+
- You can publish local audio and video streams through [startLocalVideo()](#startlocalvideo) and [startLocalAudio()](#startlocalaudio) respectively. After successful publishing, other users in the room will receive the [REMOTE_AUDIO_AVAILABLE](../module-EVENT.html#remote_audio_available) and [REMOTE_VIDEO_AVAILABLE](../module-EVENT.html#remote_video_available) event notifications.
|
|
55
|
+
- By default, the SDK automatically plays remote audio. You need to call [startRemoteVideo()](#startremotevideo) to play remote video.
|
|
56
|
+
|
|
57
|
+
#### Example
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
const trtc = TRTC.create();
|
|
61
|
+
await trtc.enterRoom({ roomId: 8888, sdkAppId, userId, userSig });
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### Parameters:
|
|
65
|
+
|
|
66
|
+
| Name | Type | Description |
|
|
67
|
+
|------|------|-------------|
|
|
68
|
+
| `options` | object | **required** Enter room parameters |
|
|
69
|
+
|
|
70
|
+
**Properties:**
|
|
71
|
+
|
|
72
|
+
| Name | Type | Default | Description |
|
|
73
|
+
|------|------|---------|-------------|
|
|
74
|
+
| `sdkAppId` | number | | **required** sdkAppId <br>You can obtain the sdkAppId information in the **Application Information** section after creating a new application by clicking **Application Management** > **Create Application** in the [TRTC Console](https://console.trtc.io/). |
|
|
75
|
+
| `userId` | string | | **required** User ID <br>It is recommended to limit the length to 32 bytes, and only allow uppercase and lowercase English letters (a-zA-Z), numbers (0-9), underscores, and hyphens. |
|
|
76
|
+
| `userSig` | string | | **required** UserSig signature <br>Please refer to [UserSig related](https://trtc.io/document/35166?platform=web&product=rtcengine&menulabel=coresdk) for the calculation method of userSig. |
|
|
77
|
+
| `roomId` | number | | the value must be an integer between 1 and 4294967294<br><font color="red">If you need to use a string type room id, please use the strRoomId parameter. One of roomId and strRoomId must be passed in. If both are passed in, the roomId will be selected first.</font> |
|
|
78
|
+
| `strRoomId` | string | | String type room id, the length is limited to 64 bytes, and only supports the following characters:<br>- Uppercase and lowercase English letters (a-zA-Z)<br>- Numbers (0-9)<br>- Space ! # $ % & ( ) + - : ; < = . > ? @ [ ] ^ _ { } \| ~ ,<br><font color="red">Note: It is recommended to use a numeric type roomId. The string type room id "123" is not the same room as the numeric type room id 123.</font> |
|
|
79
|
+
| `scene` | string | | Application scene, currently supports the following two scenes:<br>- [TRTC.TYPE.SCENE_RTC](../module-TYPE.html#scene_rtc) (default) Real-time call scene, which is suitable for 1-to-1 audio and video calls, or online meetings with up to 300 participants. [Upstream Users Limitation](../tutorial-04-info-uplink-limits.html).<br>- [TRTC.TYPE.SCENE_LIVE](../module-TYPE.html#scene_live) Interactive live streaming scene, which is suitable for online live streaming scenes with up to 100,000 people, but you need to specify the role field in the options parameter introduced next. |
|
|
80
|
+
| `role` | string | | User role, only meaningful in the [TRTC.TYPE.SCENE_LIVE](../module-TYPE.html#scene_live) scene, and the [TRTC.TYPE.SCENE_RTC](../module-TYPE.html#scene_rtc) scene does not need to specify the role. Currently supports two roles:<br>- [TRTC.TYPE.ROLE_ANCHOR](../module-TYPE.html#role_anchor) (default) Anchor<br>- [TRTC.TYPE.ROLE_AUDIENCE](../module-TYPE.html#role_audience) Audience<br>Note: The audience role does not have the permission to publish local audio and video, only the permission to watch remote streams. If the audience wants to interact with the anchor by connecting to the microphone, please switch the role to the anchor through [switchRole()](#switchrole) before publishing local audio and video. |
|
|
81
|
+
| `autoReceiveAudio` | boolean | `true` | Whether to automatically receive audio. When a remote user publishes audio, the SDK automatically plays the remote user's audio. |
|
|
82
|
+
| `autoReceiveVideo` | boolean | `false` | Whether to automatically receive video. When a remote user publishes video, the SDK automatically subscribes and decodes the remote video. You need to call [startRemoteVideo()](#startremotevideo) to play the remote video.<br>- The default value was changed to `false` since v5.6.0. Refer to [Breaking Changed for v5.6.0](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/en/tutorial-00-info-update-guideline.html). |
|
|
83
|
+
| `enableAutoPlayDialog` | boolean | | Whether to enable the SDK's automatic playback failure dialog box, default: true.<br>- Enabled by default. When automatic playback fails, the SDK will pop up a dialog box to guide the user to click the page to restore audio and video playback.<br>- Can be set to false in order to turn off. Refer to [Handle Autoplay Restriction](../tutorial-21-advanced-auto-play-policy.html). |
|
|
84
|
+
| `proxy` | string \| [ProxyServer](../global.html#proxyserver) | | proxy config. Refer to [Handle Firewall Restriction](../tutorial-34-advanced-proxy.html). |
|
|
85
|
+
| `privateMapKey` | string | | Key for entering a room. If permission control is required, please carry this parameter (empty or incorrect value will cause a failure in entering the room).<br>[privateMapKey permission configuration](https://trtc.io/document/35157?product=rtcengine). |
|
|
86
|
+
|
|
87
|
+
#### Throws:
|
|
88
|
+
- [INVALID_PARAMETER](../module-ERROR_CODE.html#invalid_parameter)
|
|
89
|
+
- [OPERATION_FAILED](../module-ERROR_CODE.html#operation_failed)
|
|
90
|
+
- [OPERATION_ABORT](../module-ERROR_CODE.html#operation_abort)
|
|
91
|
+
- [ENV_NOT_SUPPORTED](../module-ERROR_CODE.html#env_not_supported)
|
|
92
|
+
- [SERVER_ERROR](../module-ERROR_CODE.html#server_error)
|
|
93
|
+
|
|
94
|
+
### exitRoom()
|
|
95
|
+
|
|
96
|
+
Exit the current audio and video call room.
|
|
97
|
+
|
|
98
|
+
- After exiting the room, the connection with remote users will be closed, and remote audio and video will no longer be received and played, and the publishing of local audio and video will be stopped.
|
|
99
|
+
- The capture and preview of the local camera and microphone will not stop. You can call [stopLocalVideo()](#stoplocalvideo) and [stopLocalAudio()](#stoplocalaudio) to stop capturing local microphone and camera.
|
|
100
|
+
|
|
101
|
+
#### Example
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
await trtc.exitRoom();
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### Throws:
|
|
108
|
+
[OPERATION_ABORT](../module-ERROR_CODE.html#operation_abort)
|
|
109
|
+
|
|
110
|
+
### switchRoom(options)
|
|
111
|
+
|
|
112
|
+
Switch a video call room.
|
|
113
|
+
|
|
114
|
+
- Switch the video call room that the audience is watching in live scene. It is faster than exit old room and then entering the new room, and can optimize the opening time in live broadcast and other scenarios.
|
|
115
|
+
- [Contact us](https://trtc.io/contact) to enable this API.
|
|
116
|
+
|
|
117
|
+
#### Example
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
const trtc = TRTC.create();
|
|
121
|
+
await trtc.enterRoom({
|
|
122
|
+
...
|
|
123
|
+
roomId: 8888,
|
|
124
|
+
scene: TRTC.TYPE.SCENE_LIVE,
|
|
125
|
+
role: TRTC.TYPE.ROLE_AUDIENCE
|
|
126
|
+
});
|
|
127
|
+
await trtc.switchRoom({
|
|
128
|
+
userSig,
|
|
129
|
+
roomId: 9999
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### Parameters:
|
|
134
|
+
|
|
135
|
+
| Name | Type | Description |
|
|
136
|
+
|------|------|-------------|
|
|
137
|
+
| `options` | object | **required** Switch room parameters |
|
|
138
|
+
|
|
139
|
+
**Properties:**
|
|
140
|
+
|
|
141
|
+
| Name | Type | Description |
|
|
142
|
+
|------|------|-------------|
|
|
143
|
+
| `userSig` | string | **required** UserSig signature <br>Please refer to [UserSig related](https://trtc.io/document/35166) for the calculation method of userSig. <br /> |
|
|
144
|
+
| `roomId` | number | the value must be an integer between 1 and 4294967294<br><font color="red">Note: <br>1. The room to be switched and the current room must be of the same room type (both digital rooms or string rooms)<br> 2. Either roomId or strRoomId must be filled in. If both are filled in, roomId is preferred. </font> |
|
|
145
|
+
| `strRoomId` | string | String type room id, the length is limited to 64 bytes, and only supports the following characters:<br>- Uppercase and lowercase English letters (a-zA-Z)<br>- Numbers (0-9)<br>- Space ! # $ % & ( ) + - : ; < = . > ? @ [ ] ^ _ { } \| ~ , |
|
|
146
|
+
| `privateMapKey` | boolean | Key for entering a room. If permission control is required, please carry this parameter (empty or incorrect value will cause a failure in entering the room).<br>[privateMapKey permission configuration](https://trtc.io/document/35157?product=rtcengine). |
|
|
147
|
+
|
|
148
|
+
#### Throws:
|
|
149
|
+
- [INVALID_PARAMETER](../module-ERROR_CODE.html#invalid_parameter)
|
|
150
|
+
- [OPERATION_FAILED](../module-ERROR_CODE.html#operation_failed)
|
|
151
|
+
- [OPERATION_ABORT](../module-ERROR_CODE.html#operation_abort)
|
|
152
|
+
- [SERVER_ERROR](../module-ERROR_CODE.html#server_error)
|
|
153
|
+
|
|
154
|
+
### switchRole(role, option)
|
|
155
|
+
|
|
156
|
+
Switches the user role, only effective in TRTC.TYPE.SCENE_LIVE interactive live streaming mode.
|
|
157
|
+
|
|
158
|
+
In interactive live streaming mode, a user may need to switch between "audience" and "anchor".
|
|
159
|
+
You can determine the role through the role field in [enterRoom()](#enterroom), or switch roles after entering the room through switchRole.
|
|
160
|
+
|
|
161
|
+
- Audience switches to anchor, call trtc.switchRole(TRTC.TYPE.ROLE_ANCHOR) to convert the user role to TRTC.TYPE.ROLE_ANCHOR anchor role, and then call [startLocalVideo()](#startlocalvideo) and [startLocalAudio()](#startlocalaudio) to publish local audio and video as needed.
|
|
162
|
+
- Anchor switches to audience, call trtc.switchRole(TRTC.TYPE.ROLE_AUDIENCE) to convert the user role to TRTC.TYPE.ROLE_AUDIENCE audience role. If there is already published local audio and video, the SDK will cancel the publishing of local audio and video.
|
|
163
|
+
|
|
164
|
+
> **Notice:**
|
|
165
|
+
> - This interface can only be called after entering the room successfully.
|
|
166
|
+
> - After closing the camera and microphone, it is recommended to switch to the audience role in time to avoid the anchor role occupying the resources of 50 upstreams.
|
|
167
|
+
|
|
168
|
+
#### Examples
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
// After entering the room successfully
|
|
172
|
+
// TRTC.TYPE.SCENE_LIVE interactive live streaming mode, audience switches to anchor
|
|
173
|
+
await trtc.switchRole(TRTC.TYPE.ROLE_ANCHOR);
|
|
174
|
+
// Switch from audience role to anchor role and start streaming
|
|
175
|
+
await trtc.startLocalVideo();
|
|
176
|
+
// TRTC.TYPE.SCENE_LIVE interactive live streaming mode, anchor switches to audience
|
|
177
|
+
await trtc.switchRole(TRTC.TYPE.ROLE_AUDIENCE);
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
```javascript
|
|
181
|
+
// Since v5.3.0+
|
|
182
|
+
await trtc.switchRole(TRTC.TYPE.ROLE_ANCHOR, { privateMapKey: 'your new privateMapKey' });
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### Parameters:
|
|
186
|
+
|
|
187
|
+
| Name | Type | Description |
|
|
188
|
+
|------|------|-------------|
|
|
189
|
+
| `role` | string | **required** User role<br>- TRTC.TYPE.ROLE_ANCHOR anchor, can publish local audio and video, up to 50 anchors can publish local audio and video in a single room at the same time.<br>- TRTC.TYPE.ROLE_AUDIENCE audience, cannot publish local audio and video, can only watch remote streams, and there is no upper limit on the number of audience members in a single room. |
|
|
190
|
+
| `option` | object | Optional parameters |
|
|
191
|
+
|
|
192
|
+
**Properties:**
|
|
193
|
+
|
|
194
|
+
| Name | Type | Description |
|
|
195
|
+
|------|------|-------------|
|
|
196
|
+
| `privateMapKey` | string | **Since v5.3.0+** <br>The privateMapKey may expire after a timeout, so you can use this parameter to update the privateMapKey. |
|
|
197
|
+
|
|
198
|
+
#### Throws:
|
|
199
|
+
- [INVALID_PARAMETER](../module-ERROR_CODE.html#invalid_parameter)
|
|
200
|
+
- [INVALID_OPERATION](../module-ERROR_CODE.html#invalid_operation)
|
|
201
|
+
- [OPERATION_FAILED](../module-ERROR_CODE.html#operation_failed)
|
|
202
|
+
- [OPERATION_ABORT](../module-ERROR_CODE.html#operation_abort)
|
|
203
|
+
- [SERVER_ERROR](../module-ERROR_CODE.html#server_error)
|
|
204
|
+
|
|
205
|
+
### destroy()
|
|
206
|
+
|
|
207
|
+
Destroy the TRTC instance
|
|
208
|
+
|
|
209
|
+
After exiting the room, if the business side no longer needs to use trtc, you need to call this interface to destroy the trtc instance in time and release related resources.
|
|
210
|
+
|
|
211
|
+
**Note:**
|
|
212
|
+
- The trtc instance after destruction cannot be used again.
|
|
213
|
+
- If you have entered the room, you need to call the [TRTC.exitRoom](#exitroom) interface to exit the room successfully before calling this interface to destroy trtc.
|
|
214
|
+
|
|
215
|
+
#### Example
|
|
216
|
+
|
|
217
|
+
```javascript
|
|
218
|
+
// When the call is over
|
|
219
|
+
await trtc.exitRoom();
|
|
220
|
+
// If the trtc is no longer needed, destroy the trtc and release the reference.
|
|
221
|
+
trtc.destroy();
|
|
222
|
+
trtc = null;
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
#### Throws:
|
|
226
|
+
[OPERATION_FAILED](../module-ERROR_CODE.html#operation_failed)
|
|
227
|
+
|
|
228
|
+
### startLocalAudio(config)
|
|
229
|
+
|
|
230
|
+
Start collecting audio from the local microphone and publish it to the current room.
|
|
231
|
+
|
|
232
|
+
- When to call: can be called before or after entering the room, cannot be called repeatedly.
|
|
233
|
+
- Only one microphone can be opened for a trtc instance. If you need to open another microphone for testing in the case of already opening one microphone, you can create multiple trtc instances to achieve it.
|
|
234
|
+
|
|
235
|
+
#### Examples
|
|
236
|
+
|
|
237
|
+
```javascript
|
|
238
|
+
// Collect the default microphone and publish
|
|
239
|
+
await trtc.startLocalAudio();
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
```javascript
|
|
243
|
+
// The following is a code example for testing microphone volume, which can be used for microphone volume detection.
|
|
244
|
+
trtc.enableAudioVolumeEvaluation();
|
|
245
|
+
trtc.on(TRTC.EVENT.AUDIO_VOLUME, event => { });
|
|
246
|
+
// No need to publish audio for testing microphone
|
|
247
|
+
await trtc.startLocalAudio({ publish: false });
|
|
248
|
+
// After the test is completed, turn off the microphone
|
|
249
|
+
await trtc.stopLocalAudio();
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
#### Parameters:
|
|
253
|
+
|
|
254
|
+
| Name | Type | Description |
|
|
255
|
+
|------|------|-------------|
|
|
256
|
+
| `config` | object | Configuration item |
|
|
257
|
+
|
|
258
|
+
**Properties:**
|
|
259
|
+
|
|
260
|
+
| Name | Type | Description |
|
|
261
|
+
|------|------|-------------|
|
|
262
|
+
| `publish` | boolean | Whether to publish local audio to the room, default is true. If you call this interface before entering the room and publish = true, the SDK will automatically publish after entering the room. You can get the publish state by listening this event [PUBLISH_STATE_CHANGED](../module-EVENT.html#publish_state_changed). |
|
|
263
|
+
| `mute` | boolean | Whether to mute microphone. Refer to: [Turn On/Off Camera/Mic](../tutorial-15-basic-dynamic-add-video.html). |
|
|
264
|
+
| `option` | object | Local audio options |
|
|
265
|
+
|
|
266
|
+
**Properties:**
|
|
267
|
+
|
|
268
|
+
| Name | Type | Description |
|
|
269
|
+
|------|------|-------------|
|
|
270
|
+
| `microphoneId` | string | Specify which microphone to use |
|
|
271
|
+
| `audioTrack` | MediaStreamTrack | Custom audioTrack. [Custom Capturing and Rendering](../tutorial-20-advanced-customized-capture-rendering.html). |
|
|
272
|
+
| `captureVolume` | number | Set the capture volume of microphone. The default value is 100. Setting above 100 enlarges the capture volume. Since v5.2.1+. |
|
|
273
|
+
| `earMonitorVolume` | number | Set the ear return volume, value range [0, 100], the local microphone is muted by default. |
|
|
274
|
+
| `profile` | string | Audio encoding configuration, default [TRTC.TYPE.AUDIO_PROFILE_STANDARD](../module-TYPE.html#audio_profile_standard) |
|
|
275
|
+
|
|
276
|
+
#### Throws:
|
|
277
|
+
- [ENV_NOT_SUPPORTED](../module-ERROR_CODE.html#env_not_supported)
|
|
278
|
+
- [INVALID_PARAMETER](../module-ERROR_CODE.html#invalid_parameter)
|
|
279
|
+
- [DEVICE_ERROR](../module-ERROR_CODE.html#device_error)
|
|
280
|
+
- [OPERATION_FAILED](../module-ERROR_CODE.html#operation_failed)
|
|
281
|
+
- [OPERATION_ABORT](../module-ERROR_CODE.html#operation_abort)
|
|
282
|
+
- [SERVER_ERROR](../module-ERROR_CODE.html#server_error)
|
|
283
|
+
|
|
284
|
+
### updateLocalAudio(config)
|
|
285
|
+
|
|
286
|
+
Update the configuration of the local microphone.
|
|
287
|
+
|
|
288
|
+
- When to call: This interface needs to be called after [startLocalAudio()](#startlocalaudio) is successful and can be called multiple times.
|
|
289
|
+
- This method uses incremental update: only update the passed parameters, and keep the parameters that are not passed unchanged.
|
|
290
|
+
|
|
291
|
+
#### Example
|
|
292
|
+
|
|
293
|
+
```javascript
|
|
294
|
+
// Switch microphone
|
|
295
|
+
const microphoneList = await TRTC.getMicrophoneList();
|
|
296
|
+
if (microphoneList[1]) {
|
|
297
|
+
await trtc.updateLocalAudio({ option: { microphoneId: microphoneList[1].deviceId }});
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
#### Parameters:
|
|
302
|
+
|
|
303
|
+
| Name | Type | Description |
|
|
304
|
+
|------|------|-------------|
|
|
305
|
+
| `config` | object | Configuration item |
|
|
306
|
+
|
|
307
|
+
**Properties:**
|
|
308
|
+
|
|
309
|
+
| Name | Type | Description |
|
|
310
|
+
|------|------|-------------|
|
|
311
|
+
| `publish` | boolean | Whether to publish local audio to the room. You can get the publish state by listening this event [PUBLISH_STATE_CHANGED](../module-EVENT.html#publish_state_changed). |
|
|
312
|
+
| `mute` | boolean | Whether to mute microphone. Refer to: [Turn On/Off Camera/Mic](../tutorial-15-basic-dynamic-add-video.html). |
|
|
313
|
+
| `option` | object | Local audio configuration |
|
|
314
|
+
|
|
315
|
+
**Properties:**
|
|
316
|
+
|
|
317
|
+
| Name | Type | Description |
|
|
318
|
+
|------|------|-------------|
|
|
319
|
+
| `microphoneId` | string | Specify which microphone to use to switch microphones. |
|
|
320
|
+
| `audioTrack` | MediaStreamTrack | Custom audioTrack. [Custom Capturing and Rendering](../tutorial-20-advanced-customized-capture-rendering.html). |
|
|
321
|
+
| `captureVolume` | number | Set the capture volume of microphone. The default value is 100. Setting above 100 enlarges the capture volume. Since v5.2.1+. |
|
|
322
|
+
| `earMonitorVolume` | number | Set the ear return volume, value range [0, 100], the local microphone is muted by default. |
|
|
323
|
+
|
|
324
|
+
#### Throws:
|
|
325
|
+
- [INVALID_PARAMETER](../module-ERROR_CODE.html#invalid_parameter)
|
|
326
|
+
- [DEVICE_ERROR](../module-ERROR_CODE.html#device_error)
|
|
327
|
+
- [OPERATION_FAILED](../module-ERROR_CODE.html#operation_failed)
|
|
328
|
+
- [OPERATION_ABORT](../module-ERROR_CODE.html#operation_abort)
|
|
329
|
+
|
|
330
|
+
### stopLocalAudio()
|
|
331
|
+
|
|
332
|
+
Stop collecting and publishing the local microphone.
|
|
333
|
+
|
|
334
|
+
- If you just want to mute the microphone, please use updateLocalAudio({ mute: true }). Refer to: [Turn On/Off Camera/Mic](../tutorial-15-basic-dynamic-add-video.html).
|
|
335
|
+
|
|
336
|
+
#### Example
|
|
337
|
+
|
|
338
|
+
```javascript
|
|
339
|
+
await trtc.stopLocalAudio();
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
#### Throws:
|
|
343
|
+
[OPERATION_ABORT](../module-ERROR_CODE.html#operation_abort)
|
|
344
|
+
|
|
345
|
+
### startLocalVideo(config)
|
|
346
|
+
|
|
347
|
+
Start collecting video from the local camera, play the camera's video on the specified HTMLElement tag, and publish the camera's video to the current room.
|
|
348
|
+
|
|
349
|
+
- When to call: can be called before or after entering the room, but cannot be called repeatedly.
|
|
350
|
+
- Only one camera can be started per TRTC instance. If you need to start another camera for testing while one camera is already started, you can create multiple TRTC instances to achieve this.
|
|
351
|
+
|
|
352
|
+
#### Examples
|
|
353
|
+
|
|
354
|
+
```javascript
|
|
355
|
+
// Preview and publish the camera
|
|
356
|
+
await trtc.startLocalVideo({
|
|
357
|
+
view: document.getElementById('localVideo'), // Preview the video on the element with the DOM elementId of localVideo.
|
|
358
|
+
});
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
```javascript
|
|
362
|
+
// Preview the camera without publishing. Can be used for camera testing.
|
|
363
|
+
const config = {
|
|
364
|
+
view: document.getElementById('localVideo'), // Preview the video on the element with the DOM elementId of localVideo.
|
|
365
|
+
publish: false // Do not publish the camera
|
|
366
|
+
}
|
|
367
|
+
await trtc.startLocalVideo(config);
|
|
368
|
+
// Call updateLocalVideo when you need to publish the video
|
|
369
|
+
await trtc.updateLocalVideo({ publish: true });
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
```javascript
|
|
373
|
+
// Use a specified camera.
|
|
374
|
+
const cameraList = await TRTC.getCameraList();
|
|
375
|
+
if (cameraList[0]) {
|
|
376
|
+
await trtc.startLocalVideo({
|
|
377
|
+
view: document.getElementById('localVideo'), // Preview the video on the element with the DOM elementId of localVideo.
|
|
378
|
+
option: {
|
|
379
|
+
cameraId: cameraList[0].deviceId,
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
// Use the front camera on a mobile device.
|
|
384
|
+
await trtc.startLocalVideo({ view, option: { useFrontCamera: true }});
|
|
385
|
+
// Use the rear camera on a mobile device.
|
|
386
|
+
await trtc.startLocalVideo({ view, option: { useFrontCamera: false }});
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
#### Parameters:
|
|
390
|
+
|
|
391
|
+
| Name | Type | Description |
|
|
392
|
+
|------|------|-------------|
|
|
393
|
+
| `config` | object | Configuration item |
|
|
394
|
+
|
|
395
|
+
**Properties:**
|
|
396
|
+
|
|
397
|
+
| Name | Type | Description |
|
|
398
|
+
|------|------|-------------|
|
|
399
|
+
| `view` | string \| HTMLElement \| Array.\<HTMLElement> \| null | The HTMLElement instance or ID for local video preview. If not passed or passed as null, the video will not be played. |
|
|
400
|
+
| `publish` | boolean | Whether to publish the local video to the room. If you call this interface before entering the room and publish = true, the SDK will automatically publish after entering the room. You can get the publish state by listening to this event [PUBLISH_STATE_CHANGED](../module-EVENT.html#publish_state_changed). |
|
|
401
|
+
| `mute` | boolean \| string | Whether to mute the camera. Supports passing in an image URL string, the image will be published instead of the original camera stream. Other users in the room will receive the REMOTE_VIDEO_AVAILABLE event. It does not support calling when the camera is turned off. More information: [Turn On/Off Camera/Mic](../tutorial-15-basic-dynamic-add-video.html). |
|
|
402
|
+
| `option` | object | Local video configuration |
|
|
403
|
+
|
|
404
|
+
**Properties:**
|
|
405
|
+
|
|
406
|
+
| Name | Type | Description |
|
|
407
|
+
|------|------|-------------|
|
|
408
|
+
| `cameraId` | string | Specify which camera to use for switching cameras. |
|
|
409
|
+
| `useFrontCamera` | boolean | Whether to use the front camera. |
|
|
410
|
+
| `videoTrack` | MediaStreamTrack | Custom videoTrack. [Custom Capturing and Rendering](../tutorial-20-advanced-customized-capture-rendering.html). |
|
|
411
|
+
| `mirror` | 'view' \| 'publish' \| 'both' \| boolean | Video mirroring mode, default is 'view'.<br>- 'view': You see yourself as a mirror image, and the other person sees you as a non-mirror image.<br>- 'publish': The other person sees you as a mirror image, and you see yourself as a non-mirror image.<br>- 'both': You see yourself as a mirror image, and the other person sees you as a mirror image.<br>- false: Boolean value, represents no mirroring.<br><font color="orange"> Note: Before version 5.3.2, only boolean can be passed, where true represents local preview mirroring, and false represents no mirroring.</font> |
|
|
412
|
+
| `fillMode` | 'contain' \| 'cover' \| 'fill' | Video fill mode. The default is `cover`. Refer to the [CSS object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) property. |
|
|
413
|
+
| `profile` | string \| [VideoProfile](../global.html#videoprofile) | Video encoding parameters for the main video. Default value is `480p_2`. |
|
|
414
|
+
| `small` | string \| boolean \| [VideoProfile](../global.html#videoprofile) | Video encoding parameters for the small video. Refer to [Multi-Person Video Calls](../tutorial-27-advanced-small-stream.html) |
|
|
415
|
+
| `qosPreference` | QOS_PREFERENCE_SMOOTH \| QOS_PREFERENCE_CLEAR | Set the video encoding strategy for weak networks. Smooth first (default) ([QOS_PREFERENCE_SMOOTH](../module-TYPE.html#qos_preference_smooth)) or Clear first ([QOS_PREFERENCE_CLEAR](../module-TYPE.html#qos_preference_clear)). |
|
|
416
|
+
| `avoidCropping` | boolean | On PC Chrome and Firefox, capturing low-resolution 16/9 videos like 360p or 180p may result in cropping issues. Setting this parameter to true can avoid cropping. |
|
|
417
|
+
| `rotation` | 0 \| 90 \| 180 \| 270 | Set the clockwise rotation angle of the local camera. Since `v5.11.0`. |
|
|
418
|
+
|
|
419
|
+
#### Throws:
|
|
420
|
+
- [ENV_NOT_SUPPORTED](../module-ERROR_CODE.html#env_not_supported)
|
|
421
|
+
- [INVALID_PARAMETER](../module-ERROR_CODE.html#invalid_parameter)
|
|
422
|
+
- [DEVICE_ERROR](../module-ERROR_CODE.html#device_error)
|
|
423
|
+
- [OPERATION_FAILED](../module-ERROR_CODE.html#operation_failed)
|
|
424
|
+
- [OPERATION_ABORT](../module-ERROR_CODE.html#operation_abort)
|
|
425
|
+
- [SERVER_ERROR](../module-ERROR_CODE.html#server_error)
|
|
426
|
+
|
|
427
|
+
### updateLocalVideo(config)
|
|
428
|
+
|
|
429
|
+
Update the local camera configuration.
|
|
430
|
+
|
|
431
|
+
- This interface needs to be called after [startLocalVideo()](#startlocalvideo) is successful.
|
|
432
|
+
- This interface can be called multiple times.
|
|
433
|
+
- This method uses incremental update: only updates the passed-in parameters, and keeps the parameters that are not passed in unchanged.
|
|
434
|
+
|
|
435
|
+
#### Examples
|
|
436
|
+
|
|
437
|
+
```javascript
|
|
438
|
+
// Switch camera
|
|
439
|
+
const cameraList = await TRTC.getCameraList();
|
|
440
|
+
if (cameraList[1]) {
|
|
441
|
+
await trtc.updateLocalVideo({ option: { cameraId: cameraList[1].deviceId }});
|
|
442
|
+
}
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
```javascript
|
|
446
|
+
// Stop publishing video, but keep local preview
|
|
447
|
+
await trtc.updateLocalVideo({ publish:false });
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
#### Parameters:
|
|
451
|
+
|
|
452
|
+
| Name | Type | Description |
|
|
453
|
+
|------|------|-------------|
|
|
454
|
+
| `config` | object | Configuration item |
|
|
455
|
+
|
|
456
|
+
**Properties:**
|
|
457
|
+
|
|
458
|
+
| Name | Type | Description |
|
|
459
|
+
|------|------|-------------|
|
|
460
|
+
| `view` | string \| HTMLElement \| Array.\<HTMLElement> \| null | The HTMLElement instance or Id of the preview camera. If not passed in or passed in null, the video will not be rendered, but still pushes the stream and consumes bandwidth. |
|
|
461
|
+
| `publish` | boolean | Whether to publish the local video to the room. You can get the publish state by listening this event [PUBLISH_STATE_CHANGED](../module-EVENT.html#publish_state_changed). |
|
|
462
|
+
| `mute` | boolean \| string | Whether to mute the camera. Supports passing in image url string, the image will be published instead of origin camera stream, Other users in the room will receive the REMOTE_VIDEO_AVAILABLE event. It does not support calling when the camera is turned off. More information: [Turn On/Off Camera/Mic](../tutorial-15-basic-dynamic-add-video.html). |
|
|
463
|
+
| `option` | object | Local video configuration |
|
|
464
|
+
|
|
465
|
+
**Properties:**
|
|
466
|
+
|
|
467
|
+
| Name | Type | Description |
|
|
468
|
+
|------|------|-------------|
|
|
469
|
+
| `cameraId` | string | Specify which camera to use |
|
|
470
|
+
| `useFrontCamera` | boolean | Whether to use the front camera |
|
|
471
|
+
| `videoTrack` | MediaStreamTrack | Custom videoTrack. [Custom Capturing and Rendering](../tutorial-20-advanced-customized-capture-rendering.html). |
|
|
472
|
+
| `mirror` | 'view' \| 'publish' \| 'both' \| boolean | Video mirroring mode, default is 'view'.<br>- 'view': You see yourself as a mirror image, and the other person sees you as a non-mirror image.<br>- 'publish': The other person sees you as a mirror image, and you see yourself as a non-mirror image.<br>- 'both': You see yourself as a mirror image, and the other person sees you as a mirror image.<br>- false: Boolean value, represents no mirroring. |
|
|
473
|
+
| `fillMode` | 'contain' \| 'cover' \| 'fill' | Video fill mode. Refer to the [ CSS object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) property |
|
|
474
|
+
| `profile` | string \| [VideoProfile](../global.html#videoprofile) | Video encoding parameters for the main stream |
|
|
475
|
+
| `small` | string \| boolean \| [VideoProfile](../global.html#videoprofile) | Video encoding parameters for the small video. Refer to [Multi-Person Video Calls](../tutorial-27-advanced-small-stream.html) |
|
|
476
|
+
| `qosPreference` | QOS_PREFERENCE_SMOOTH \| QOS_PREFERENCE_CLEAR | Set the video encoding strategy for weak networks. Smooth first ([QOS_PREFERENCE_SMOOTH](../module-TYPE.html#qos_preference_smooth)) or Clear first ([QOS_PREFERENCE_CLEAR](../module-TYPE.html#qos_preference_clear)) |
|
|
477
|
+
| `rotation` | 0 \| 90 \| 180 \| 270 | Set the clockwise rotation angle of the local camera. Since `v5.11.0`. |
|
|
478
|
+
|
|
479
|
+
#### Throws:
|
|
480
|
+
- [INVALID_PARAMETER](../module-ERROR_CODE.html#invalid_parameter)
|
|
481
|
+
- [DEVICE_ERROR](../module-ERROR_CODE.html#device_error)
|
|
482
|
+
- [OPERATION_FAILED](../module-ERROR_CODE.html#operation_failed)
|
|
483
|
+
- [OPERATION_ABORT](../module-ERROR_CODE.html#operation_abort)
|
|
484
|
+
|
|
485
|
+
### stopLocalVideo()
|
|
486
|
+
|
|
487
|
+
Stop capturing, previewing, and publishing the local camera.
|
|
488
|
+
|
|
489
|
+
- If you only want to stop publishing video but keep the local camera preview, you can use the [updateLocalVideo({ publish:false })](#updatelocalvideo) method.
|
|
490
|
+
|
|
491
|
+
#### Example
|
|
492
|
+
|
|
493
|
+
```javascript
|
|
494
|
+
await trtc.stopLocalVideo();
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
#### Throws:
|
|
498
|
+
[OPERATION_ABORT](../module-ERROR_CODE.html#operation_abort)
|
|
499
|
+
|
|
500
|
+
### startScreenShare(config)
|
|
501
|
+
|
|
502
|
+
Start screen sharing.
|
|
503
|
+
|
|
504
|
+
- After starting screen sharing, other users in the room will receive the [REMOTE_VIDEO_AVAILABLE](../module-EVENT.html#remote_video_available) event, with streamType as [STREAM_TYPE_SUB](../module-TYPE.html#stream_type_sub), and other users can play screen sharing through [startRemoteVideo](#startremotevideo).
|
|
505
|
+
|
|
506
|
+
#### Example
|
|
507
|
+
|
|
508
|
+
```javascript
|
|
509
|
+
// Start screen sharing
|
|
510
|
+
await trtc.startScreenShare();
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
#### Parameters:
|
|
514
|
+
|
|
515
|
+
| Name | Type | Default | Description |
|
|
516
|
+
|------|------|---------|-------------|
|
|
517
|
+
| `config` | object | | Configuration item |
|
|
518
|
+
|
|
519
|
+
**Properties:**
|
|
520
|
+
|
|
521
|
+
| Name | Type | Default | Description |
|
|
522
|
+
|------|------|---------|-------------|
|
|
523
|
+
| `view` | string \| HTMLElement \| Array.\<HTMLElement> \| null | | The HTMLElement instance or Id for previewing local screen sharing. If not passed or passed as null, local screen sharing will not be rendered. |
|
|
524
|
+
| `publish` | boolean | | Whether to publish screen sharing to the room. The default is true. If you call this interface before entering the room and publish = true, the SDK will automatically publish after entering the room. You can get the publish state by listening this event [PUBLISH_STATE_CHANGED](../module-EVENT.html#publish_state_changed). |
|
|
525
|
+
| `streamType` | TRTC.TYPE.STREAM_TYPE_MAIN \| TRTC.TYPE.STREAM_TYPE_SUB | | **required** Stream type. A trtc instance can publish one main stream (video+audio) and one auxiliary stream (video). Screen sharing is publish through the sub stream by default.<br>- [TRTC.TYPE.STREAM_TYPE_MAIN](../module-TYPE.html#stream_type_main): Main stream. If set to publish screen sharing as the main stream, the camera cannot be published through the main stream.<br>- [TRTC.TYPE.STREAM_TYPE_SUB](../module-TYPE.html#stream_type_sub): Sub stream (default value). |
|
|
526
|
+
| `muteSystemAudio` | boolean | `false` | Whether to mute system audio. Supported since v5.12.0+. |
|
|
527
|
+
| `option` | object | | Screen sharing configuration |
|
|
528
|
+
|
|
529
|
+
**Properties:**
|
|
530
|
+
|
|
531
|
+
| Name | Type | Default | Description |
|
|
532
|
+
|------|------|---------|-------------|
|
|
533
|
+
| `systemAudio` | boolean | | Whether to capture system audio. The default is false. |
|
|
534
|
+
| `fillMode` | 'contain' \| 'cover' \| 'fill' | | Video fill mode. The default is `contain`, refer to [CSS object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) property. |
|
|
535
|
+
| `profile` | [ScreenShareProfile](../global.html#screenshareprofile) | | Screen sharing encoding configuration. Default value is `1080p`. |
|
|
536
|
+
| `qosPreference` | QOS_PREFERENCE_SMOOTH \| QOS_PREFERENCE_CLEAR | | Set the video encoding strategy for weak networks. Smooth first ([QOS_PREFERENCE_SMOOTH](../module-TYPE.html#qos_preference_smooth)) or Clear first(default) ([QOS_PREFERENCE_CLEAR](../module-TYPE.html#qos_preference_clear)) |
|
|
537
|
+
| `captureElement` | HTMLElement | | Capture screen from the specified element of current tab. Available on Chrome 104+. |
|
|
538
|
+
| `preferDisplaySurface` | 'current-tab' \| 'tab' \| 'window' \| 'monitor' | `'monitor'` | The prefer display surface for screen sharing. Available on Chrome 94+.<br>- The default is monitor, which means that monitor capture will be displayed first in the Screen Sharing Capture pre-checkbox。<br>- If you fill in 'current-tab', the pre-checkbox will only show the current page. |
|
|
539
|
+
|
|
540
|
+
#### Throws:
|
|
541
|
+
- [ENV_NOT_SUPPORTED](../module-ERROR_CODE.html#env_not_supported)
|
|
542
|
+
- [INVALID_PARAMETER](../module-ERROR_CODE.html#invalid_parameter)
|
|
543
|
+
- [DEVICE_ERROR](../module-ERROR_CODE.html#device_error)
|
|
544
|
+
- [OPERATION_FAILED](../module-ERROR_CODE.html#operation_failed)
|
|
545
|
+
- [OPERATION_ABORT](../module-ERROR_CODE.html#operation_abort)
|
|
546
|
+
- [SERVER_ERROR](../module-ERROR_CODE.html#server_error)
|
|
547
|
+
|
|
548
|
+
### updateScreenShare(config)
|
|
549
|
+
|
|
550
|
+
Update screen sharing configuration
|
|
551
|
+
|
|
552
|
+
- This interface needs to be called after [startScreenShare()](#startscreenshare) is successful.
|
|
553
|
+
- This interface can be called multiple times.
|
|
554
|
+
- This method uses incremental update: only update the passed-in parameters, and keep the parameters that are not passed-in unchanged.
|
|
555
|
+
|
|
556
|
+
#### Example
|
|
557
|
+
|
|
558
|
+
```javascript
|
|
559
|
+
// Stop screen sharing, but keep the local preview of screen sharing
|
|
560
|
+
await trtc.updateScreenShare({ publish:false });
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
#### Parameters:
|
|
564
|
+
|
|
565
|
+
| Name | Type | Default | Description |
|
|
566
|
+
|------|------|---------|-------------|
|
|
567
|
+
| `config` | object | | Configuration item |
|
|
568
|
+
|
|
569
|
+
**Properties:**
|
|
570
|
+
|
|
571
|
+
| Name | Type | Default | Description |
|
|
572
|
+
|------|------|---------|-------------|
|
|
573
|
+
| `view` | string \| HTMLElement \| Array.\<HTMLElement> \| null | | The HTMLElement instance or Id for screen sharing preview. If not passed in or passed in null, the screen sharing will not be rendered. |
|
|
574
|
+
| `publish` | boolean | `true` | Whether to publish screen sharing to the room |
|
|
575
|
+
| `muteSystemAudio` | boolean | `false` | Whether to mute system audio. Supported since v5.12.0+. |
|
|
576
|
+
| `option` | object | | Screen sharing configuration |
|
|
577
|
+
|
|
578
|
+
**Properties:**
|
|
579
|
+
|
|
580
|
+
| Name | Type | Description |
|
|
581
|
+
|------|------|-------------|
|
|
582
|
+
| `fillMode` | 'contain' \| 'cover' \| 'fill' | Video fill mode. The default is `contain`, refer to [CSS object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) property. |
|
|
583
|
+
| `qosPreference` | QOS_PREFERENCE_SMOOTH \| QOS_PREFERENCE_CLEAR | Set the video encoding strategy for weak networks. Smooth first ([QOS_PREFERENCE_SMOOTH](../module-TYPE.html#qos_preference_smooth)) or Clear first ([QOS_PREFERENCE_CLEAR](../module-TYPE.html#qos_preference_clear)) |
|
|
584
|
+
|
|
585
|
+
#### Throws:
|
|
586
|
+
- [INVALID_PARAMETER](../module-ERROR_CODE.html#invalid_parameter)
|
|
587
|
+
- [DEVICE_ERROR](../module-ERROR_CODE.html#device_error)
|
|
588
|
+
- [OPERATION_FAILED](../module-ERROR_CODE.html#operation_failed)
|
|
589
|
+
- [OPERATION_ABORT](../module-ERROR_CODE.html#operation_abort)
|
|
590
|
+
- [SERVER_ERROR](../module-ERROR_CODE.html#server_error)
|
|
591
|
+
|
|
592
|
+
### stopScreenShare()
|
|
593
|
+
|
|
594
|
+
Stop screen sharing.
|
|
595
|
+
|
|
596
|
+
#### Example
|
|
597
|
+
|
|
598
|
+
```javascript
|
|
599
|
+
await trtc.stopScreenShare();
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
#### Throws:
|
|
603
|
+
[OPERATION_ABORT](../module-ERROR_CODE.html#operation_abort)
|
|
604
|
+
|
|
605
|
+
### startRemoteVideo
|
|
606
|
+
|
|
607
|
+
**(async)** startRemoteVideo(config)
|
|
608
|
+
|
|
609
|
+
Play remote video
|
|
610
|
+
|
|
611
|
+
- When to call: Call after receiving the [TRTC.on(TRTC.EVENT.REMOTE_VIDEO_AVAILABLE)](module-EVENT.html#.REMOTE_VIDEO_AVAILABLE) event.
|
|
612
|
+
|
|
613
|
+
#### Example
|
|
614
|
+
|
|
615
|
+
```javascript
|
|
616
|
+
trtc.on(TRTC.EVENT.REMOTE_VIDEO_AVAILABLE, ({ userId, streamType }) => {
|
|
617
|
+
// You need to place the video container in the DOM in advance, and it is recommended to use `${userId}_${streamType}` as the element id.
|
|
618
|
+
trtc.startRemoteVideo({ userId, streamType, view: `${userId}_${streamType}` });
|
|
619
|
+
})
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
#### Parameters
|
|
623
|
+
|
|
624
|
+
| Name | Type | Description |
|
|
625
|
+
|------|------|-------------|
|
|
626
|
+
| config | object | Remote video configuration |
|
|
627
|
+
|
|
628
|
+
**Properties**
|
|
629
|
+
|
|
630
|
+
| Name | Type | Description |
|
|
631
|
+
|------|------|-------------|
|
|
632
|
+
| view | string \| HTMLElement \| Array.\<HTMLElement> \| null | The HTMLElement instance or Id used to play remote video. If not passed or passed null, the video will not be rendered, but the bandwidth will still be consumed. |
|
|
633
|
+
| userId | string | **required** Remote user ID |
|
|
634
|
+
| streamType | TRTC.TYPE.STREAM_TYPE_MAIN \| TRTC.TYPE.STREAM_TYPE_SUB | **required** Remote stream type<br>- [TRTC.TYPE.STREAM_TYPE_MAIN](module-TYPE.html#.STREAM_TYPE_MAIN): Main stream (remote user's camera)<br>- [TRTC.TYPE.STREAM_TYPE_SUB](module-TYPE.html#.STREAM_TYPE_SUB): Sub stream (remote user's screen sharing) |
|
|
635
|
+
| option | object | Remote video configuration |
|
|
636
|
+
|
|
637
|
+
**Option Properties**
|
|
638
|
+
|
|
639
|
+
| Name | Type | Default | Description |
|
|
640
|
+
|------|------|---------|-------------|
|
|
641
|
+
| small | boolean | | Whether to subscribe small streams |
|
|
642
|
+
| mirror | boolean | | Whether to enable mirror |
|
|
643
|
+
| fillMode | 'contain' \| 'cover' \| 'fill' | | Video fill mode. Refer to the [CSS object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) property. |
|
|
644
|
+
| receiveWhenViewVisible | boolean | | Since v5.4.0<br>Subscribe video only when view is visible. Refer to: [Multi-Person Video Calls](tutorial-27-advanced-small-stream.html). |
|
|
645
|
+
| viewRoot | HTMLElement | document.body | Since v5.4.0<br>The root element is the parent element of the view and is used to calculate whether the view is visible relative to the root. The default value is document.body, and it is recommended that you use the first-level parent of the video view list. Refer to: [Multi-Person Video Calls](tutorial-27-advanced-small-stream.html). |
|
|
646
|
+
| poster | string | | Since v5.10.0<br>The default poster image for the video. Generally no need to concern about this, only a few browsers display their default built-in images, in which case you can customize it through this parameter. Reference: [HTMLVideoElement: poster property](https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement/poster) |
|
|
647
|
+
|
|
648
|
+
#### Throws
|
|
649
|
+
|
|
650
|
+
- [INVALID_PARAMETER](module-ERROR_CODE.html#.INVALID_PARAMETER)
|
|
651
|
+
- [INVALID_OPERATION](module-ERROR_CODE.html#.INVALID_OPERATION)
|
|
652
|
+
- [OPERATION_FAILED](module-ERROR_CODE.html#.OPERATION_FAILED)
|
|
653
|
+
- [OPERATION_ABORT](module-ERROR_CODE.html#.OPERATION_ABORT)
|
|
654
|
+
- [SERVER_ERROR](module-ERROR_CODE.html#.SERVER_ERROR)
|
|
655
|
+
|
|
656
|
+
### updateRemoteVideo
|
|
657
|
+
|
|
658
|
+
**(async)** updateRemoteVideo(config)
|
|
659
|
+
|
|
660
|
+
Update remote video playback configuration
|
|
661
|
+
|
|
662
|
+
- This method should be called after [startRemoteVideo](TRTC.html#startRemoteVideo) is successful.
|
|
663
|
+
- This method can be called multiple times.
|
|
664
|
+
- This method uses incremental updates, so only the configuration items that need to be updated need to be passed in.
|
|
665
|
+
|
|
666
|
+
#### Example
|
|
667
|
+
|
|
668
|
+
```javascript
|
|
669
|
+
const config = {
|
|
670
|
+
view: document.getElementById(userId), // you can use a new view to update the position of video.
|
|
671
|
+
userId,
|
|
672
|
+
streamType: TRTC.TYPE.STREAM_TYPE_MAIN
|
|
673
|
+
}
|
|
674
|
+
await trtc.updateRemoteVideo(config);
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
#### Parameters
|
|
678
|
+
|
|
679
|
+
| Name | Type | Description |
|
|
680
|
+
|------|------|-------------|
|
|
681
|
+
| config | object | Remote video configuration |
|
|
682
|
+
|
|
683
|
+
**Properties**
|
|
684
|
+
|
|
685
|
+
| Name | Type | Description |
|
|
686
|
+
|------|------|-------------|
|
|
687
|
+
| view | string \| HTMLElement \| Array.\<HTMLElement> \| null | The HTMLElement instance or Id used to play remote video. If not passed or passed null, the video will not be rendered, but the bandwidth will still be consumed. |
|
|
688
|
+
| userId | string | **required** Remote user ID |
|
|
689
|
+
| streamType | TRTC.TYPE.STREAM_TYPE_MAIN \| TRTC.TYPE.STREAM_TYPE_SUB | **required** Remote stream type<br>- [TRTC.TYPE.STREAM_TYPE_MAIN](module-TYPE.html#.STREAM_TYPE_MAIN): Main stream (remote user's camera)<br>- [TRTC.TYPE.STREAM_TYPE_SUB](module-TYPE.html#.STREAM_TYPE_SUB): Sub stream (remote user's screen sharing) |
|
|
690
|
+
| option | object | Remote video configuration |
|
|
691
|
+
|
|
692
|
+
**Option Properties**
|
|
693
|
+
|
|
694
|
+
| Name | Type | Default | Description |
|
|
695
|
+
|------|------|---------|-------------|
|
|
696
|
+
| small | boolean | | Whether to subscribe small streams. Refer to: [Multi-Person Video Calls](tutorial-27-advanced-small-stream.html). |
|
|
697
|
+
| mirror | boolean | | Whether to enable mirror |
|
|
698
|
+
| fillMode | 'contain' \| 'cover' \| 'fill' | | Video fill mode. Refer to the [CSS object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) property. |
|
|
699
|
+
| receiveWhenViewVisible | boolean | | Since v5.4.0<br>Subscribe video only when view is visible. Refer to: [Multi-Person Video Calls](tutorial-27-advanced-small-stream.html). |
|
|
700
|
+
| viewRoot | HTMLElement | document.body | Since v5.4.0<br>The root element is the parent element of the view and is used to calculate whether the view is visible relative to the root. The default value is document.body, and it is recommended that you use the first-level parent of the video view list. Refer to: [Multi-Person Video Calls](tutorial-27-advanced-small-stream.html). |
|
|
701
|
+
|
|
702
|
+
#### Throws
|
|
703
|
+
|
|
704
|
+
- [INVALID_PARAMETER](module-ERROR_CODE.html#.INVALID_PARAMETER)
|
|
705
|
+
- [INVALID_OPERATION](module-ERROR_CODE.html#.INVALID_OPERATION)
|
|
706
|
+
- [OPERATION_FAILED](module-ERROR_CODE.html#.OPERATION_FAILED)
|
|
707
|
+
- [OPERATION_ABORT](module-ERROR_CODE.html#.OPERATION_ABORT)
|
|
708
|
+
|
|
709
|
+
### stopRemoteVideo
|
|
710
|
+
|
|
711
|
+
**(async)** stopRemoteVideo(config)
|
|
712
|
+
|
|
713
|
+
Used to stop remote video playback.
|
|
714
|
+
|
|
715
|
+
#### Example
|
|
716
|
+
|
|
717
|
+
```javascript
|
|
718
|
+
// Stop playing all remote users
|
|
719
|
+
await trtc.stopRemoteVideo({ userId: '*' });
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
#### Parameters
|
|
723
|
+
|
|
724
|
+
| Name | Type | Description |
|
|
725
|
+
|------|------|-------------|
|
|
726
|
+
| config | object | **required** Remote video configuration |
|
|
727
|
+
|
|
728
|
+
**Properties**
|
|
729
|
+
|
|
730
|
+
| Name | Type | Description |
|
|
731
|
+
|------|------|-------------|
|
|
732
|
+
| userId | string | **required** Remote user ID, '*' represents all users. |
|
|
733
|
+
| streamType | TRTC.TYPE.STREAM_TYPE_MAIN \| TRTC.TYPE.STREAM_TYPE_SUB | Remote stream type. This field is required when userId is not '*'.<br>- [TRTC.TYPE.STREAM_TYPE_MAIN](module-TYPE.html#.STREAM_TYPE_MAIN): Main stream (remote user's camera)<br>- [TRTC.TYPE.STREAM_TYPE_SUB](module-TYPE.html#.STREAM_TYPE_SUB): Sub stream (remote user's screen sharing) |
|
|
734
|
+
|
|
735
|
+
#### Throws
|
|
736
|
+
|
|
737
|
+
[OPERATION_ABORT](module-ERROR_CODE.html#.OPERATION_ABORT)
|
|
738
|
+
|
|
739
|
+
### muteRemoteAudio
|
|
740
|
+
|
|
741
|
+
**(async)** muteRemoteAudio(userId, mute)
|
|
742
|
+
|
|
743
|
+
Mute a remote user and stop subscribing audio data from that user. Only effective for the current user, other users in the room can still hear the muted user's voice.
|
|
744
|
+
|
|
745
|
+
Note:
|
|
746
|
+
|
|
747
|
+
- By default, after entering the room, the SDK will automatically play remote audio. You can call this interface to mute or unmute remote users.
|
|
748
|
+
- If the parameter autoReceiveAudio = false is passed in when entering the room, remote audio will not be played automatically. When audio playback is required, you need to call this method (mute is passed in false) to play remote audio.
|
|
749
|
+
- This interface is effective before or after entering the room (enterRoom), and the mute state will be reset to false after exiting the room (exitRoom).
|
|
750
|
+
- If you want to continue subscribing audio data from the user but not play it, you can call setRemoteAudioVolume(userId, 0)
|
|
751
|
+
|
|
752
|
+
#### Example
|
|
753
|
+
|
|
754
|
+
```javascript
|
|
755
|
+
// Mute all remote users
|
|
756
|
+
await trtc.muteRemoteAudio('*', true);
|
|
757
|
+
```
|
|
758
|
+
|
|
759
|
+
#### Parameters
|
|
760
|
+
|
|
761
|
+
| Name | Type | Description |
|
|
762
|
+
|------|------|-------------|
|
|
763
|
+
| userId | string | **required** Remote user ID, '*' represents all users. |
|
|
764
|
+
| mute | boolean | **required** Whether to mute |
|
|
765
|
+
|
|
766
|
+
#### Throws
|
|
767
|
+
|
|
768
|
+
- [INVALID_PARAMETER](module-ERROR_CODE.html#.INVALID_PARAMETER)
|
|
769
|
+
- [INVALID_OPERATION](module-ERROR_CODE.html#.INVALID_OPERATION)
|
|
770
|
+
- [OPERATION_FAILED](module-ERROR_CODE.html#.OPERATION_FAILED)
|
|
771
|
+
- [OPERATION_ABORT](module-ERROR_CODE.html#.OPERATION_ABORT)
|
|
772
|
+
|
|
773
|
+
### setRemoteAudioVolume
|
|
774
|
+
|
|
775
|
+
setRemoteAudioVolume(userId, volume)
|
|
776
|
+
|
|
777
|
+
Used to control the playback volume of remote audio.
|
|
778
|
+
|
|
779
|
+
- Starting from version v5.12.1, this setting only needs to be configured once, and there is no need to reset it when remote users rejoin the room. For versions prior to v5.12.1, if a remote user rejoins the room, the volume setting needs to be reconfigured.
|
|
780
|
+
- Not supported by iOS Safari
|
|
781
|
+
|
|
782
|
+
#### Example
|
|
783
|
+
|
|
784
|
+
```javascript
|
|
785
|
+
await trtc.setRemoteAudioVolume('123', 90);
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
#### Parameters
|
|
789
|
+
|
|
790
|
+
| Name | Type | Description |
|
|
791
|
+
|------|------|-------------|
|
|
792
|
+
| userId | string | **required** Remote user ID. '*' represents all remote users. |
|
|
793
|
+
| volume | number | **required** Volume, ranging from 0 to 100. The default value is 100.<br>Since `v5.1.3+`, the volume can be set higher than 100. |
|
|
794
|
+
|
|
795
|
+
### startPlugin
|
|
796
|
+
|
|
797
|
+
**(async)** startPlugin(plugin, options) → {Promise.\<void>}
|
|
798
|
+
|
|
799
|
+
start plugin
|
|
800
|
+
|
|
801
|
+
| pluginName | name | tutorial | param |
|
|
802
|
+
|------------|------|----------|-------|
|
|
803
|
+
| 'AudioMixer' | Audio Mixer Plugin | [Music and Audio Effects](tutorial-22-advanced-audio-mixer.html) | [AudioMixerOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/en/global.html#AudioMixerOptions) |
|
|
804
|
+
| 'AIDenoiser' | AI Denoiser Plugin | [Implement AI noise reduction](tutorial-35-advanced-ai-denoiser.html) | [AIDenoiserOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/en/global.html#AIDenoiserOptions) |
|
|
805
|
+
| 'VirtualBackground' | Virtual Background Plugin | [Enable Virtual Background](tutorial-36-advanced-virtual-background.html) | [VirtualBackgroundOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/en/global.html#VirtualBackgroundOptions) |
|
|
806
|
+
| 'Watermark' | Watermark Plugin | [Enable Watermark Plugin](tutorial-29-advanced-water-mark.html) | [WatermarkOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/en/global.html#WatermarkOptions) |
|
|
807
|
+
| 'SmallStreamAutoSwitcher' | Small Stream Auto Switcher Plugin | [Enable Small Stream Auto Switcher Plugin](tutorial-41-advanced-small-stream-auto-switcher.html) | [SmallStreamAutoSwitcherOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/en/global.html#SmallStreamAutoSwitcherOptions) |
|
|
808
|
+
| 'VoiceChanger' | Voice Changer Plugin | [Enable Voice Changer](tutorial-37-advanced-voice-changer.html) | [VoiceChangerStartOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/zh-cn/global.html#VoiceChangerStartOptions) |
|
|
809
|
+
|
|
810
|
+
#### Parameters
|
|
811
|
+
|
|
812
|
+
| Name | Type | Description |
|
|
813
|
+
|------|------|-------------|
|
|
814
|
+
| plugin | [PluginName](global.html#PluginName) | **required** |
|
|
815
|
+
| options | AudioMixerOptions \| [AIDenoiserOptions](global.html#AIDenoiserOptions) \| [VirtualBackgroundOptions](global.html#VirtualBackgroundOptions) \| [WatermarkOptions](global.html#WatermarkOptions) \| [SmallStreamAutoSwitcherOptions](global.html#SmallStreamAutoSwitcherOptions) \| [VoiceChangerStartOptions](global.html#VoiceChangerStartOptions) | **required** |
|
|
816
|
+
|
|
817
|
+
#### Returns
|
|
818
|
+
|
|
819
|
+
**Type:** Promise.\<void>
|
|
820
|
+
|
|
821
|
+
### updatePlugin
|
|
822
|
+
|
|
823
|
+
**(async)** updatePlugin(plugin, options) → {Promise.\<void>}
|
|
824
|
+
|
|
825
|
+
Update plugin
|
|
826
|
+
|
|
827
|
+
| pluginName | name | tutorial | param |
|
|
828
|
+
|------------|------|----------|-------|
|
|
829
|
+
| 'AudioMixer' | Audio Mixer Plugin | [Music and Audio Effects](tutorial-22-advanced-audio-mixer.html) | [UpdateAudioMixerOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/en/global.html#UpdateAudioMixerOptions) |
|
|
830
|
+
| 'AIDenoiser' | AI Denoiser Plugin | [Implement AI noise reduction](tutorial-35-advanced-ai-denoiser.html) | [AIDenoiserOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/zh-cn/global.html#AIDenoiserOptions) |
|
|
831
|
+
| 'VirtualBackground' | Virtual Background Plugin | [Enable Virtual Background](tutorial-36-advanced-virtual-background.html) | [VirtualBackgroundOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/en/global.html#VirtualBackgroundOptions) |
|
|
832
|
+
| 'Watermark' | Watermark Plugin | [Enable Watermark Plugin](tutorial-29-advanced-water-mark.html) | [WatermarkOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/zh-cn/global.html#WatermarkOptions) |
|
|
833
|
+
| 'SmallStreamAutoSwitcher' | Small Stream Auto Switcher | [Enable Small Stream Auto Switcher Plugin](tutorial-41-advanced-small-stream-auto-switcher.html) | [SmallStreamAutoSwitcherOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/zh-cn/global.html#SmallStreamAutoSwitcherOptions) |
|
|
834
|
+
| 'VoiceChanger' | Voice Changer Plugin | [Enable Voice Changer](tutorial-37-advanced-voice-changer.html) | [VoiceChangerUpdateOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/zh-cn/global.html#VoiceChangerUpdateOptions) |
|
|
835
|
+
|
|
836
|
+
#### Parameters
|
|
837
|
+
|
|
838
|
+
| Name | Type | Description |
|
|
839
|
+
|------|------|-------------|
|
|
840
|
+
| plugin | [PluginName](global.html#PluginName) | **required** |
|
|
841
|
+
| options | [UpdateAudioMixerOptions](global.html#UpdateAudioMixerOptions) \| [AIDenoiserOptions](global.html#AIDenoiserOptions) \| [VirtualBackgroundOptions](global.html#VirtualBackgroundOptions) \| [WatermarkOptions](global.html#WatermarkOptions) \| [SmallStreamAutoSwitcherOptions](global.html#SmallStreamAutoSwitcherOptions) \| [VoiceChangerUpdateOptions](global.html#VoiceChangerUpdateOptions) | **required** |
|
|
842
|
+
|
|
843
|
+
#### Returns
|
|
844
|
+
|
|
845
|
+
**Type:** Promise.\<void>
|
|
846
|
+
|
|
847
|
+
### stopPlugin
|
|
848
|
+
|
|
849
|
+
**(async)** stopPlugin(plugin, options) → {Promise.\<void>}
|
|
850
|
+
|
|
851
|
+
Stop plugin
|
|
852
|
+
|
|
853
|
+
| pluginName | name | tutorial | param |
|
|
854
|
+
|------------|------|----------|-------|
|
|
855
|
+
| 'AudioMixer' | AudioMixer Plugin | [Music and Audio Effects](tutorial-22-advanced-audio-mixer.html) | [StopAudioMixerOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/en/global.html#StopAudioMixerOptions) |
|
|
856
|
+
| 'AIDenoiser' | AIdenoiser Plugin | [Implement AI noise reduction](tutorial-35-advanced-ai-denoiser.html) | |
|
|
857
|
+
| 'VirtualBackground' | Virtual Background Plugin | [Enable Virtual Background](tutorial-36-advanced-virtual-background.html) | |
|
|
858
|
+
| 'Watermark' | Watermark Plugin | [Enable Watermark Plugin](tutorial-29-advanced-water-mark.html) | |
|
|
859
|
+
| 'SmallStreamAutoSwitcher' | Small Stream Auto Switcher Plugin | [Enable Small Stream Auto Switcher Plugin](tutorial-41-advanced-small-stream-auto-switcher.html) | |
|
|
860
|
+
| 'VoiceChanger' | Voice Changer Plugin | [Enable Voice Changer](tutorial-37-advanced-voice-changer.html) | |
|
|
861
|
+
|
|
862
|
+
#### Parameters
|
|
863
|
+
|
|
864
|
+
| Name | Type | Description |
|
|
865
|
+
|------|------|-------------|
|
|
866
|
+
| plugin | [PluginName](global.html#PluginName) | **required** |
|
|
867
|
+
| options | [StopAudioMixerOptions](global.html#StopAudioMixerOptions) | **required** |
|
|
868
|
+
|
|
869
|
+
#### Returns
|
|
870
|
+
|
|
871
|
+
**Type:** Promise.\<void>
|
|
872
|
+
|
|
873
|
+
### enableAudioVolumeEvaluation
|
|
874
|
+
|
|
875
|
+
enableAudioVolumeEvaluation(interval, enableInBackground)
|
|
876
|
+
|
|
877
|
+
Enables or disables the volume callback.
|
|
878
|
+
|
|
879
|
+
- After enabling this function, whether someone is speaking in the room or not, the SDK will regularly throw the [TRTC.on(TRTC.EVENT.AUDIO_VOLUME)](module-EVENT.html#.AUDIO_VOLUME) event, which feedbacks the volume evaluation value of each user.
|
|
880
|
+
|
|
881
|
+
#### Example
|
|
882
|
+
|
|
883
|
+
```javascript
|
|
884
|
+
trtc.on(TRTC.EVENT.AUDIO_VOLUME, event => {
|
|
885
|
+
event.result.forEach(({ userId, volume }) => {
|
|
886
|
+
const isMe = userId === ''; // When userId is an empty string, it represents the local microphone volume.
|
|
887
|
+
if (isMe) {
|
|
888
|
+
console.log(`my volume: ${volume}`);
|
|
889
|
+
} else {
|
|
890
|
+
console.log(`user: ${userId} volume: ${volume}`);
|
|
891
|
+
}
|
|
892
|
+
})
|
|
893
|
+
});
|
|
894
|
+
// Enable volume callback and trigger the event every 1000ms
|
|
895
|
+
trtc.enableAudioVolumeEvaluation(1000);
|
|
896
|
+
// To turn off the volume callback, pass in an interval value less than or equal to 0
|
|
897
|
+
trtc.enableAudioVolumeEvaluation(-1);
|
|
898
|
+
```
|
|
899
|
+
|
|
900
|
+
#### Parameters
|
|
901
|
+
|
|
902
|
+
| Name | Type | Default | Description |
|
|
903
|
+
|------|------|---------|-------------|
|
|
904
|
+
| interval | number | 2000 | Used to set the time interval for triggering the volume callback event. The default is 2000(ms), and the minimum value is 100(ms). If set to less than or equal to 0, the volume callback will be turned off. |
|
|
905
|
+
| enableInBackground | boolean | false | For performance reasons, when the page switches to the background, the SDK will not throw volume callback events. If you need to receive volume callback events when the page is switched to the background, you can set this parameter to true. |
|
|
906
|
+
|
|
907
|
+
### on
|
|
908
|
+
|
|
909
|
+
on(eventName, handler, context)
|
|
910
|
+
|
|
911
|
+
Listen to TRTC events
|
|
912
|
+
|
|
913
|
+
For a detailed list of events, please refer to: [TRTC.EVENT](module-EVENT.html)
|
|
914
|
+
|
|
915
|
+
#### Example
|
|
916
|
+
|
|
917
|
+
```javascript
|
|
918
|
+
trtc.on(TRTC.EVENT.REMOTE_VIDEO_AVAILABLE, event => {
|
|
919
|
+
// REMOTE_VIDEO_AVAILABLE event handler
|
|
920
|
+
});
|
|
921
|
+
```
|
|
922
|
+
|
|
923
|
+
#### Parameters
|
|
924
|
+
|
|
925
|
+
| Name | Type | Description |
|
|
926
|
+
|------|------|-------------|
|
|
927
|
+
| eventName | string | **required** Event name |
|
|
928
|
+
| handler | function | **required** Event callback function |
|
|
929
|
+
| context | context | **required** Context |
|
|
930
|
+
|
|
931
|
+
### off
|
|
932
|
+
|
|
933
|
+
off(eventName, handler, context)
|
|
934
|
+
|
|
935
|
+
Remove event listener
|
|
936
|
+
|
|
937
|
+
#### Example
|
|
938
|
+
|
|
939
|
+
```javascript
|
|
940
|
+
trtc.on(TRTC.EVENT.REMOTE_USER_ENTER, function peerJoinHandler(event) {
|
|
941
|
+
// REMOTE_USER_ENTER event handler
|
|
942
|
+
console.log('remote user enter');
|
|
943
|
+
trtc.off(TRTC.EVENT.REMOTE_USER_ENTER, peerJoinHandler);
|
|
944
|
+
});
|
|
945
|
+
// Remove all event listeners
|
|
946
|
+
trtc.off('*');
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
#### Parameters
|
|
950
|
+
|
|
951
|
+
| Name | Type | Description |
|
|
952
|
+
|------|------|-------------|
|
|
953
|
+
| eventName | string | **required** Event name. Passing in the wildcard '*' will remove all event listeners. |
|
|
954
|
+
| handler | function | **required** Event callback function |
|
|
955
|
+
| context | context | **required** Context |
|
|
956
|
+
|
|
957
|
+
### getAudioTrack
|
|
958
|
+
|
|
959
|
+
getAudioTrack(config) → {(nullable) MediaStreamTrack}
|
|
960
|
+
|
|
961
|
+
Get audio track
|
|
962
|
+
|
|
963
|
+
#### Example
|
|
964
|
+
|
|
965
|
+
```javascript
|
|
966
|
+
// Version before v5.4.3
|
|
967
|
+
trtc.getAudioTrack(); // Get local microphone audioTrack, captured by trtc.startLocalAudio()
|
|
968
|
+
trtc.getAudioTrack('remoteUserId'); // Get remote audioTrack
|
|
969
|
+
// Since v5.4.3+, you can get local screen audioTrack by passing the streamType = TRTC.STREAM_TYPE_SUB
|
|
970
|
+
trtc.getAudioTrack({ streamType: TRTC.STREAM_TYPE_SUB });
|
|
971
|
+
// Since v5.8.2+, you can get the processed audioTrack by passing processed = true
|
|
972
|
+
trtc.getAudioTrack({ processed: true });
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
#### Parameters
|
|
976
|
+
|
|
977
|
+
| Name | Type | Description |
|
|
978
|
+
|------|------|-------------|
|
|
979
|
+
| config | Object \| string | If not passed, get the local microphone audioTrack |
|
|
980
|
+
|
|
981
|
+
**Properties**
|
|
982
|
+
|
|
983
|
+
| Name | Type | Default | Description |
|
|
984
|
+
|------|------|---------|-------------|
|
|
985
|
+
| userId | string | | If not passed or passed an empty string, get the local audioTrack. Pass the userId of the remote user to get the remote user's audioTrack. |
|
|
986
|
+
| streamType | STREAM_TYPE_MAIN \| STREAM_TYPE_SUB | | stream type:<br>- [TRTC.TYPE.STREAM_TYPE_MAIN](module-TYPE.html#.STREAM_TYPE_MAIN): Main stream (user's microphone)(default)<br>- [TRTC.TYPE.STREAM_TYPE_SUB](module-TYPE.html#.STREAM_TYPE_SUB): Sub stream (user's screen sharing audio). Only works for local screen sharing audio because there is only one remote audioTrack, and there is no distinction between Main and Sub for remote audioTrack. |
|
|
987
|
+
| processed | boolean | false | Whether to get the processed audioTrack. The processed audioTrack is the audioTrack after the SDK processes the audio frame, such as ai-denose, gain, mix. The default value is false. |
|
|
988
|
+
|
|
989
|
+
#### Returns
|
|
990
|
+
|
|
991
|
+
Audio track
|
|
992
|
+
|
|
993
|
+
**Type:** MediaStreamTrack
|
|
994
|
+
|
|
995
|
+
### getVideoTrack
|
|
996
|
+
|
|
997
|
+
getVideoTrack(config) → {MediaStreamTrack|null}
|
|
998
|
+
|
|
999
|
+
Get video track
|
|
1000
|
+
|
|
1001
|
+
#### Example
|
|
1002
|
+
|
|
1003
|
+
```javascript
|
|
1004
|
+
// Get local camera videoTrack
|
|
1005
|
+
const videoTrack = trtc.getVideoTrack();
|
|
1006
|
+
// Get local screen sharing videoTrack
|
|
1007
|
+
const screenVideoTrack = trtc.getVideoTrack({ streamType: TRTC.TYPE.STREAM_TYPE_SUB });
|
|
1008
|
+
// Get remote user's main stream videoTrack
|
|
1009
|
+
const remoteMainVideoTrack = trtc.getVideoTrack({ userId: 'test', streamType: TRTC.TYPE.STREAM_TYPE_MAIN });
|
|
1010
|
+
// Get remote user's sub stream videoTrack
|
|
1011
|
+
const remoteSubVideoTrack = trtc.getVideoTrack({ userId: 'test', streamType: TRTC.TYPE.STREAM_TYPE_SUB });
|
|
1012
|
+
// Since v5.8.2+, you can get the processed videoTrack by passing processed = true
|
|
1013
|
+
const processedVideoTrack = trtc.getVideoTrack({ processed: true });
|
|
1014
|
+
```
|
|
1015
|
+
|
|
1016
|
+
#### Parameters
|
|
1017
|
+
|
|
1018
|
+
| Name | Type | Description |
|
|
1019
|
+
|------|------|-------------|
|
|
1020
|
+
| config | string | If not passed, get the local camera videoTrack |
|
|
1021
|
+
|
|
1022
|
+
**Properties**
|
|
1023
|
+
|
|
1024
|
+
| Name | Type | Default | Description |
|
|
1025
|
+
|------|------|---------|-------------|
|
|
1026
|
+
| userId | string | | If not passed or passed an empty string, get the local videoTrack. Pass the userId of the remote user to get the remote user's videoTrack. |
|
|
1027
|
+
| streamType | STREAM_TYPE_MAIN \| STREAM_TYPE_SUB | | stream type:<br>- [TRTC.TYPE.STREAM_TYPE_MAIN](module-TYPE.html#.STREAM_TYPE_MAIN): Main stream (user's camera)(default)<br>- [TRTC.TYPE.STREAM_TYPE_SUB](module-TYPE.html#.STREAM_TYPE_SUB): Sub stream (user's screen sharing) |
|
|
1028
|
+
| processed | boolean | false | Whether to get the processed videoTrack. The processed videoTrack is the videoTrack after the SDK processes the video frame, such as virtual background, mirror, watermark, rotation. The default value is false. |
|
|
1029
|
+
|
|
1030
|
+
#### Returns
|
|
1031
|
+
|
|
1032
|
+
Video track
|
|
1033
|
+
|
|
1034
|
+
**Type:** MediaStreamTrack | null
|
|
1035
|
+
|
|
1036
|
+
### getVideoSnapshot
|
|
1037
|
+
|
|
1038
|
+
getVideoSnapshot()
|
|
1039
|
+
|
|
1040
|
+
Get video snapshot
|
|
1041
|
+
|
|
1042
|
+
Notice: must play the video before it can obtain the snapshot. If there is no playback, an empty string will be returned.
|
|
1043
|
+
|
|
1044
|
+
**Since:** 5.4.0
|
|
1045
|
+
|
|
1046
|
+
#### Example
|
|
1047
|
+
|
|
1048
|
+
```javascript
|
|
1049
|
+
// get self main stream video frame
|
|
1050
|
+
trtc.getVideoSnapshot()
|
|
1051
|
+
// get self sub stream video frame
|
|
1052
|
+
trtc.getVideoSnapshot({streamType:TRTC.TYPE.STREAM_TYPE_SUB})
|
|
1053
|
+
// get remote user main stream video frame
|
|
1054
|
+
trtc.getVideoSnapshot({userId: 'remote userId', streamType:TRTC.TYPE.STREAM_TYPE_MAIN})
|
|
1055
|
+
```
|
|
1056
|
+
|
|
1057
|
+
#### Parameters
|
|
1058
|
+
|
|
1059
|
+
| Name | Type | Description |
|
|
1060
|
+
|------|------|-------------|
|
|
1061
|
+
| config.userId | string | **required** Remote user ID |
|
|
1062
|
+
| config.streamType | TRTC.TYPE.STREAM_TYPE_MAIN \| TRTC.TYPE.STREAM_TYPE_SUB | **required**<br>- [TRTC.TYPE.STREAM_TYPE_MAIN](module-TYPE.html#.STREAM_TYPE_MAIN): Main stream<br>- [TRTC.TYPE.STREAM_TYPE_SUB](module-TYPE.html#.STREAM_TYPE_SUB): Sub stream |
|
|
1063
|
+
|
|
1064
|
+
### sendSEIMessage
|
|
1065
|
+
|
|
1066
|
+
sendSEIMessage(buffer, options)
|
|
1067
|
+
|
|
1068
|
+
Send SEI Message
|
|
1069
|
+
|
|
1070
|
+
> The header of a video frame has a header block called SEI.
|
|
1071
|
+
> The principle of this interface is to use the SEI to embed the custom data you want to send along with the video frame.
|
|
1072
|
+
> SEI messages can accompany video frames all the way to the live CDN.
|
|
1073
|
+
|
|
1074
|
+
Applicable scenarios: synchronization of lyrics, live answering questions, etc.
|
|
1075
|
+
|
|
1076
|
+
When to call: call after [trtc.startLocalVideo](TRTC.html#startLocalVideo) or trtc.startLocalScreen when set 'toSubStream' option to true successfully.
|
|
1077
|
+
|
|
1078
|
+
Note:
|
|
1079
|
+
|
|
1080
|
+
1. Maximum 1KB(Byte) sent in a single call, maximum 30 calls per second, maximum 8KB sent per second.
|
|
1081
|
+
2. Supported browsers: Chrome 86+, Edge 86+, Opera 72+, Safari 15.4+, Firefox 117+. Safari and Firefox are supported since v5.8.0.
|
|
1082
|
+
3. Since SEI is sent along with video frames, there is a possibility that video frames may be lost, and therefore SEI may be lost as well. The number of times it can be sent can be increased within the frequency limit, and the business side needs to do message de-duplication on the receiving side.
|
|
1083
|
+
4. SEI cannot be sent without trtc.startLocalVideo(or trtc.startLocalScreen when set 'toSubStream' option to true); SEI cannot be received without startRemoteVideo.
|
|
1084
|
+
5. Only H264 encoder is supported to send SEI.
|
|
1085
|
+
|
|
1086
|
+
**Since:** v5.3.0
|
|
1087
|
+
|
|
1088
|
+
**See:** [TRTC.EVENT.SEI_MESSAGE](module-EVENT.html#.SEI_MESSAGE)
|
|
1089
|
+
|
|
1090
|
+
#### Example
|
|
1091
|
+
|
|
1092
|
+
```javascript
|
|
1093
|
+
// 1. enable SEI
|
|
1094
|
+
const trtc = TRTC.create({
|
|
1095
|
+
enableSEI: true
|
|
1096
|
+
})
|
|
1097
|
+
// 2. send SEI
|
|
1098
|
+
try {
|
|
1099
|
+
await trtc.enterRoom({
|
|
1100
|
+
userId: 'user_1',
|
|
1101
|
+
roomId: 12345,
|
|
1102
|
+
})
|
|
1103
|
+
await trtc.startLocalVideo();
|
|
1104
|
+
const unit8Array = new Uint8Array([1, 2, 3]);
|
|
1105
|
+
trtc.sendSEIMessage(unit8Array.buffer);
|
|
1106
|
+
} catch(error) {
|
|
1107
|
+
console.warn(error);
|
|
1108
|
+
}
|
|
1109
|
+
// 3. receive SEI
|
|
1110
|
+
trtc.on(TRTC.EVENT.SEI_MESSAGE, event => {
|
|
1111
|
+
console.warn(`sei ${event.data} from ${event.userId}`);
|
|
1112
|
+
})
|
|
1113
|
+
```
|
|
1114
|
+
|
|
1115
|
+
#### Parameters
|
|
1116
|
+
|
|
1117
|
+
| Name | Type | Description |
|
|
1118
|
+
|------|------|-------------|
|
|
1119
|
+
| buffer | ArrayBuffer | **required** SEI data to be sent |
|
|
1120
|
+
| options | Object | SEI options |
|
|
1121
|
+
|
|
1122
|
+
**Properties**
|
|
1123
|
+
|
|
1124
|
+
| Name | Type | Default | Description |
|
|
1125
|
+
|------|------|---------|-------------|
|
|
1126
|
+
| seiPayloadType | Number | | **required** Set the SEI payload type. SDK uses the custom payloadType 243 by default, the business side can use this parameter to set the payloadType to the standard 5. When the business side uses the 5 payloadType, you need to follow the specification to make sure that the first 16 bytes of the `buffer` are the business side's customized uuid. |
|
|
1127
|
+
| toSubStream | Boolean | false | Send SEI data to substream. Need call trtc.startLocalScreen first. Since v5.7.0+. |
|
|
1128
|
+
|
|
1129
|
+
### sendCustomMessage
|
|
1130
|
+
|
|
1131
|
+
sendCustomMessage(message)
|
|
1132
|
+
|
|
1133
|
+
Send Custom Message to all remote users in the room.
|
|
1134
|
+
|
|
1135
|
+
Note:
|
|
1136
|
+
|
|
1137
|
+
1. Only [TRTC.TYPE.ROLE_ANCHOR](module-TYPE.html#.ROLE_ANCHOR) can call sendCustomMessage.
|
|
1138
|
+
2. You should call this api after [TRTC.enterRoom](TRTC.html#enterRoom) successfully.
|
|
1139
|
+
3. The custom message will be sent in order and as reliably as possible, but it's possible to loss messages in a very bad network. The receiver will also receive the message in order.
|
|
1140
|
+
|
|
1141
|
+
**Since:** v5.6.0
|
|
1142
|
+
|
|
1143
|
+
**See:** Listen for the event [TRTC.EVENT.CUSTOM_MESSAGE](module-EVENT.html#.CUSTOM_MESSAGE) to receive custom message.
|
|
1144
|
+
|
|
1145
|
+
#### Example
|
|
1146
|
+
|
|
1147
|
+
```javascript
|
|
1148
|
+
// send custom message
|
|
1149
|
+
trtc.sendCustomMessage({
|
|
1150
|
+
cmdId: 1,
|
|
1151
|
+
data: new TextEncoder().encode('hello').buffer
|
|
1152
|
+
});
|
|
1153
|
+
// receive custom message
|
|
1154
|
+
trtc.on(TRTC.EVENT.CUSTOM_MESSAGE, event => {
|
|
1155
|
+
// event.userId: remote userId.
|
|
1156
|
+
// event.cmdId: message cmdId.
|
|
1157
|
+
// event.seq: message sequence number.
|
|
1158
|
+
// event.data: custom message data, type is ArrayBuffer.
|
|
1159
|
+
console.log(`received custom msg from ${event.userId}, message: ${new TextDecoder().decode(event.data)}`)
|
|
1160
|
+
})
|
|
1161
|
+
```
|
|
1162
|
+
|
|
1163
|
+
#### Parameters
|
|
1164
|
+
|
|
1165
|
+
| Name | Type | Description |
|
|
1166
|
+
|------|------|-------------|
|
|
1167
|
+
| message | object | **required** Custom message |
|
|
1168
|
+
|
|
1169
|
+
**Properties**
|
|
1170
|
+
|
|
1171
|
+
| Name | Type | Description |
|
|
1172
|
+
|------|------|-------------|
|
|
1173
|
+
| cmdId | number | **required** message Id. Integer, range [1, 10]. You can set different cmdId for different types of messages to reduce the delay of transferring message. |
|
|
1174
|
+
| data | ArrayBuffer | **required** message content.<br>- Maximum 1KB(Byte) sent in a single call.<br>- Maximum 30 calls per second<br>- Maximum 8KB sent per second. |
|
|
1175
|
+
|
|
1176
|
+
### callExperimentalAPI
|
|
1177
|
+
|
|
1178
|
+
**(async)** callExperimentalAPI(name, options)
|
|
1179
|
+
|
|
1180
|
+
call experimental API
|
|
1181
|
+
|
|
1182
|
+
| APIName | name | param |
|
|
1183
|
+
|---------|------|-------|
|
|
1184
|
+
| 'enableAudioFrameEvent' | Config the pcm data of Audio Frame Event | [EnableAudioFrameEventOptions](https://web.sdk.qcloud.com/trtc/webrtc/v5/doc/en/global.html#EnableAudioFrameEventOptions) |
|
|
1185
|
+
|
|
1186
|
+
#### Example
|
|
1187
|
+
|
|
1188
|
+
```javascript
|
|
1189
|
+
// Call back the pcm data of the remote user 'user_A'. The default pcm data is 48kHZ, mono
|
|
1190
|
+
await trtc.callExperimentalAPI('enableAudioFrameEvent', { enable: true, userId: 'user_A'})
|
|
1191
|
+
// Call back all remote pcm data and set the pcm data to 16kHZ, stereo
|
|
1192
|
+
await trtc.callExperimentalAPI('enableAudioFrameEvent', { enable: true, userId: '*', sampleRate: 16000, channelCount: 2 })
|
|
1193
|
+
// Set the MessagePort for the local microphone pcm data callback
|
|
1194
|
+
await trtc.callExperimentalAPI('enableAudioFrameEvent', { enable: true, userId: '', port })
|
|
1195
|
+
// Cancel callback of local microphone pcm data
|
|
1196
|
+
await trtc.callExperimentalAPI('enableAudioFrameEvent', { enable: false, userId: '' })
|
|
1197
|
+
```
|
|
1198
|
+
|
|
1199
|
+
#### Parameters
|
|
1200
|
+
|
|
1201
|
+
| Name | Type | Description |
|
|
1202
|
+
|------|------|-------------|
|
|
1203
|
+
| name | string | **required** |
|
|
1204
|
+
| options | EnableAudioFrameEventOptions | **required** |
|
|
1205
|
+
|
|
1206
|
+
### setLogLevel
|
|
1207
|
+
|
|
1208
|
+
**(static)** setLogLevel(level, enableUploadLog)
|
|
1209
|
+
|
|
1210
|
+
Set the log output level
|
|
1211
|
+
|
|
1212
|
+
It is recommended to set the DEBUG level during development and testing, which includes detailed prompt information.
|
|
1213
|
+
The default output level is INFO, which includes the log information of the main functions of the SDK.
|
|
1214
|
+
|
|
1215
|
+
#### Example
|
|
1216
|
+
|
|
1217
|
+
```javascript
|
|
1218
|
+
// Output log levels above DEBUG
|
|
1219
|
+
TRTC.setLogLevel(1);
|
|
1220
|
+
```
|
|
1221
|
+
|
|
1222
|
+
#### Parameters
|
|
1223
|
+
|
|
1224
|
+
| Name | Type | Default | Description |
|
|
1225
|
+
|------|------|---------|-------------|
|
|
1226
|
+
| level | 0-5 | | Log output level 0: TRACE 1: DEBUG 2: INFO 3: WARN 4: ERROR 5: NONE |
|
|
1227
|
+
| enableUploadLog | boolean | true | Whether to enable log upload, which is enabled by default. It is not recommended to turn it off, which will affect problem troubleshooting.<br>- Logs are uploaded to Tencent Cloud servers and are only used by developers to troubleshoot problems. If you need to obtain log information, you can [contact us](https://trtc.io/contact). |
|
|
1228
|
+
|
|
1229
|
+
### isSupported
|
|
1230
|
+
|
|
1231
|
+
**(static)** isSupported() → {Promise.\<object>}
|
|
1232
|
+
|
|
1233
|
+
Check if the TRTC Web SDK is supported by the current browser
|
|
1234
|
+
|
|
1235
|
+
- Reference: [Browsers Supported](tutorial-05-info-browser.html).
|
|
1236
|
+
|
|
1237
|
+
#### Example
|
|
1238
|
+
|
|
1239
|
+
```javascript
|
|
1240
|
+
TRTC.isSupported().then((checkResult) => {
|
|
1241
|
+
if(!checkResult.result) {
|
|
1242
|
+
console.log('checkResult', checkResult.result, 'checkDetail', checkResult.detail);
|
|
1243
|
+
// The SDK does not support the current browser. Guide the user to use the latest version of Chrome.
|
|
1244
|
+
}
|
|
1245
|
+
const { isBrowserSupported, isWebRTCSupported, isMediaDevicesSupported, isH264EncodeSupported, isH264DecodeSupported } = checkResult.detail;
|
|
1246
|
+
// Different business scenarios may require varying levels of detection granularity, such as only needing pushing or pulling stream.
|
|
1247
|
+
// Detect whether the browser supports capturing the camera and microphone for upstreaming.
|
|
1248
|
+
const isPushMicrophoneSupported = isBrowserSupported && isWebRTCSupported && isMediaDevicesSupported;
|
|
1249
|
+
const isPushCameraSupported = isBrowserSupported && isWebRTCSupported && isMediaDevicesSupported && isH264EncodeSupported;
|
|
1250
|
+
// Detect whether the browser supports pulling stream.
|
|
1251
|
+
const isPullAudioSupported = isBrowserSupported && isWebRTCSupported;
|
|
1252
|
+
const isPullVideoSupported = isBrowserSupported && isWebRTCSupported && isH264DecodeSupported;
|
|
1253
|
+
});
|
|
1254
|
+
```
|
|
1255
|
+
|
|
1256
|
+
#### Returns
|
|
1257
|
+
|
|
1258
|
+
Promise returns the detection result
|
|
1259
|
+
|
|
1260
|
+
| Property | Type | Description |
|
|
1261
|
+
|----------|------|-------------|
|
|
1262
|
+
| checkResult.result | boolean | If true, it means the current environment supports the basic ability to capture the camera and microphone for streaming. |
|
|
1263
|
+
| checkResult.detail.isBrowserSupported | boolean | Whether the current browser is supported by the SDK |
|
|
1264
|
+
| checkResult.detail.isWebRTCSupported | boolean | Whether the current browser supports WebRTC |
|
|
1265
|
+
| checkResult.detail.isWebCodecsSupported | boolean | Whether the current browser supports WebCodecs |
|
|
1266
|
+
| checkResult.detail.isMediaDevicesSupported | boolean | Whether the current browser supports accessing media devices and capturing microphone/camera |
|
|
1267
|
+
| checkResult.detail.isScreenShareSupported | boolean | Whether the current browser supports screen sharing functionality |
|
|
1268
|
+
| checkResult.detail.isSmallStreamSupported | boolean | Whether the current browser supports small streams |
|
|
1269
|
+
| checkResult.detail.isH264EncodeSupported | boolean | Whether the current browser supports H264 encoding |
|
|
1270
|
+
| checkResult.detail.isH264DecodeSupported | boolean | Whether the current browser supports H264 decoding |
|
|
1271
|
+
| checkResult.detail.isVp8EncodeSupported | boolean | Whether the current browser supports VP8 encoding |
|
|
1272
|
+
| checkResult.detail.isVp8DecodeSupported | boolean | Whether the current browser supports VP8 decoding |
|
|
1273
|
+
|
|
1274
|
+
**Type:** Promise.\<object>
|
|
1275
|
+
|
|
1276
|
+
### getPermissions
|
|
1277
|
+
|
|
1278
|
+
**(async, static)** getPermissions(option) → {Promise.\<PermissionResult>}
|
|
1279
|
+
|
|
1280
|
+
Get the permission state of the camera and microphone.
|
|
1281
|
+
|
|
1282
|
+
**Since:** v5.13.0
|
|
1283
|
+
|
|
1284
|
+
#### Example
|
|
1285
|
+
|
|
1286
|
+
```javascript
|
|
1287
|
+
const { camera, microphone } = await TRTC.getPermissions({
|
|
1288
|
+
request: true, // if true, will request permission to use the camera and microphone.
|
|
1289
|
+
types: ['camera', 'microphone']
|
|
1290
|
+
});
|
|
1291
|
+
console.log(camera, microphone); // 'granted' | 'denied' | 'prompt' | null. null means the permission is not supported query.
|
|
1292
|
+
```
|
|
1293
|
+
|
|
1294
|
+
#### Parameters
|
|
1295
|
+
|
|
1296
|
+
| Name | Type | Description |
|
|
1297
|
+
|------|------|-------------|
|
|
1298
|
+
| option | PermissionOption | **required** Permission options |
|
|
1299
|
+
|
|
1300
|
+
**Properties**
|
|
1301
|
+
|
|
1302
|
+
| Name | Type | Default | Description |
|
|
1303
|
+
|------|------|---------|-------------|
|
|
1304
|
+
| request | boolean | true | Whether to request permission to use the camera and microphone. |
|
|
1305
|
+
| types | Array.\<string> | ['camera', 'microphone'] | The types of permission to request. |
|
|
1306
|
+
|
|
1307
|
+
#### Returns
|
|
1308
|
+
|
|
1309
|
+
Promise returns the permission state of the camera and microphone
|
|
1310
|
+
|
|
1311
|
+
**Type:** Promise.\<PermissionResult>
|
|
1312
|
+
|
|
1313
|
+
### getCameraList
|
|
1314
|
+
|
|
1315
|
+
**(static)** getCameraList(requestPermission) → {Promise.\<Array.\<MediaDeviceInfo>>}
|
|
1316
|
+
|
|
1317
|
+
Returns the list of camera devices
|
|
1318
|
+
|
|
1319
|
+
**Note**
|
|
1320
|
+
|
|
1321
|
+
- This interface does not support use under the http protocol, please use the https protocol to deploy your website. [Privacy and security](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Privacy_and_security)
|
|
1322
|
+
- You can call the browser's native interface [getCapabilities](https://developer.mozilla.org/en-US/docs/Web/API/InputDeviceInfo/getCapabilities) to get the maximum resolutions supported by the camera, frame rate, and distinguish between front and rear cameras on mobile devices, etc. This interface supports Chrome 67+, Edge 79+, Safari 17+, Opera 54+.
|
|
1323
|
+
- On Huawei phones, the rear camera may capture the telephoto lens. In this case, you can use this interface to obtain the rear camera with the largest supported resolution. Generally, the main camera of a phone has the largest resolution.
|
|
1324
|
+
|
|
1325
|
+
#### Example
|
|
1326
|
+
|
|
1327
|
+
```javascript
|
|
1328
|
+
const cameraList = await TRTC.getCameraList();
|
|
1329
|
+
if (cameraList[0] && cameraList[0].getCapabilities) {
|
|
1330
|
+
const { width, height, frameRate, facingMode } = cameraList[0].getCapabilities();
|
|
1331
|
+
console.log(width.max, height.max, frameRate.max);
|
|
1332
|
+
if (facingMode) {
|
|
1333
|
+
if (facingMode[0] === 'user') {
|
|
1334
|
+
// front camera
|
|
1335
|
+
} else if (facingMode[0] === 'environment') {
|
|
1336
|
+
// rear camera
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
```
|
|
1341
|
+
|
|
1342
|
+
#### Parameters
|
|
1343
|
+
|
|
1344
|
+
| Name | Type | Default | Description |
|
|
1345
|
+
|------|------|---------|-------------|
|
|
1346
|
+
| requestPermission | boolean | true | **Since v5.6.3**. Whether to request permission to use the camera. If requestPermission is true, calling this method may temporarily open the camera to ensure that the camera list can be normally obtained, and the SDK will automatically stop the camera capture later. |
|
|
1347
|
+
|
|
1348
|
+
#### Returns
|
|
1349
|
+
|
|
1350
|
+
Promise returns an array of [MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo)
|
|
1351
|
+
|
|
1352
|
+
**Type:** Promise.\<Array.\<MediaDeviceInfo>>
|
|
1353
|
+
|
|
1354
|
+
### getMicrophoneList
|
|
1355
|
+
|
|
1356
|
+
**(static)** getMicrophoneList(requestPermission) → {Promise.\<Array.\<MediaDeviceInfo>>}
|
|
1357
|
+
|
|
1358
|
+
Returns the list of microphone devices
|
|
1359
|
+
|
|
1360
|
+
**Note**
|
|
1361
|
+
|
|
1362
|
+
- This interface does not support use under the http protocol, please use the https protocol to deploy your website. [Privacy and security](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Privacy_and_security)
|
|
1363
|
+
- You can call the browser's native interface [getCapabilities](https://developer.mozilla.org/en-US/docs/Web/API/InputDeviceInfo/getCapabilities) to get information about the microphone's capabilities, e.g. the maximum number of channels supported, etc. This interface supports Chrome 67+, Edge 79+, Safari 17+, Opera 54+.
|
|
1364
|
+
- On Android, there are usually multiple microphones, and the label list is: ['default', 'Speakerphone', 'Headset earpiece'], if you do not specify the microphone in trtc.startLocalAudio, the browser default microphone may be the Headset earpiece and the sound will come out of the headset. If you need to play out through the speaker, you need to specify the microphone with the label 'Speakerphone'.
|
|
1365
|
+
|
|
1366
|
+
#### Example
|
|
1367
|
+
|
|
1368
|
+
```javascript
|
|
1369
|
+
const microphoneList = await TRTC.getMicrophoneList();
|
|
1370
|
+
if (microphoneList[0] && microphoneList[0].getCapabilities) {
|
|
1371
|
+
const { channelCount } = microphoneList[0].getCapabilities();
|
|
1372
|
+
console.log(channelCount.max);
|
|
1373
|
+
}
|
|
1374
|
+
```
|
|
1375
|
+
|
|
1376
|
+
#### Parameters
|
|
1377
|
+
|
|
1378
|
+
| Name | Type | Default | Description |
|
|
1379
|
+
|------|------|---------|-------------|
|
|
1380
|
+
| requestPermission | boolean | true | **Since v5.6.3**. Whether to request permission to use the microphone. If requestPermission is true, calling this method may temporarily open the microphone to ensure that the microphone list can be normally obtained, and the SDK will automatically stop the microphone capture later. |
|
|
1381
|
+
|
|
1382
|
+
#### Returns
|
|
1383
|
+
|
|
1384
|
+
Promise returns an array of [MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo)
|
|
1385
|
+
|
|
1386
|
+
**Type:** Promise.\<Array.\<MediaDeviceInfo>>
|
|
1387
|
+
|
|
1388
|
+
### getSpeakerList
|
|
1389
|
+
|
|
1390
|
+
**(static)** getSpeakerList(requestPermission) → {Promise.\<Array.\<MediaDeviceInfo>>}
|
|
1391
|
+
|
|
1392
|
+
Returns the list of speaker devices. Only support PC browser, not support mobile browser.
|
|
1393
|
+
|
|
1394
|
+
#### Parameters
|
|
1395
|
+
|
|
1396
|
+
| Name | Type | Default | Description |
|
|
1397
|
+
|------|------|---------|-------------|
|
|
1398
|
+
| requestPermission | boolean | true | **Since v5.6.3**. Whether to request permission to use the microphone. If requestPermission is true, calling this method may temporarily open the microphone to ensure that the microphone list can be normally obtained, and the SDK will automatically stop the microphone capture later. |
|
|
1399
|
+
|
|
1400
|
+
#### Returns
|
|
1401
|
+
|
|
1402
|
+
Promise returns an array of [MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo)
|
|
1403
|
+
|
|
1404
|
+
**Type:** Promise.\<Array.\<MediaDeviceInfo>>
|
|
1405
|
+
|
|
1406
|
+
### setCurrentSpeaker
|
|
1407
|
+
|
|
1408
|
+
**(async, static)** setCurrentSpeaker(speakerId)
|
|
1409
|
+
|
|
1410
|
+
Set the current speaker for audio playback
|
|
1411
|
+
|
|
1412
|
+
**Note**
|
|
1413
|
+
|
|
1414
|
+
- This interface only supports PC and Android devices.
|
|
1415
|
+
- Android device requirements:
|
|
1416
|
+
- SDK version >= 5.9.0
|
|
1417
|
+
- Support switching between speaker and headset, i.e. pass in TRTC.TYPE.SPEAKER or TRTC.TYPE.HEADSET
|
|
1418
|
+
- Need to call [startLocalAudio()](TRTC.html#startLocalAudio) to collect microphone first
|
|
1419
|
+
|
|
1420
|
+
#### Example
|
|
1421
|
+
|
|
1422
|
+
```javascript
|
|
1423
|
+
// For PC
|
|
1424
|
+
TRTC.setCurrentSpeaker('your_expected_speaker_id');
|
|
1425
|
+
// For Android(sdk version >= 5.9.0)
|
|
1426
|
+
TRTC.setCurrentSpeaker(TRTC.TYPE.SPEAKER); // Switch to speaker
|
|
1427
|
+
TRTC.setCurrentSpeaker(TRTC.TYPE.HEADSET); // Or switch to headset
|
|
1428
|
+
```
|
|
1429
|
+
|
|
1430
|
+
#### Parameters
|
|
1431
|
+
|
|
1432
|
+
| Name | Type | Description |
|
|
1433
|
+
|------|------|-------------|
|
|
1434
|
+
| speakerId | string \| TRTC.TYPE.SPEAKER \| TRTC.TYPE.HEADSET | **required** Speaker ID, support passing in speaker ID or TRTC.TYPE.SPEAKER or TRTC.TYPE.HEADSET |
|
|
1435
|
+
|
|
1436
|
+
## EVENT
|
|
1437
|
+
|
|
1438
|
+
**TRTC Event List**
|
|
1439
|
+
|
|
1440
|
+
Listen to specific events through [trtc.on(TRTC.EVENT.XXX)](TRTC.html#on). You can use these events to manage the room user list, manage user stream state, and perceive network state. The following is a detailed introduction to the events.
|
|
1441
|
+
|
|
1442
|
+
> **Notice:**
|
|
1443
|
+
> - Events need to be listened to before they are triggered, so that you can receive the corresponding event notifications. Therefore, it is recommended to complete event listening before entering the room, so as to ensure that no event notifications are missed.
|
|
1444
|
+
|
|
1445
|
+
### Example
|
|
1446
|
+
|
|
1447
|
+
```javascript
|
|
1448
|
+
// Usage:
|
|
1449
|
+
trtc.on(TRTC.EVENT.ERROR, () => {});
|
|
1450
|
+
```
|
|
1451
|
+
|
|
1452
|
+
### Members
|
|
1453
|
+
|
|
1454
|
+
#### ERROR
|
|
1455
|
+
|
|
1456
|
+
**Default Value:** 'error'
|
|
1457
|
+
|
|
1458
|
+
**See:** [RtcError](RtcError.html)
|
|
1459
|
+
|
|
1460
|
+
Error event, non-API call error, SDK throws when an unrecoverable error occurs during operation.
|
|
1461
|
+
|
|
1462
|
+
- Error code (error.code): [ErrorCode.OPERATION_FAILED](module-ERROR_CODE.html#.OPERATION_FAILED)
|
|
1463
|
+
- Possible extended error codes (error.extraCode): 5501, 5502
|
|
1464
|
+
|
|
1465
|
+
##### Example
|
|
1466
|
+
|
|
1467
|
+
```javascript
|
|
1468
|
+
trtc.on(TRTC.EVENT.ERROR, error => {
|
|
1469
|
+
console.error('trtc error observed: ' + error);
|
|
1470
|
+
const errorCode = error.code;
|
|
1471
|
+
const extraCode = error.extraCode;
|
|
1472
|
+
});
|
|
1473
|
+
```
|
|
1474
|
+
|
|
1475
|
+
#### AUTOPLAY_FAILED
|
|
1476
|
+
|
|
1477
|
+
**Default Value:** 'autoplay-failed'
|
|
1478
|
+
|
|
1479
|
+
Automatic playback failed, refer to [Handle Autoplay Restriction](tutorial-21-advanced-auto-play-policy.html)
|
|
1480
|
+
|
|
1481
|
+
##### Example
|
|
1482
|
+
|
|
1483
|
+
```javascript
|
|
1484
|
+
trtc.on(TRTC.EVENT.AUTOPLAY_FAILED, event => {
|
|
1485
|
+
// Guide user to click the page, SDK will resume playback automatically when user click the page.
|
|
1486
|
+
// Since v5.1.3+, you can get userId on this event.
|
|
1487
|
+
console.log(event.userId);
|
|
1488
|
+
// Since v5.11.0+, mediaType includes 'audio'|'video'|'screen'.
|
|
1489
|
+
console.log(event.mediaType);
|
|
1490
|
+
// Since v5.9.0+, you can call the `resume` method to resume playback of the stream corresponding to event.userId when user clicked the page.
|
|
1491
|
+
event.resume();
|
|
1492
|
+
});
|
|
1493
|
+
```
|
|
1494
|
+
|
|
1495
|
+
#### KICKED_OUT
|
|
1496
|
+
|
|
1497
|
+
**Default Value:** 'kicked-out'
|
|
1498
|
+
|
|
1499
|
+
Kicked out of the room for some reason, including:
|
|
1500
|
+
|
|
1501
|
+
- **kick**: The same user with same userId enters same room. The user who enters the room first will be kicked out of the room by the user who enters later.
|
|
1502
|
+
- Entering a room with the same userId is not allowed behavior, which may lead to abnormal audio/video calls between the two parties, and should be avoided on the business side.
|
|
1503
|
+
- Users with the same userId who enter the same room with the same audience role may not receive this event.
|
|
1504
|
+
- **banned**: kicked out by the administrator using [Server API - RemoveUser](https://trtc.io/document/34267/34268).
|
|
1505
|
+
- **room_disband**: kicked out by the administrator using [Server API - DismissRoom](https://trtc.io/document/34267/34269).
|
|
1506
|
+
|
|
1507
|
+
##### Example
|
|
1508
|
+
|
|
1509
|
+
```javascript
|
|
1510
|
+
trtc.on(TRTC.EVENT.KICKED_OUT, event => {
|
|
1511
|
+
console.log(event.reason)
|
|
1512
|
+
});
|
|
1513
|
+
```
|
|
1514
|
+
|
|
1515
|
+
#### REMOTE_USER_ENTER
|
|
1516
|
+
|
|
1517
|
+
**Default Value:** 'remote-user-enter'
|
|
1518
|
+
|
|
1519
|
+
Remote user enters the room event.
|
|
1520
|
+
|
|
1521
|
+
- In `rtc` mode, all users will receive the notification of entering and exiting the room of the other user.
|
|
1522
|
+
- In `live` mode, only the anchor has the notification of entering and exiting the room, and the audience does not have the notification of entering and exiting the room. The audience can receive the notification of entering and exiting the room of the anchor.
|
|
1523
|
+
|
|
1524
|
+
##### Example
|
|
1525
|
+
|
|
1526
|
+
```javascript
|
|
1527
|
+
trtc.on(TRTC.EVENT.REMOTE_USER_ENTER, event => {
|
|
1528
|
+
const userId = event.userId;
|
|
1529
|
+
});
|
|
1530
|
+
```
|
|
1531
|
+
|
|
1532
|
+
#### REMOTE_USER_EXIT
|
|
1533
|
+
|
|
1534
|
+
**Default Value:** 'remote-user-exit'
|
|
1535
|
+
|
|
1536
|
+
Remote user exits the room event.
|
|
1537
|
+
|
|
1538
|
+
- In `rtc` mode, all users will receive the notification of entering and exiting the room of the other user.
|
|
1539
|
+
- In `live` mode, only the anchor has the notification of entering and exiting the room, and the audience does not have the notification of entering and exiting the room. The audience can receive the notification of entering and exiting the room of the anchor.
|
|
1540
|
+
|
|
1541
|
+
##### Example
|
|
1542
|
+
|
|
1543
|
+
```javascript
|
|
1544
|
+
trtc.on(TRTC.EVENT.REMOTE_USER_EXIT, event => {
|
|
1545
|
+
const userId = event.userId;
|
|
1546
|
+
});
|
|
1547
|
+
```
|
|
1548
|
+
|
|
1549
|
+
#### REMOTE_AUDIO_AVAILABLE
|
|
1550
|
+
|
|
1551
|
+
**Default Value:** 'remote-audio-available'
|
|
1552
|
+
|
|
1553
|
+
Remote user publishes audio. You will receive this notification when the remote user turns on the microphone. Refer to: [Turn on/off camera and microphone](./tutorial-15-basic-dynamic-add-video.html)
|
|
1554
|
+
|
|
1555
|
+
- By default, the SDK automatically plays remote audio, and you do not need to call the API to play remote audio. You can listen for this event and [REMOTE_AUDIO_UNAVAILABLE](#remote_audio_unavailable) to update the UI icon for "whether the remote microphone is turned on".
|
|
1556
|
+
- Note: If the user has not interacted with the page before entering the room, automatic audio playback may fail due to the [browser's automatic playback policy restrictions](./tutorial-21-advanced-auto-play-policy.html). You need to refer to the [suggestions for handling automatic playback restrictions](./tutorial-21-advanced-auto-play-policy.html) for processing.
|
|
1557
|
+
- If you do not want the SDK to automatically play audio, you can set `autoReceiveAudio` to `false` to turn off automatic audio playback when calling [trtc.enterRoom()](TRTC.html#enterRoom).
|
|
1558
|
+
- Listen for the [TRTC.EVENT.REMOTE_AUDIO_AVAILABLE](#remote_audio_available) event, record the userId with remote audio, and call the [trtc.muteRemoteAudio(userId, false)](TRTC.html#muteRemoteAudio) method when you need to play audio.
|
|
1559
|
+
|
|
1560
|
+
##### Example
|
|
1561
|
+
|
|
1562
|
+
```javascript
|
|
1563
|
+
// Listen before entering the room
|
|
1564
|
+
trtc.on(TRTC.EVENT.REMOTE_AUDIO_AVAILABLE, event => {
|
|
1565
|
+
const userId = event.userId;
|
|
1566
|
+
});
|
|
1567
|
+
```
|
|
1568
|
+
|
|
1569
|
+
#### REMOTE_AUDIO_UNAVAILABLE
|
|
1570
|
+
|
|
1571
|
+
**Default Value:** 'remote-audio-unavailable'
|
|
1572
|
+
|
|
1573
|
+
Remote user stops publishing audio. You will receive this notification when the remote user turns off the microphone.
|
|
1574
|
+
|
|
1575
|
+
##### Example
|
|
1576
|
+
|
|
1577
|
+
```javascript
|
|
1578
|
+
// Listen before entering the room
|
|
1579
|
+
trtc.on(TRTC.EVENT.REMOTE_AUDIO_UNAVAILABLE, event => {
|
|
1580
|
+
const userId = event.userId;
|
|
1581
|
+
});
|
|
1582
|
+
```
|
|
1583
|
+
|
|
1584
|
+
#### REMOTE_VIDEO_AVAILABLE
|
|
1585
|
+
|
|
1586
|
+
**Default Value:** 'remote-video-available'
|
|
1587
|
+
|
|
1588
|
+
**See:** [STREAM_TYPE_MAIN](module-TYPE.html#.STREAM_TYPE_MAIN), [STREAM_TYPE_SUB](module-TYPE.html#.STREAM_TYPE_SUB)
|
|
1589
|
+
|
|
1590
|
+
Remote user publishes video. You will receive this notification when the remote user turns on the camera. Refer to: [Turn on/off camera and microphone](./tutorial-15-basic-dynamic-add-video.html)
|
|
1591
|
+
|
|
1592
|
+
- You can listen for this event and [REMOTE_VIDEO_UNAVAILABLE](#remote_video_unavailable) to update the UI icon for "whether the remote camera is turned on".
|
|
1593
|
+
|
|
1594
|
+
##### Example
|
|
1595
|
+
|
|
1596
|
+
```javascript
|
|
1597
|
+
// Listen before entering the room
|
|
1598
|
+
trtc.on(TRTC.EVENT.REMOTE_VIDEO_AVAILABLE, event => {
|
|
1599
|
+
const userId = event.userId;
|
|
1600
|
+
const streamType = event.streamType;
|
|
1601
|
+
trtc.startRemoteVideo({userId, streamType, view});
|
|
1602
|
+
});
|
|
1603
|
+
```
|
|
1604
|
+
|
|
1605
|
+
#### REMOTE_VIDEO_UNAVAILABLE
|
|
1606
|
+
|
|
1607
|
+
**Default Value:** 'remote-video-unavailable'
|
|
1608
|
+
|
|
1609
|
+
Remote user stops publishing video. You will receive this notification when the remote user turns off the camera.
|
|
1610
|
+
|
|
1611
|
+
##### Example
|
|
1612
|
+
|
|
1613
|
+
```javascript
|
|
1614
|
+
// Listen before entering the room
|
|
1615
|
+
trtc.on(TRTC.EVENT.REMOTE_VIDEO_UNAVAILABLE, event => {
|
|
1616
|
+
const userId = event.userId;
|
|
1617
|
+
const streamType = event.streamType;
|
|
1618
|
+
// At this point, the SDK will automatically stop playing, and there is no need to call stopRemoteVideo.
|
|
1619
|
+
});
|
|
1620
|
+
```
|
|
1621
|
+
|
|
1622
|
+
#### AUDIO_VOLUME
|
|
1623
|
+
|
|
1624
|
+
**Default Value:** 'audio-volume'
|
|
1625
|
+
|
|
1626
|
+
Volume event
|
|
1627
|
+
|
|
1628
|
+
After calling the [enableAudioVolumeEvaluation](TRTC.html#enableAudioVolumeEvaluation) interface to enable the volume callback, the SDK will throw this event regularly to notify the volume of each userId.
|
|
1629
|
+
|
|
1630
|
+
**Note**
|
|
1631
|
+
|
|
1632
|
+
- The callback contains the volume of the local microphone and the volume of the remote user. The callback will be triggered regardless of whether anyone is speaking.
|
|
1633
|
+
- The event.result will be sorted from large to small according to the volume size.
|
|
1634
|
+
- When userId is an empty string, it represents the volume of the local microphone.
|
|
1635
|
+
- `volume` is a positive integer with a value of 0-100.
|
|
1636
|
+
- `floatVolume` is a float number with a value of 0-1.0. Since v5.11.1+. The floatVolume will be 0 when the microphone exception occurs. If user is not speaking, the floatVolume will be a non-zero float number.
|
|
1637
|
+
|
|
1638
|
+
##### Example
|
|
1639
|
+
|
|
1640
|
+
```javascript
|
|
1641
|
+
trtc.on(TRTC.EVENT.AUDIO_VOLUME, event => {
|
|
1642
|
+
event.result.forEach(({ userId, volume, floatVolume }) => {
|
|
1643
|
+
const isMe = userId === ''; // When userId is an empty string, it represents the volume of the local microphone.
|
|
1644
|
+
if (isMe) {
|
|
1645
|
+
console.log(`my volume: ${volume}`);
|
|
1646
|
+
} else {
|
|
1647
|
+
console.log(`user: ${userId} volume: ${volume}`);
|
|
1648
|
+
}
|
|
1649
|
+
})
|
|
1650
|
+
});
|
|
1651
|
+
// Enable volume callback and trigger the event every 1000ms
|
|
1652
|
+
trtc.enableAudioVolumeEvaluation(1000);
|
|
1653
|
+
```
|
|
1654
|
+
|
|
1655
|
+
#### AUDIO_FRAME
|
|
1656
|
+
|
|
1657
|
+
**Since:** v5.8.3
|
|
1658
|
+
|
|
1659
|
+
**Default Value:** 'audio-frame'
|
|
1660
|
+
|
|
1661
|
+
PCM event of microphone, the pcm data can be used to do ASR. since v5.11.0, support callback of raw pcm data from remote users.
|
|
1662
|
+
|
|
1663
|
+
**Note**
|
|
1664
|
+
|
|
1665
|
+
- By default, only the microphone data is called back. If you need to subscribe to the remote user's audio, you need to call trtc.callExperimentalAPI('enableAudioFrameEvent', options) to enable the callback. For details, please visit [TRTC#callExperimentalAPI](TRTC.html#callExperimentalAPI)
|
|
1666
|
+
- After starting the microphone or subscribing to the remote user's audio, this event is triggered every 40ms to obtain pcm data (float32 type).
|
|
1667
|
+
- PCM data is mono and sampled at 48000Hz. Since v5.11.0, Other sampling rates and channel count can be specified through [TRTC#callExperimentalAPI](TRTC.html#callExperimentalAPI).
|
|
1668
|
+
|
|
1669
|
+
##### Example
|
|
1670
|
+
|
|
1671
|
+
```javascript
|
|
1672
|
+
trtc.on(TRTC.EVENT.AUDIO_FRAME, event => {
|
|
1673
|
+
console.log(event.data) // pcm data. If it is mono, the data type is float32Array, if it is stereo, the data type is float32Array[].
|
|
1674
|
+
console.log(event.userId) // since v5.11.0. If userId is empty string, it means local microphone.
|
|
1675
|
+
console.log(event.channelCount) // since v5.11.0. 1 means mono, 2 means stereo.
|
|
1676
|
+
console.log(event.sampleRate) // since v5.11.0. The sampling rate of the pcm data.
|
|
1677
|
+
});
|
|
1678
|
+
```
|
|
1679
|
+
|
|
1680
|
+
#### NETWORK_QUALITY
|
|
1681
|
+
|
|
1682
|
+
**Default Value:** 'network-quality'
|
|
1683
|
+
|
|
1684
|
+
Network quality statistics data event, which starts to be counted after entering the room and triggers every two seconds. This data reflects the network quality of your local uplink and downlink.
|
|
1685
|
+
|
|
1686
|
+
- The uplink network quality (uplinkNetworkQuality) refers to the network situation of uploading local streams (uplink connection network quality from SDK to Tencent Cloud)
|
|
1687
|
+
- The downlink network quality (downlinkNetworkQuality) refers to the average network situation of downloading all streams (average network quality of all downlink connections from Tencent Cloud to SDK)
|
|
1688
|
+
|
|
1689
|
+
The enumeration values and meanings are shown in the following table:
|
|
1690
|
+
|
|
1691
|
+
| Value | Meaning |
|
|
1692
|
+
|-------|---------|
|
|
1693
|
+
| 0 | Network state is unknown, indicating that the current trtc instance has not established an uplink/downlink connection |
|
|
1694
|
+
| 1 | Network state is excellent |
|
|
1695
|
+
| 2 | Network state is good |
|
|
1696
|
+
| 3 | Network state is average |
|
|
1697
|
+
| 4 | Network state is poor |
|
|
1698
|
+
| 5 | Network state is very poor |
|
|
1699
|
+
| 6 | Network connection is disconnected<br />Note: If the downlink network quality is this value, it means that all downlink connections have been disconnected |
|
|
1700
|
+
|
|
1701
|
+
- uplinkRTT, uplinkLoss are the uplink RTT (ms) and uplink packet loss rate.
|
|
1702
|
+
- downlinkRTT, downlinkLoss are the average RTT (ms) and average packet loss rate of all downlink connections.
|
|
1703
|
+
|
|
1704
|
+
**Note**
|
|
1705
|
+
|
|
1706
|
+
- If you want to know the uplink and downlink network conditions of the other party, you need to broadcast the other party's network quality through IM.
|
|
1707
|
+
|
|
1708
|
+
##### Example
|
|
1709
|
+
|
|
1710
|
+
```javascript
|
|
1711
|
+
trtc.on(TRTC.EVENT.NETWORK_QUALITY, event => {
|
|
1712
|
+
console.log(`network-quality, uplinkNetworkQuality:${event.uplinkNetworkQuality}, downlinkNetworkQuality: ${event.downlinkNetworkQuality}`)
|
|
1713
|
+
console.log(`uplink rtt:${event.uplinkRTT} loss:${event.uplinkLoss}`)
|
|
1714
|
+
console.log(`downlink rtt:${event.downlinkRTT} loss:${event.downlinkLoss}`)
|
|
1715
|
+
})
|
|
1716
|
+
```
|
|
1717
|
+
|
|
1718
|
+
#### CONNECTION_STATE_CHANGED
|
|
1719
|
+
|
|
1720
|
+
**Default Value:** 'connection-state-changed'
|
|
1721
|
+
|
|
1722
|
+
SDK and Tencent Cloud connection state change event, you can use this event to listen to the overall connection state of the SDK and Tencent Cloud.
|
|
1723
|
+
|
|
1724
|
+
- 'DISCONNECTED': Connection disconnected
|
|
1725
|
+
- 'CONNECTING': Connecting
|
|
1726
|
+
- 'CONNECTED': Connected
|
|
1727
|
+
|
|
1728
|
+
Meanings of different state changes:
|
|
1729
|
+
|
|
1730
|
+
- DISCONNECTED -> CONNECTING: Trying to establish a connection, triggered when calling the enter room interface or when the SDK automatically reconnects.
|
|
1731
|
+
- CONNECTING -> DISCONNECTED: Connection establishment failed, triggered when calling the exit room interface to interrupt the connection or when the connection fails after SDK retries.
|
|
1732
|
+
- CONNECTING -> CONNECTED: Connection established successfully, triggered when the connection is successful.
|
|
1733
|
+
- CONNECTED -> DISCONNECTED: Connection interrupted, triggered when calling the exit room interface or when the connection is disconnected due to network anomalies.
|
|
1734
|
+
|
|
1735
|
+
Suggestion: You can listen to this event and display different UIs in different states to remind users of the current connection state.
|
|
1736
|
+
|
|
1737
|
+
##### Example
|
|
1738
|
+
|
|
1739
|
+
```javascript
|
|
1740
|
+
trtc.on(TRTC.EVENT.CONNECTION_STATE_CHANGED, event => {
|
|
1741
|
+
const prevState = event.prevState;
|
|
1742
|
+
const curState = event.state;
|
|
1743
|
+
});
|
|
1744
|
+
```
|
|
1745
|
+
|
|
1746
|
+
#### AUDIO_PLAY_STATE_CHANGED
|
|
1747
|
+
|
|
1748
|
+
**Default Value:** 'audio-play-state-changed'
|
|
1749
|
+
|
|
1750
|
+
Audio playback state change event
|
|
1751
|
+
|
|
1752
|
+
event.userId When userId is an empty string, it represents the local user, and when it is a non-empty string, it represents a remote user.
|
|
1753
|
+
|
|
1754
|
+
event.state The value is as follows:
|
|
1755
|
+
|
|
1756
|
+
- 'PLAYING': start playing
|
|
1757
|
+
- event.reason is 'playing' or 'unmute'.
|
|
1758
|
+
- 'PAUSED': pause playback
|
|
1759
|
+
- When event.reason is 'pause', it is triggered by the pause event of the <audio> element. The following situations will trigger:
|
|
1760
|
+
- Call the HTMLMediaElement.pause interface.
|
|
1761
|
+
- When event.reason is 'mute'. See event [MediaStreamTrack.mute_event](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/mute_event)
|
|
1762
|
+
- When userId is oneself, this event is triggered, indicating that audio collection is paused, usually caused by device abnormalities, such as being preempted by other applications on the device, at this time, the user needs to be guided to recollect.
|
|
1763
|
+
- When userId is others, this event is triggered, indicating that the received audio data is not enough to play. Usually caused by network jitter, no processing is required on the access side. When the received data is sufficient to play, it will automatically resume.
|
|
1764
|
+
- 'STOPPED': stop playing
|
|
1765
|
+
- event.reason is 'ended'.
|
|
1766
|
+
|
|
1767
|
+
event.reason The reason for the state change, the value is as follows:
|
|
1768
|
+
|
|
1769
|
+
- 'playing': start playing, see event [HTMLMediaElement.playing_event](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/playing_event)
|
|
1770
|
+
- 'mute': The audio track cannot provide data temporarily, see event [MediaStreamTrack.mute_event](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/mute_event)
|
|
1771
|
+
- 'unmute': The audio track resumes providing data, see event [MediaStreamTrack.unmute_event](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/unmute_event)
|
|
1772
|
+
- 'ended': The audio track has been closed
|
|
1773
|
+
- 'pause': Playback paused
|
|
1774
|
+
|
|
1775
|
+
##### Example
|
|
1776
|
+
|
|
1777
|
+
```javascript
|
|
1778
|
+
trtc.on(TRTC.EVENT.AUDIO_PLAY_STATE_CHANGED, event => {
|
|
1779
|
+
console.log(`${event.userId} player is ${event.state} because of ${event.reason}`);
|
|
1780
|
+
});
|
|
1781
|
+
```
|
|
1782
|
+
|
|
1783
|
+
#### VIDEO_PLAY_STATE_CHANGED
|
|
1784
|
+
|
|
1785
|
+
**Default Value:** 'video-play-state-changed'
|
|
1786
|
+
|
|
1787
|
+
Video playback state change event
|
|
1788
|
+
|
|
1789
|
+
event.userId When userId is an empty string, it represents the local user, and when it is a non-empty string, it represents a remote user.
|
|
1790
|
+
|
|
1791
|
+
event.streamType Stream type, value: [TRTC.TYPE.STREAM_TYPE_MAIN](module-TYPE.html#.STREAM_TYPE_MAIN) [TRTC.TYPE.STREAM_TYPE_SUB](module-TYPE.html#.STREAM_TYPE_SUB)
|
|
1792
|
+
|
|
1793
|
+
event.state The value is as follows:
|
|
1794
|
+
|
|
1795
|
+
- 'PLAYING': start playing
|
|
1796
|
+
- event.reason is 'playing' or 'unmute'.
|
|
1797
|
+
- 'PAUSED': pause playback
|
|
1798
|
+
- When event.reason is 'pause', it is triggered by the pause event of the <video> element. The following situations will trigger:
|
|
1799
|
+
- Call the HTMLMediaElement.pause interface.
|
|
1800
|
+
- After successful playback, the view container for playing the video is removed from the DOM.
|
|
1801
|
+
- When event.reason is 'mute'. See event [MediaStreamTrack.mute_event](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/mute_event)
|
|
1802
|
+
- When userId is oneself, this event is triggered, indicating that video collection is paused, usually caused by device abnormalities, such as being preempted by other applications on the device, at this time, the user needs to be guided to recollect.
|
|
1803
|
+
- When userId is others, this event is triggered, indicating that the received video data is not enough to play. Usually caused by network jitter, no processing is required on the access side. When the received data is sufficient to play, it will automatically resume.
|
|
1804
|
+
- 'STOPPED': stop playing
|
|
1805
|
+
- event.reason is 'ended'.
|
|
1806
|
+
|
|
1807
|
+
event.reason The reason for the state change, the value is as follows:
|
|
1808
|
+
|
|
1809
|
+
- 'playing': start playing, see event [HTMLMediaElement.playing_event](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/playing_event)
|
|
1810
|
+
- 'mute': The video track cannot provide data temporarily, see event [MediaStreamTrack.mute_event](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/mute_event)
|
|
1811
|
+
- 'unmute': The video track resumes providing data, see event [MediaStreamTrack.unmute_event](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/unmute_event)
|
|
1812
|
+
- 'ended': The video track has been closed
|
|
1813
|
+
- 'pause': Playback paused
|
|
1814
|
+
|
|
1815
|
+
##### Example
|
|
1816
|
+
|
|
1817
|
+
```javascript
|
|
1818
|
+
trtc.on(TRTC.EVENT.VIDEO_PLAY_STATE_CHANGED, event => {
|
|
1819
|
+
console.log(`${event.userId} ${event.streamType} video player is ${event.state} because of ${event.reason}`);
|
|
1820
|
+
});
|
|
1821
|
+
```
|
|
1822
|
+
|
|
1823
|
+
#### SCREEN_SHARE_STOPPED
|
|
1824
|
+
|
|
1825
|
+
**Default Value:** 'screen-share-stopped'
|
|
1826
|
+
|
|
1827
|
+
Notification event for local screen sharing stop, only valid for local screen sharing streams.
|
|
1828
|
+
|
|
1829
|
+
##### Example
|
|
1830
|
+
|
|
1831
|
+
```javascript
|
|
1832
|
+
trtc.on(TRTC.EVENT.SCREEN_SHARE_STOPPED, () => {
|
|
1833
|
+
console.log('screen sharing was stopped');
|
|
1834
|
+
});
|
|
1835
|
+
```
|
|
1836
|
+
|
|
1837
|
+
#### DEVICE_CHANGED
|
|
1838
|
+
|
|
1839
|
+
**Default Value:** 'device-changed'
|
|
1840
|
+
|
|
1841
|
+
Notification event for device changes such as camera and microphone.
|
|
1842
|
+
|
|
1843
|
+
- event.device is a [MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo) object with properties:
|
|
1844
|
+
- deviceId: device ID
|
|
1845
|
+
- label: device description information
|
|
1846
|
+
- groupId: device group ID
|
|
1847
|
+
- event.type value: `'camera'|'microphone'|'speaker'`
|
|
1848
|
+
- event.action value:
|
|
1849
|
+
- 'add' device has been added.
|
|
1850
|
+
- 'remove' device has been removed.
|
|
1851
|
+
- 'active' device has been activated, for example: after startLocalVideo is successful, this event will be triggered.
|
|
1852
|
+
|
|
1853
|
+
##### Example
|
|
1854
|
+
|
|
1855
|
+
```javascript
|
|
1856
|
+
trtc.on(TRTC.EVENT.DEVICE_CHANGED, (event) => {
|
|
1857
|
+
console.log(`${event.type}(${event.device.label}) ${event.action}`);
|
|
1858
|
+
});
|
|
1859
|
+
```
|
|
1860
|
+
|
|
1861
|
+
#### PUBLISH_STATE_CHANGED
|
|
1862
|
+
|
|
1863
|
+
**Default Value:** 'publish-state-changed'
|
|
1864
|
+
|
|
1865
|
+
Publish state change event.
|
|
1866
|
+
|
|
1867
|
+
- event.mediaType media type, value: `'audio'|'video'|'screen'`.
|
|
1868
|
+
- event.state current publish state, value:
|
|
1869
|
+
- `'starting'` trying to publish stream
|
|
1870
|
+
- `'started'` publish stream succeeded
|
|
1871
|
+
- `'stopped'` publish stream stopped, see event.reason field for the reason
|
|
1872
|
+
- event.prevState the publish state at the last event trigger, with the same type as event.state.
|
|
1873
|
+
- event.reason the reason for the publish state to become `'stopped'`, value:
|
|
1874
|
+
- `'timeout'` publish stream timeout, usually caused by network jitter or firewall interception. The SDK will keep retrying, and the business side can guide the user to check the network or change the network at this time.
|
|
1875
|
+
- `'error'` publish stream error, at this time, you can get the specific error information from event.error, usually caused by the browser not supporting H264 encoding.
|
|
1876
|
+
- `'api-call'` publish stream stopped due to business side API call, for example, stopLocalVideo was called to stop the publish stream before startLocalVideo was successful, which is a normal behavior and the business side does not need to pay attention to it.
|
|
1877
|
+
- event.error error information when event.reason is `'error'`.
|
|
1878
|
+
|
|
1879
|
+
##### Example
|
|
1880
|
+
|
|
1881
|
+
```javascript
|
|
1882
|
+
trtc.on(TRTC.EVENT.PUBLISH_STATE_CHANGED, (event) => {
|
|
1883
|
+
console.log(`${event.mediaType} ${event.state} ${event.reason}`);
|
|
1884
|
+
});
|
|
1885
|
+
```
|
|
1886
|
+
|
|
1887
|
+
#### TRACK
|
|
1888
|
+
|
|
1889
|
+
**Since:** v5.3.0
|
|
1890
|
+
|
|
1891
|
+
**Default Value:** 'track'
|
|
1892
|
+
|
|
1893
|
+
a new MediaStreamTrack object received.
|
|
1894
|
+
|
|
1895
|
+
##### Example
|
|
1896
|
+
|
|
1897
|
+
```javascript
|
|
1898
|
+
trtc.on(TRTC.EVENT.TRACK, event => {
|
|
1899
|
+
// userId === '' means event.track is a local track, otherwise it's a remote track
|
|
1900
|
+
const isLocal = event.userId === '';
|
|
1901
|
+
// Usually the sub stream is a screen-sharing video stream.
|
|
1902
|
+
const isSubStream = event.streamType === TRTC.TYPE.STREAM_TYPE_SUB;
|
|
1903
|
+
const mediaStreamTrack = event.track;
|
|
1904
|
+
const kind = event.track.kind; // audio or video
|
|
1905
|
+
})
|
|
1906
|
+
```
|
|
1907
|
+
|
|
1908
|
+
#### STATISTICS
|
|
1909
|
+
|
|
1910
|
+
**Since:** v5.2.0
|
|
1911
|
+
|
|
1912
|
+
**Default Value:** 'statistics'
|
|
1913
|
+
|
|
1914
|
+
TRTC statistics.
|
|
1915
|
+
|
|
1916
|
+
- SDK will fires this event once every 2s.
|
|
1917
|
+
- You can get the network quality, statistics of audio and video from this event. For detailed parameter description, please refer to [TRTCStatistics](global.html#TRTCStatistics).
|
|
1918
|
+
|
|
1919
|
+
##### Example
|
|
1920
|
+
|
|
1921
|
+
```javascript
|
|
1922
|
+
trtc.on(TRTC.EVENT.STATISTICS, statistics => {
|
|
1923
|
+
console.warn(statistics.rtt, statistics.upLoss, statistics.downLoss);
|
|
1924
|
+
})
|
|
1925
|
+
```
|
|
1926
|
+
|
|
1927
|
+
#### SEI_MESSAGE
|
|
1928
|
+
|
|
1929
|
+
**Since:** v5.3.0
|
|
1930
|
+
|
|
1931
|
+
**Default Value:** 'sei-message'
|
|
1932
|
+
|
|
1933
|
+
SEI message received
|
|
1934
|
+
|
|
1935
|
+
##### Example
|
|
1936
|
+
|
|
1937
|
+
```javascript
|
|
1938
|
+
trtc.on(TRTC.EVENT.SEI_MESSAGE, event => {
|
|
1939
|
+
console.log(`received sei message from ${event.userId}, data: ${event.data}, streamType: ${event.streamType}`)
|
|
1940
|
+
})
|
|
1941
|
+
```
|
|
1942
|
+
|
|
1943
|
+
#### CUSTOM_MESSAGE
|
|
1944
|
+
|
|
1945
|
+
**Since:** v5.6.0
|
|
1946
|
+
|
|
1947
|
+
**Default Value:** 'custom-message'
|
|
1948
|
+
|
|
1949
|
+
received a new custom message.
|
|
1950
|
+
|
|
1951
|
+
##### Example
|
|
1952
|
+
|
|
1953
|
+
```javascript
|
|
1954
|
+
trtc.on(TRTC.EVENT.CUSTOM_MESSAGE, event => {
|
|
1955
|
+
// event.userId: remote userId.
|
|
1956
|
+
// event.cmdId: message cmdId.
|
|
1957
|
+
// event.seq: message sequence number.
|
|
1958
|
+
// event.data: custom message data, type is ArrayBuffer.
|
|
1959
|
+
})
|
|
1960
|
+
```
|
|
1961
|
+
|
|
1962
|
+
#### FIRST_VIDEO_FRAME
|
|
1963
|
+
|
|
1964
|
+
**Since:** v5.9.0
|
|
1965
|
+
|
|
1966
|
+
**Default Value:** 'first-video-frame'
|
|
1967
|
+
|
|
1968
|
+
started rendering the first video frame of the local or a remote user.
|
|
1969
|
+
|
|
1970
|
+
##### Example
|
|
1971
|
+
|
|
1972
|
+
```javascript
|
|
1973
|
+
trtc.on(TRTC.EVENT.FIRST_VIDEO_FRAME, event => {
|
|
1974
|
+
// event.height: video height.
|
|
1975
|
+
// event.width: video width.
|
|
1976
|
+
// event.streamType: video stream type.
|
|
1977
|
+
// event.userId: The user ID of the local or a remote user. If it is empty, it indicates that the first local video frame is available; if it is not empty, it indicates that the first video frame of a remote user is available.
|
|
1978
|
+
})
|
|
1979
|
+
```
|
|
1980
|
+
|
|
1981
|
+
#### PERMISSION_STATE_CHANGE
|
|
1982
|
+
|
|
1983
|
+
**Since:** v5.13.0
|
|
1984
|
+
|
|
1985
|
+
**Default Value:** 'permission-state-change'
|
|
1986
|
+
|
|
1987
|
+
Permission state change event
|
|
1988
|
+
|
|
1989
|
+
##### Example
|
|
1990
|
+
|
|
1991
|
+
```javascript
|
|
1992
|
+
trtc.on(TRTC.EVENT.PERMISSION_STATE_CHANGE, event => {
|
|
1993
|
+
// event.camera: camera permission state.
|
|
1994
|
+
// event.microphone: microphone permission state.
|
|
1995
|
+
})
|
|
1996
|
+
```
|
|
1997
|
+
|
|
1998
|
+
#### VIDEO_SIZE_CHANGED
|
|
1999
|
+
|
|
2000
|
+
**Since:** v5.13.0
|
|
2001
|
+
|
|
2002
|
+
**Default Value:** 'video-size-changed'
|
|
2003
|
+
|
|
2004
|
+
Video size changed event
|
|
2005
|
+
|
|
2006
|
+
##### Example
|
|
2007
|
+
|
|
2008
|
+
```javascript
|
|
2009
|
+
trtc.on(TRTC.EVENT.VIDEO_SIZE_CHANGED, event => {
|
|
2010
|
+
// event.newHeight: video height.
|
|
2011
|
+
// event.newWidth: video width.
|
|
2012
|
+
// event.streamType: video stream type.
|
|
2013
|
+
// event.userId: The user ID of the local or a remote user. If it is empty, it indicates that video is the local video and the local user has not entered the room; if it is not empty, it indicates that video is remote video or local user enter room already.
|
|
2014
|
+
})
|
|
2015
|
+
```
|
|
2016
|
+
|
|
2017
|
+
### Type Definitions
|
|
2018
|
+
|
|
2019
|
+
#### EnableAudioFrameEventOptions
|
|
2020
|
+
|
|
2021
|
+
**Properties:**
|
|
2022
|
+
|
|
2023
|
+
| Name | Type | Attributes | Default | Description |
|
|
2024
|
+
|------|------|------------|---------|-------------|
|
|
2025
|
+
| enable | boolean | | | Whether to enable callback of audio frame |
|
|
2026
|
+
| userId | string | | | The userId of the monitored user. '' indicates local microphone data, '*' indicates monitoring the audio data of all remote users. |
|
|
2027
|
+
| sampleRate | number | optional | 48000 | Set the sampling rate of pcm data, the default is 48000. Support 8000, 16000, 32000, 44100, 48000 |
|
|
2028
|
+
| channelCount | number | optional | 1 | Set the number of channels of pcm data, the default is 1. Support 1, 2 |
|
|
2029
|
+
| port | MessagePort | optional | | Set the MessagePort for the pcm callback |
|
|
2030
|
+
|
|
2031
|
+
enableAudioFrameEvent Options
|
|
2032
|
+
|
|
2033
|
+
## ERROR_CODE
|
|
2034
|
+
|
|
2035
|
+
TRTC SDK v5.0 defines 8 types of error codes, and handles them through the RtcError object.
|
|
2036
|
+
|
|
2037
|
+
**See:**
|
|
2038
|
+
- [RtcError](RtcError.html)
|
|
2039
|
+
- [TRTC.EVENT.ERROR](module-EVENT.html#.ERROR)
|
|
2040
|
+
|
|
2041
|
+
### Example
|
|
2042
|
+
|
|
2043
|
+
```javascript
|
|
2044
|
+
// Usage:
|
|
2045
|
+
// 1. API call error
|
|
2046
|
+
trtc.startLocalVideo().catch(error => {
|
|
2047
|
+
if (error.code === TRTC.ERROR_CODE.DEVICE_ERROR) {}
|
|
2048
|
+
});
|
|
2049
|
+
// 2. Non-API call error, the error that the SDK cannot recover after internal retry
|
|
2050
|
+
trtc.on(TRTC.EVENT.ERROR, (error) => {
|
|
2051
|
+
if (error.code === TRTC.ERROR_CODE.OPERATION_FAILED) {}
|
|
2052
|
+
});
|
|
2053
|
+
```
|
|
2054
|
+
|
|
2055
|
+
### Members
|
|
2056
|
+
|
|
2057
|
+
#### INVALID_PARAMETER
|
|
2058
|
+
|
|
2059
|
+
**Default Value:** `5000`
|
|
2060
|
+
|
|
2061
|
+
**Description:** The parameters passed in when calling the interface do not meet the API requirements.
|
|
2062
|
+
|
|
2063
|
+
**Handling suggestion:** Please check whether the passed-in parameters comply with the API specifications, such as whether the parameter type is correct.
|
|
2064
|
+
|
|
2065
|
+
| extraCode | Description |
|
|
2066
|
+
|-----------|-------------|
|
|
2067
|
+
| 5001 | The required parameter is not passed in |
|
|
2068
|
+
| 5002 | The parameter type is incorrect |
|
|
2069
|
+
| 5003 | The parameter is empty |
|
|
2070
|
+
| 5004 | The parameter instance is incorrect |
|
|
2071
|
+
| 5005 | The parameter value is out of range |
|
|
2072
|
+
| 5006 | The parameter value is less than 0 |
|
|
2073
|
+
| 5007 | The parameter value is less than the minimum value |
|
|
2074
|
+
| 5008 | The parameter value is greater than the maximum value |
|
|
2075
|
+
| 5009 | The elementId cannot be found on the page or was not found on the page when searching |
|
|
2076
|
+
| 5010 | The parameter passed in is not of type HTMLElement |
|
|
2077
|
+
| 5011 | streamId does not meet the specifications |
|
|
2078
|
+
| 5012 | The range of the incoming roomId does not comply with the specifications [1, 4294967294] |
|
|
2079
|
+
| 5013 | The strRoomId type passed in is not a legal string |
|
|
2080
|
+
| 5014 | When the userId is not '*', a streamType needs to be passed in |
|
|
2081
|
+
| 5015 | roomId or strRoomId not passed in, one of them must be passed in |
|
|
2082
|
+
| 5016 | roomId must be a numeric type. Currently, a string type has been passed in. If you need to use a string as the room id, please use strRoomId |
|
|
2083
|
+
| 5017 | The size of arraybuffer cannot be empty. Thrown from [TRTC.sendSEIMessage](TRTC.html#sendSEIMessage), [TRTC.sendCustomMessage](TRTC.html#sendCustomMessage) |
|
|
2084
|
+
| 5018 | The arraybuffer is oversize. Thrown from [TRTC.sendSEIMessage](TRTC.html#sendSEIMessage), [TRTC.sendCustomMessage](TRTC.html#sendCustomMessage) |
|
|
2085
|
+
|
|
2086
|
+
#### INVALID_OPERATION
|
|
2087
|
+
|
|
2088
|
+
**Default Value:** `5100`
|
|
2089
|
+
|
|
2090
|
+
**Description:** The prerequisite requirements of the API are not met when calling the interface.
|
|
2091
|
+
|
|
2092
|
+
**Handling suggestion:** Please check whether the calling logic complies with the API prerequisite requirements according to the corresponding API document. For example: 1. Switching roles before entering the room successfully, 2. The remote user and stream being played do not exist.
|
|
2093
|
+
|
|
2094
|
+
| extraCode | Description |
|
|
2095
|
+
|-----------|-------------|
|
|
2096
|
+
| 5101 | The API is called without entering the room, such as startRemoteVideo muteRemoteAudio switchRole and other APIs need to be called after entering the room |
|
|
2097
|
+
| 5102 | The remote user does not exist, for example, when startRemoteVideo is called, the userId passed in corresponds to a remote user who is not in the room. |
|
|
2098
|
+
| 5103 | The remote stream type does not exist, for example, when startRemoteVideo is called, streamType = TRTC.TYPE.STREAM_TYPE.SUB is passed in, but the corresponding remote user does not share the screen. |
|
|
2099
|
+
| 5104 | Repeatedly calling the API, for example, after entering the room successfully, enterRoom interface is called again. |
|
|
2100
|
+
| 5105 | Calling the API without the camera being enabled. For example, virtual background plugins require the camera to be enabled for use. |
|
|
2101
|
+
| 5106 | Calling the API without the microphone being enabled. For example, AI noise reduction plugins require the microphone to be enabled for use. |
|
|
2102
|
+
| 5107 | Role [TRTC.TYPE.ROLE_AUDIENCE](module-TYPE.html#.ROLE_AUDIENCE) cannot call this api. |
|
|
2103
|
+
| 5108 | You should enable SEI by TRTC.create({ enableSEI: true }) |
|
|
2104
|
+
| 5109 | You need to publish video before sendSEIMessage |
|
|
2105
|
+
|
|
2106
|
+
#### ENV_NOT_SUPPORTED
|
|
2107
|
+
|
|
2108
|
+
**Default Value:** `5200`
|
|
2109
|
+
|
|
2110
|
+
**Description:** The current environment does not support this function, indicating that the current browser does not support calling the corresponding API.
|
|
2111
|
+
|
|
2112
|
+
**Handling suggestion:** Usually, TRTC.isSupported can be used to perceive which capabilities the current browser supports. If the browser does not support it, you need to guide the user to use a browser that supports this capability. Reference: [Check Environment and Device Before Calls](tutorial-23-advanced-support-detection.html)
|
|
2113
|
+
|
|
2114
|
+
| extraCode | Description |
|
|
2115
|
+
|-----------|-------------|
|
|
2116
|
+
| 5201 | The current page protocol is not HTTPS, and the audio and video capture (pushing, linking) capabilities are not supported |
|
|
2117
|
+
| 5202 | The current browser does not support WebRTC capabilities, the browser version is too low, or |
|
|
2118
|
+
| 5203 | The browser does not support H264 encoding capability |
|
|
2119
|
+
| 5204 | The browser does not support H264 decoding capability |
|
|
2120
|
+
| 5205 | The browser does not support screen sharing capability |
|
|
2121
|
+
| 5206 | The browser does not support small stream encoding capability |
|
|
2122
|
+
| 5207 | The browser does not support SEI receiving and sending capabilities |
|
|
2123
|
+
| 5208 | The browser does not support WebGL. |
|
|
2124
|
+
| 5209 | The current version of the browser does not support this feature. Please upgrade to the latest version. |
|
|
2125
|
+
| 5210 | The current version of the browser does not support this plugin. Please upgrade to the latest version. |
|
|
2126
|
+
|
|
2127
|
+
#### DEVICE_ERROR
|
|
2128
|
+
|
|
2129
|
+
**Default Value:** `5300`
|
|
2130
|
+
|
|
2131
|
+
**Description:** Exception occurred when obtaining device or capturing microphone/camera/screen sharing.
|
|
2132
|
+
|
|
2133
|
+
The following API will throw this error code when an exception occurs: [trtc.startLocalAudio](TRTC.html#startLocalAudio) [trtc.startLocalVideo](TRTC.html#startLocalVideo) [trtc.startScreenShare](TRTC.html#startScreenShare)
|
|
2134
|
+
|
|
2135
|
+
**Suggestion:** Guide the user to check whether the device has a camera and microphone, whether the system has authorized the browser, and whether the browser has authorized the page. It is recommended to increase the device detection process before entering the room to confirm whether the microphone and camera exist and can be captured normally before proceeding to the next call operation. Usually, this exception can be avoided after the device check. [Check Environment and Device Before Calls](tutorial-23-advanced-support-detection.html)
|
|
2136
|
+
|
|
2137
|
+
If you need to distinguish more detailed exception categories, you can process according to the following extraCode:
|
|
2138
|
+
|
|
2139
|
+
| extraCode | Description |
|
|
2140
|
+
|-----------|-------------|
|
|
2141
|
+
| 5301 | NotFoundError(DOMException) thrown by the browser <br> Reason: The media device type that meets the request parameters cannot be found (including: audio, video, screen sharing). For example: The PC does not have a camera, but the browser is requested to obtain a video stream, which will report this error. <br> Suggestion: It is recommended to guide users to check the camera or microphone and other external devices required for the call before the call. |
|
|
2142
|
+
| 5302 | NotAllowedError(DOMException) thrown by the browser <br> Reason: <li>The user refused the microphone, camera, and screen sharing requests of the current browser instance.</li><li>The permission of camera/microphone/screen sharing has been denied by system.</li><br> Suggestion: <li>Prompt the user to authorize the camera/microphone access before audio and video calls can be made.</li><li>If the browser permission is denied by the system, rtcError will have rtcError.handler method, which can be called to jump to the System Permission Setting APP, so as to facilitate the user to open the permission.</li> |
|
|
2143
|
+
| 5303 | NotReadableError(DOMException) thrown by the browser <br> Reason: Although the user has authorized the use of the corresponding device, due to errors that occurred on some hardware, browser, or webpage levels on the operating system, or other applications occupying the device, the device cannot be accessed by the browser.<br> Suggestion: Handle according to the browser's error message, and prompt the user: "Unable to access the camera/microphone temporarily, please ensure that there are no other applications requesting access to the camera/microphone, and try again" |
|
|
2144
|
+
| 5303 | NotReadableError(DOMException) thrown by the browser <br> Reason: Although the user has authorized the use of the corresponding device, due to errors that occurred on some hardware, browser, or webpage levels on the operating system, or other applications occupying the device, the device cannot be accessed by the browser.<br> Suggestion: 1-If this problem occurs with Windows Camera, the user will be directed to check whether the device is occupied. Only the camera of Windows system will be exclusive, but the microphone will not be exclusive. 2-If this error occurs with the microphone and camera of other systems, the user will be directed to check whether the device is normal or try to restart the browser. |
|
|
2145
|
+
| 5304 | OverconstrainedError(DOMException) thrown by the browser <br> Reason: The value of the cameraId/microphoneId parameter is invalid <br> Suggestion: Check whether cameraId/microphoneId is the value returned by the device information acquisition interface |
|
|
2146
|
+
| 5305 | InvalidStateError(DOMException) thrown by the browser <br> Reason: The current page has not generated interaction, and the page is not fully activated <br> Suggestion: It is recommended to turn on the camera and microphone after the user has clicked on the page to generate interaction |
|
|
2147
|
+
| 5306 | SecurityError(DOMException) thrown by the browser <br> Reason: The system security policy prohibits the use of the device<br> Suggestion: Check whether the system restricts the use of the device, and recommend turning on the camera and microphone after the user clicks on the page to generate interaction |
|
|
2148
|
+
| 5307 | AbortError(DOMException) thrown by the browser <br> Reason: The device cannot be used due to some unknown reasons <br> Suggestion: It is recommended to replace the device or browser, and recheck whether the device is normal |
|
|
2149
|
+
| 5308 | Camera capture exception, after SDK retry, the capture cannot be restored. <br> Reason: Camera exception or the user manually closes the capture permission of the browser <br> Suggestion: Prompt the user that the camera capture is abnormal, and guide the user to check whether the camera is normal and whether there is a capture permission |
|
|
2150
|
+
| 5309 | Microphone capture exception, after SDK retry, the capture cannot be restored. <br> Reason: Microphone exception or the user manually closes the capture permission of the browser <br> Suggestion: Prompt the user that the microphone capture is abnormal, and guide the user to check whether the microphone is normal and whether there is a capture permission |
|
|
2151
|
+
|
|
2152
|
+
**Reference:** [getUserMedia exception](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#%E5%BC%82%E5%B8%B8) and [getDisplayMedia exception](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia#%E5%BC%82%E5%B8%B8)
|
|
2153
|
+
|
|
2154
|
+
##### Example
|
|
2155
|
+
|
|
2156
|
+
```javascript
|
|
2157
|
+
trtc.startLocalVideo(...).catch(function(rtcError) {
|
|
2158
|
+
if(rtcError.code == TRTC.ERROR_CODE.DEVICE_ERROR) {
|
|
2159
|
+
// Guide the user to check the device
|
|
2160
|
+
switch(rtcError.extraCode) {
|
|
2161
|
+
case 5301:
|
|
2162
|
+
// Can't find a camera or microphone, guide the user to check if the microphone and camera are working.
|
|
2163
|
+
break;
|
|
2164
|
+
case 5302:
|
|
2165
|
+
if (error.handler) {
|
|
2166
|
+
// Prompt the user the browser permission(camera/microphone/screen sharing) has been denied by system. The browser will jump to the System Settings APP, please enable the relevant permissions!
|
|
2167
|
+
} else {
|
|
2168
|
+
// Prompt the user to allow camera, microphone, and screen share capture permissions on the page.
|
|
2169
|
+
}
|
|
2170
|
+
break;
|
|
2171
|
+
// ...
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
})
|
|
2175
|
+
```
|
|
2176
|
+
|
|
2177
|
+
#### SERVER_ERROR
|
|
2178
|
+
|
|
2179
|
+
**Default Value:** `5400`
|
|
2180
|
+
|
|
2181
|
+
**Description:** This error code is thrown when abnormal data is returned from the server.
|
|
2182
|
+
|
|
2183
|
+
The following interfaces will throw this error code when an exception occurs: `enterRoom`, `startLocalVideo`, `startLocalAudio`, `startScreenShare`, `startRemoteVideo`, `switchRole`
|
|
2184
|
+
|
|
2185
|
+
**Handling suggestion:** Server exceptions are usually handled during development. Common exceptions include: expired userSig, Tencent Cloud account arrears, TRTC service not enabled, etc. The server returns abnormal data for the following reasons.
|
|
2186
|
+
|
|
2187
|
+
| extraCode | Description |
|
|
2188
|
+
|-----------|-------------|
|
|
2189
|
+
| 5401 | The feature requires a purchase of a package. |
|
|
2190
|
+
| -8 | Incorrect sdkAppId, please check if sdkAppId is correctly filled in |
|
|
2191
|
+
| -10012 | roomId is not passed in or roomId does not meet the specifications. If you need to use the string type roomId, please use strRoomId instead when calling trtc.enterRoom |
|
|
2192
|
+
| -10015 | Failed to obtain server node |
|
|
2193
|
+
| -10016 | Server internal communication timeout, timeout is 3s |
|
|
2194
|
+
| -10035 | Server switch room failed |
|
|
2195
|
+
| -10037 | The anchor role does not support switching the room |
|
|
2196
|
+
| -100006 | Failed to check permissions. After enabling advanced permission control, please check whether the privateMapKey parameter carried by [enterRoom](TRTC.html#enterRoom) is correct. Please see [Enable advanced permission settings](https://trtc.io/document/35157?product=rtcengine) |
|
|
2197
|
+
| -100013 | Customer service arrears, please log in to the [TRTC Console](https://console.trtc.io/), click the application you created, click [Account Information], and you can confirm the service status in the account information panel |
|
|
2198
|
+
| -100021 | Server overload, failed to enter the room |
|
|
2199
|
+
| -100022 | Server allocation failed |
|
|
2200
|
+
| -100024 | Failed to enter the room due to TRTC service not enabled. Please go to the [IM Console](https://console.intl.cloud.tencent.com/im) to enable TRTC service for your application |
|
|
2201
|
+
| -102006 | Flow control defined error code (add user failed) |
|
|
2202
|
+
| -102010 | After enabling advanced permission control, the user does not have the permission to create a room. Please see [Enable advanced permission settings](https://trtc.io/document/35157?product=rtcengine) |
|
|
2203
|
+
| -102023 | Request parameter error (request parameter error generated by the backend interface service) |
|
|
2204
|
+
| 70001 | userSig expired, please try to regenerate. If it expires just after generation, please check whether the validity period is too small or mistakenly filled in as 0 |
|
|
2205
|
+
| 70002 | userSig length is 0, please confirm whether the signature calculation is correct, access sign_src to get the idiotic source code of the calculation signature, check the parameters, and ensure the correctness of the signature calculation |
|
|
2206
|
+
| 70003 | userSig verification failed, please confirm whether the userSig content is truncated, such as content truncation caused by insufficient buffer length |
|
|
2207
|
+
| 70004 | userSig verification failed, please confirm whether the userSig content is truncated, such as content truncation caused by insufficient buffer length |
|
|
2208
|
+
| 70005 | userSig verification failed, use tools to verify whether the generated userSig is correct |
|
|
2209
|
+
| 70006 | userSig verification failed, use tools to verify whether the generated userSig is correct |
|
|
2210
|
+
| 70007 | userSig verification failed, use tools to verify whether the generated userSig is correct |
|
|
2211
|
+
| 70008 | userSig verification failed, use tools to verify whether the generated userSig is correct |
|
|
2212
|
+
| 70009 | Failed to verify userSig with business public key, please confirm whether the userSig used for generation corresponds to the private key and sdkAppId |
|
|
2213
|
+
| 70010 | userSig verification failed, use tools to verify whether the generated userSig is correct |
|
|
2214
|
+
| 70013 | userId in userSig does not match the userId filled in when requesting, please check whether the userId filled in when logging in is consistent with that in userSig |
|
|
2215
|
+
| 70014 | sdkAppId in userSig does not match the sdkAppId filled in when requesting, please check whether the sdkAppId filled in when logging in is consistent with that in userSig |
|
|
2216
|
+
| 70015 | No verification method corresponding to the sdkAppId and account type was found. Please confirm whether the account integration operation has been performed |
|
|
2217
|
+
| 70016 | The length of the pulled public key is 0. Please confirm whether the public key has been uploaded. If the public key is re-uploaded, please try again after ten minutes. |
|
|
2218
|
+
| 70017 | Internal third-party ticket verification timed out. Please try again. If multiple retries are unsuccessful, please contact TLS account support, QQ: 3268519604. |
|
|
2219
|
+
| 70018 | Internal verification of third-party tickets failed. |
|
|
2220
|
+
| 70019 | The ticket field verified by HTTPS is empty. Please fill in userSig correctly. |
|
|
2221
|
+
| 70020 | sdkAppId not found. Please confirm whether it has been configured on Tencent Cloud. |
|
|
2222
|
+
| 70052 | userSig has expired. Please regenerate and try again. |
|
|
2223
|
+
| 70101 | Request packet information is empty. |
|
|
2224
|
+
| 70102 | Account type in request packet is incorrect. |
|
|
2225
|
+
| 70103 | Phone number format is incorrect. |
|
|
2226
|
+
| 70104 | Email format is incorrect. |
|
|
2227
|
+
| 70105 | TLS account format is incorrect. |
|
|
2228
|
+
| 70106 | Illegal account format type. |
|
|
2229
|
+
| 70107 | userId is not registered. |
|
|
2230
|
+
| 70113 | Batch quantity is invalid. |
|
|
2231
|
+
| 70114 | Restricted for security reasons. |
|
|
2232
|
+
| 70115 | uin is not the developer uin corresponding to sdkAppId. |
|
|
2233
|
+
| 70140 | sdkAppId and acctype do not match. |
|
|
2234
|
+
| 70145 | Account type is incorrect. |
|
|
2235
|
+
| 70169 | Internal error. Please try again. If multiple retries are unsuccessful, please contact TLS account support, QQ: 3268519604. |
|
|
2236
|
+
| 70201 | Internal error. Please try again. If multiple retries are unsuccessful, please contact TLS account support, QQ: 3268519604. |
|
|
2237
|
+
| 70202 | Internal error. Please try again. If multiple retries are unsuccessful, please contact TLS account support, QQ: 3268519604. |
|
|
2238
|
+
| 70203 | Internal error. Please try again. If multiple retries are unsuccessful, please contact TLS account support, QQ: 3268519604. |
|
|
2239
|
+
| 70204 | sdkAppId does not have a corresponding acctype. |
|
|
2240
|
+
| 70205 | Failed to find acctype. Please try again. |
|
|
2241
|
+
| 70206 | Batch quantity in request is invalid. |
|
|
2242
|
+
| 70207 | Internal error. Please try again. |
|
|
2243
|
+
| 70208 | Internal error. Please try again. |
|
|
2244
|
+
| 70209 | Failed to obtain developer uin flag. |
|
|
2245
|
+
| 70210 | uin in request is not a developer uin. |
|
|
2246
|
+
| 70211 | uin in request is illegal. |
|
|
2247
|
+
| 70212 | Internal error. Please try again. If multiple retries are unsuccessful, please contact TLS account support, QQ: 3268519604. |
|
|
2248
|
+
| 70213 | Failed to access internal data. Please try again. If multiple retries are unsuccessful, please contact TLS account support, QQ: 3268519604. |
|
|
2249
|
+
| 70214 | Failed to verify internal ticket. |
|
|
2250
|
+
| 70221 | Invalid login status, please re-authenticate with UserSig. |
|
|
2251
|
+
| 70222 | Internal error, please try again. |
|
|
2252
|
+
| 70225 | Internal error, please try again. If multiple retries are unsuccessful, please contact TLS account support, QQ: 3268519604. |
|
|
2253
|
+
| 70231 | Internal error, please try again. If multiple retries are unsuccessful, please contact TLS account support, QQ: 3268519604. |
|
|
2254
|
+
| 70236 | Failed to verify user signature. |
|
|
2255
|
+
| 70308 | Internal error, please try again. If multiple retries are unsuccessful, please contact TLS account support, QQ: 3268519604. |
|
|
2256
|
+
| 70346 | Ticket verification failed. |
|
|
2257
|
+
| 70347 | Ticket verification failed due to expiration. |
|
|
2258
|
+
| 70348 | Internal error, please try again. If multiple retries are unsuccessful, please contact TLS account support, QQ: 3268519604. |
|
|
2259
|
+
| 70362 | Internal timeout, please try again. If multiple retries are unsuccessful, please contact TLS account support, QQ: 3268519604. |
|
|
2260
|
+
| 70401 | Internal error, please try again. |
|
|
2261
|
+
| 70402 | Invalid parameter. Please check if the required fields are filled in and if the filling meets the protocol requirements. |
|
|
2262
|
+
| 70403 | The initiator is not an App administrator and does not have permission to operate. |
|
|
2263
|
+
| 70050 | Limited due to failure and too many retries. Please check if the ticket is correct and try again in one minute. |
|
|
2264
|
+
| 70051 | The account has been blacklisted. Please contact TLS account support, QQ: 3268519604. |
|
|
2265
|
+
|
|
2266
|
+
#### OPERATION_FAILED
|
|
2267
|
+
|
|
2268
|
+
**Default Value:** `5500`
|
|
2269
|
+
|
|
2270
|
+
**Description:** The exception that the SDK cannot solve after multiple retries under the condition of meeting the API call requirements, usually caused by browser or network problems.
|
|
2271
|
+
|
|
2272
|
+
The following interfaces will throw this error code when an exception occurs: `enterRoom`, `startLocalVideo`, `startLocalAudio`, `startScreenShare`, `startRemoteVideo`, `switchRole`
|
|
2273
|
+
|
|
2274
|
+
**Handling suggestions:**
|
|
2275
|
+
- Confirm whether the domain name and port required for communication meet your network environment requirements, refer to the document [Handle Firewall Restriction](tutorial-34-advanced-proxy.html)
|
|
2276
|
+
- Other issues need to be handled by engineers. [Contact us on telegram](https://t.me/+EPk6TMZEZMM5OGY1)
|
|
2277
|
+
|
|
2278
|
+
| extraCode | Description |
|
|
2279
|
+
|-----------|-------------|
|
|
2280
|
+
| 5501 | Firewall restriction: After multiple retries, the SDK still cannot establish a media connection, which will cause streaming and pulling to fail. <br />Handling suggestions: Refer to the tutorial [Handle Firewall Restriction](tutorial-34-advanced-proxy.html) |
|
|
2281
|
+
| 5502 | Re-entering the room failed: When the user experiences a network outage of more than 30s, the SDK will try to re-enter the room to restore the call, but the re-entry may fail due to the expiration of userSig, and this error will be thrown.<br />Handling suggestions: When encountering this error, you can use the latest userSig to call [TRTC.enterRoom](TRTC.html#enterRoom) to enter the room again |
|
|
2282
|
+
| 5503 | Re-entering the room failed: When the user experiences a network outage of more than 30s, the SDK will try to re-enter the room to restore the call, but the re-entry may fail due to the expiration of userSig, and this error will be thrown.<br />Handling suggestions: When encountering this error, you can use the latest userSig to call [TRTC.enterRoom](TRTC.html#enterRoom) to enter the room again |
|
|
2283
|
+
| 5505 | Video encoding failed. Usually, the device does not support h264 encoding. <br />Solution: Android devices from some manufacturers do not have H264 encoding capabilities (i.e., they cannot push streams). If you want to use the TRTC Web SDK to push streams in the browsers of these devices, please submit [Web SDK User Capability Support Application](https://console.tencentcloud.com/workorder/category) to enable VP8 encoding and decoding capabilities. |
|
|
2284
|
+
| 5506 | Audio encoding failed. <br />Solution: When encountering this error, you can upgrade to the latest SDK version, or prompt the user to upgrade to the latest system version. |
|
|
2285
|
+
| 5507 | Video decoding failed. Usually, the device does not support h264 decoding. <br />Solution: Refer to the solution for video encoding failure. |
|
|
2286
|
+
| 5508 | Audio decoding failed. <br />Solution: When encountering this error, you can upgrade to the latest SDK version, or prompt the user to upgrade to the latest system version. |
|
|
2287
|
+
|
|
2288
|
+
#### OPERATION_ABORT
|
|
2289
|
+
|
|
2290
|
+
**Default Value:** `5998`
|
|
2291
|
+
|
|
2292
|
+
**Description:** The error code thrown when the API execution is aborted. When the API is called or repeatedly called without meeting the API lifecycle, the API will abort execution to avoid meaningless operations. <br>For example: Call enterRoom, startLocalXxx and other interfaces continuously, and call exitRoom without entering the room.<br>
|
|
2293
|
+
|
|
2294
|
+
The following interfaces will throw this error code when an exception occurs: `enterRoom`, `startLocalVideo`, `startLocalAudio`, `startScreenShare`, `startRemoteVideo`, `switchRole`
|
|
2295
|
+
|
|
2296
|
+
**Handling suggestions:** Capture and identify this error code, then avoid unnecessary calls in business logic, or you can do nothing, because the SDK has done side-effect-free processing, you only need to identify and ignore this error code when catching it.
|
|
2297
|
+
|
|
2298
|
+
#### UNKNOWN_ERROR
|
|
2299
|
+
|
|
2300
|
+
**Default Value:** `5999`
|
|
2301
|
+
|
|
2302
|
+
**Description:** Unknown error or undefined error
|
|
2303
|
+
|
|
2304
|
+
**Handling suggestions:** [Contact us on telegram](https://t.me/+EPk6TMZEZMM5OGY1)
|
|
2305
|
+
|
|
2306
|
+
## TYPE
|
|
2307
|
+
|
|
2308
|
+
**TRTC Constants**
|
|
2309
|
+
|
|
2310
|
+
### Example
|
|
2311
|
+
|
|
2312
|
+
```javascript
|
|
2313
|
+
// Usage:
|
|
2314
|
+
TRTC.TYPE.SCENE_LIVE
|
|
2315
|
+
```
|
|
2316
|
+
|
|
2317
|
+
### Members
|
|
2318
|
+
|
|
2319
|
+
#### SCENE_LIVE
|
|
2320
|
+
|
|
2321
|
+
**Default Value:** `'live'`
|
|
2322
|
+
|
|
2323
|
+
Live streaming scene
|
|
2324
|
+
|
|
2325
|
+
#### SCENE_RTC
|
|
2326
|
+
|
|
2327
|
+
**Default Value:** `'rtc'`
|
|
2328
|
+
|
|
2329
|
+
RTC scene
|
|
2330
|
+
|
|
2331
|
+
#### ROLE_ANCHOR
|
|
2332
|
+
|
|
2333
|
+
**Default Value:** `'anchor'`
|
|
2334
|
+
|
|
2335
|
+
Anchor role
|
|
2336
|
+
|
|
2337
|
+
#### ROLE_AUDIENCE
|
|
2338
|
+
|
|
2339
|
+
**Default Value:** `'audience'`
|
|
2340
|
+
|
|
2341
|
+
Audience role
|
|
2342
|
+
|
|
2343
|
+
#### STREAM_TYPE_MAIN
|
|
2344
|
+
|
|
2345
|
+
**Default Value:** `'main'`
|
|
2346
|
+
|
|
2347
|
+
Main stream
|
|
2348
|
+
|
|
2349
|
+
- TRTC has a main video stream (main stream) and an sub video stream (sub stream)
|
|
2350
|
+
- The camera is published through the main stream, and the screen sharing is published through the sub stream.
|
|
2351
|
+
- The main video stream includes: high-definition large picture and low-definition small picture. By default, [TRTC.startRemoteVideo](TRTC.html#startRemoteVideo) plays the high-definition large picture, and the low-definition small picture can be played through the small parameter. Refer to: [Enable small stream function](./tutorial-27-advanced-small-stream.html).
|
|
2352
|
+
|
|
2353
|
+
#### STREAM_TYPE_SUB
|
|
2354
|
+
|
|
2355
|
+
**Default Value:** `'sub'`
|
|
2356
|
+
|
|
2357
|
+
Sub stream
|
|
2358
|
+
|
|
2359
|
+
#### AUDIO_PROFILE_STANDARD
|
|
2360
|
+
|
|
2361
|
+
**Default Value:** `'standard'`
|
|
2362
|
+
|
|
2363
|
+
Standard audio quality
|
|
2364
|
+
|
|
2365
|
+
| Audio Profile | Sampling Rate | Channel | Bitrate (kbps) |
|
|
2366
|
+
|---------------|---------------|---------|----------------|
|
|
2367
|
+
| TRTC.TYPE.AUDIO_PROFILE_STANDARD | 48000 | Mono | 40 |
|
|
2368
|
+
| TRTC.TYPE.AUDIO_PROFILE_HIGH | 48000 | Mono | 128 |
|
|
2369
|
+
| TRTC.TYPE.AUDIO_PROFILE_STANDARD_STEREO | 48000 | Stereo | 64 |
|
|
2370
|
+
| TRTC.TYPE.AUDIO_PROFILE_HIGH_STEREO | 48000 | Stereo | 192 |
|
|
2371
|
+
|
|
2372
|
+
#### AUDIO_PROFILE_STANDARD_STEREO
|
|
2373
|
+
|
|
2374
|
+
**Default Value:** `'standard-stereo'`
|
|
2375
|
+
|
|
2376
|
+
Standard stereo audio quality
|
|
2377
|
+
|
|
2378
|
+
| Audio Profile | Sampling Rate | Channel | Bitrate (kbps) |
|
|
2379
|
+
|---------------|---------------|---------|----------------|
|
|
2380
|
+
| TRTC.TYPE.AUDIO_PROFILE_STANDARD | 48000 | Mono | 40 |
|
|
2381
|
+
| TRTC.TYPE.AUDIO_PROFILE_HIGH | 48000 | Mono | 128 |
|
|
2382
|
+
| TRTC.TYPE.AUDIO_PROFILE_STANDARD_STEREO | 48000 | Stereo | 64 |
|
|
2383
|
+
| TRTC.TYPE.AUDIO_PROFILE_HIGH_STEREO | 48000 | Stereo | 192 |
|
|
2384
|
+
|
|
2385
|
+
#### AUDIO_PROFILE_HIGH
|
|
2386
|
+
|
|
2387
|
+
**Default Value:** `'high'`
|
|
2388
|
+
|
|
2389
|
+
High audio quality
|
|
2390
|
+
|
|
2391
|
+
| Audio Profile | Sampling Rate | Channel | Bitrate (kbps) |
|
|
2392
|
+
|---------------|---------------|---------|----------------|
|
|
2393
|
+
| TRTC.TYPE.AUDIO_PROFILE_STANDARD | 48000 | Mono | 40 |
|
|
2394
|
+
| TRTC.TYPE.AUDIO_PROFILE_HIGH | 48000 | Mono | 128 |
|
|
2395
|
+
| TRTC.TYPE.AUDIO_PROFILE_STANDARD_STEREO | 48000 | Stereo | 64 |
|
|
2396
|
+
| TRTC.TYPE.AUDIO_PROFILE_HIGH_STEREO | 48000 | Stereo | 192 |
|
|
2397
|
+
|
|
2398
|
+
#### AUDIO_PROFILE_HIGH_STEREO
|
|
2399
|
+
|
|
2400
|
+
**Default Value:** `'high-stereo'`
|
|
2401
|
+
|
|
2402
|
+
High-quality stereo audio
|
|
2403
|
+
|
|
2404
|
+
| Audio Profile | Sampling Rate | Channel | Bitrate (kbps) |
|
|
2405
|
+
|---------------|---------------|---------|----------------|
|
|
2406
|
+
| TRTC.TYPE.AUDIO_PROFILE_STANDARD | 48000 | Mono | 40 |
|
|
2407
|
+
| TRTC.TYPE.AUDIO_PROFILE_HIGH | 48000 | Mono | 128 |
|
|
2408
|
+
| TRTC.TYPE.AUDIO_PROFILE_STANDARD_STEREO | 48000 | Stereo | 64 |
|
|
2409
|
+
| TRTC.TYPE.AUDIO_PROFILE_HIGH_STEREO | 48000 | Stereo | 192 |
|
|
2410
|
+
|
|
2411
|
+
#### QOS_PREFERENCE_SMOOTH
|
|
2412
|
+
|
|
2413
|
+
**Default Value:** `'smooth'`
|
|
2414
|
+
|
|
2415
|
+
When the network is weak, the video encoding strategy takes 'smooth' first, i.e., the priority is to preserve frame rate.
|
|
2416
|
+
|
|
2417
|
+
Default 'smooth' first for camera, 'default' clear first for screen sharing
|
|
2418
|
+
|
|
2419
|
+
#### QOS_PREFERENCE_CLEAR
|
|
2420
|
+
|
|
2421
|
+
**Default Value:** `'clear'`
|
|
2422
|
+
|
|
2423
|
+
When the network is weak, the video encoding strategy takes 'clear' first, i.e., the priority is to preserve resolution.
|
|
2424
|
+
|
|
2425
|
+
Default 'smooth' first for camera, 'default' clear first for screen sharing
|