@tencent-rtc/mcp 1.3.4 → 1.3.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.
Files changed (102) hide show
  1. package/package.json +1 -1
  2. package/resource/doc/chatuikit/android/features/theme.md +363 -0
  3. package/resource/doc/chatuikit/{android/client_api_Android.md → faq/android_sdk/client-api.md} +0 -2
  4. package/resource/doc/chatuikit/faq/common/product.md +8 -0
  5. package/resource/doc/chatuikit/faq/flutter_sdk/faq.md +53 -0
  6. package/resource/doc/chatuikit/{iOS/client_api_iOS.md → faq/ios_sdk/client-api.md} +0 -2
  7. package/resource/doc/chatuikit/flutter/features/theme.md +379 -0
  8. package/resource/doc/chatuikit/flutter/integration.md +413 -0
  9. package/resource/doc/chatuikit/flutter/workflow.md +941 -0
  10. package/resource/doc/chatuikit/iOS/features/theme.md +416 -0
  11. package/resource/doc/chatuikit/iOS/workflow.md +0 -0
  12. package/resource/doc/chatuikit/react/components/chat-setting.md +86 -0
  13. package/resource/doc/chatuikit/react/components/contact-list.md +1093 -0
  14. package/resource/doc/chatuikit/react/components/search.md +745 -0
  15. package/resource/doc/chatuikit/vue/components/chat-setting.md +64 -0
  16. package/resource/doc/chatuikit/vue/components/contact-list.md +679 -0
  17. package/resource/doc/chatuikit/vue/components/search.md +1384 -0
  18. package/resource/doc/livekit/live/android/workflow.md +137 -6
  19. package/resource/doc/livekit/live/ios/live-audience-list.md +339 -0
  20. package/resource/doc/livekit/live/ios/live-audio-effect.md +370 -0
  21. package/resource/doc/livekit/live/ios/live-barrage.md +517 -0
  22. package/resource/doc/livekit/live/ios/live-base-beauty.md +247 -0
  23. package/resource/doc/livekit/live/ios/live-co-guest-interaction.md +518 -0
  24. package/resource/doc/livekit/live/ios/live-gift.md +783 -0
  25. package/resource/doc/livekit/live/ios/live-host-interaction.md +815 -0
  26. package/resource/doc/livekit/live/ios/live-integration.md +931 -0
  27. package/resource/doc/livekit/live/ios/live-live-list.md +485 -0
  28. package/resource/doc/livekit/live/ios/workflow.md +454 -0
  29. package/resource/doc/rtcengine/web/plugin/20-advanced-customized-capture-rendering.md +87 -0
  30. package/resource/doc/rtcengine/web/plugin/21-advanced-auto-play-policy.md +87 -0
  31. package/resource/doc/rtcengine/web/plugin/22-advanced-audio-mixer.md +175 -0
  32. package/resource/doc/rtcengine/web/plugin/23-advanced-support-detection.md +221 -0
  33. package/resource/doc/rtcengine/web/plugin/24-advanced-network-quality.md +140 -0
  34. package/resource/doc/rtcengine/web/plugin/25-advanced-device-change.md +99 -0
  35. package/resource/doc/rtcengine/web/plugin/26-advanced-publish-cdn-stream.md +451 -0
  36. package/resource/doc/rtcengine/web/plugin/27-advanced-small-stream.md +151 -0
  37. package/resource/doc/rtcengine/web/plugin/28-advanced-beauty.md +322 -0
  38. package/resource/doc/rtcengine/web/plugin/29-advanced-water-mark.md +149 -0
  39. package/resource/doc/rtcengine/web/plugin/30-advanced-cross-room-link.md +96 -0
  40. package/resource/doc/rtcengine/web/plugin/31-advanced-plugins-overview.md +330 -0
  41. package/resource/doc/rtcengine/web/plugin/34-advanced-proxy.md +248 -0
  42. package/resource/doc/rtcengine/web/plugin/35-advanced-ai-denoiser.md +81 -0
  43. package/resource/doc/rtcengine/web/plugin/36-advanced-virtual-background.md +242 -0
  44. package/resource/doc/rtcengine/web/plugin/37-advanced-voice-changer.md +99 -0
  45. package/resource/doc/rtcengine/web/plugin/39-advanced-video-decoder.md +33 -0
  46. package/resource/doc/rtcengine/web/plugin/40-advanced-video-mixer.md +379 -0
  47. package/resource/doc/rtcengine/web/plugin/41-advanced-small-stream-auto-switcher.md +91 -0
  48. package/resource/doc/rtcengine/web/plugin/42-advanced-realtime-transcriber.md +315 -0
  49. package/resource/doc/rtcengine/web/plugin/43-advanced-face-detection.md +180 -0
  50. package/tools/chat/get-native-chat-feature-detail.js +30 -0
  51. package/tools/chat/get-native-chat-feature-detail.js.map +1 -0
  52. package/tools/chat/get-native-chat-integration.js +30 -12
  53. package/tools/chat/get-native-chat-integration.js.map +1 -1
  54. package/tools/common/get-faq.js +2 -4
  55. package/tools/common/get-faq.js.map +1 -1
  56. package/tools/definitions/get_native_chat_feature_detail_def.js +32 -0
  57. package/tools/definitions/get_native_chat_feature_detail_def.js.map +1 -0
  58. package/tools/definitions/get_native_chat_uikit_integration_def.js +19 -7
  59. package/tools/definitions/get_native_chat_uikit_integration_def.js.map +1 -1
  60. package/tools/definitions/{get_native_live_extra_features_def.js → get_native_live_uikit_extra_features_def.js} +3 -3
  61. package/tools/definitions/get_native_live_uikit_extra_features_def.js.map +1 -0
  62. package/tools/definitions/{get_native_live_interaction_def.js → get_native_live_uikit_interaction_def.js} +3 -3
  63. package/tools/definitions/get_native_live_uikit_interaction_def.js.map +1 -0
  64. package/tools/definitions/get_web_chat_uikit_component_detail_def.js +49 -10
  65. package/tools/definitions/get_web_chat_uikit_component_detail_def.js.map +1 -1
  66. package/tools/index.js +6 -4
  67. package/tools/index.js.map +1 -1
  68. package/tools/live/{get_native_live_extra_features.js → get_native_live_uikit_extra_features.js} +4 -4
  69. package/tools/live/get_native_live_uikit_extra_features.js.map +1 -0
  70. package/tools/live/{get_native_live_interaction.js → get_native_live_uikit_interaction.js} +4 -4
  71. package/tools/live/get_native_live_uikit_interaction.js.map +1 -0
  72. package/tools/rtcengine/get-rtcengine-web-sdk-integration.js.map +1 -1
  73. package/tools/rtcengine/get-trtc-sdk-faq.js +32 -0
  74. package/tools/rtcengine/get-trtc-sdk-faq.js.map +1 -0
  75. package/tools/rtcengine/get-trtc-web-sdk-faq.js +1 -1
  76. package/tools/rtcengine/get-trtc-web-sdk-integration.js.map +1 -1
  77. package/tools/rtcengine/get-trtc-web-sdk-plugin.js +45 -0
  78. package/tools/rtcengine/get-trtc-web-sdk-plugin.js.map +1 -0
  79. package/utils/handle-component-name.js +0 -16
  80. package/utils/handle-component-name.js.map +1 -1
  81. package/utils/report-cls-client.js +1 -1
  82. package/utils/report-es-client.js +1 -1
  83. package/resource/doc/chatuikit/android/generate_UserSig.md +0 -306
  84. package/resource/doc/chatuikit/android/integrarte_only_tuichat_Android.md +0 -290
  85. package/resource/doc/chatuikit/android/quick_start_Android.md +0 -138
  86. package/resource/doc/chatuikit/android/show_typing_Android.md +0 -43
  87. package/resource/doc/chatuikit/flutter/generate_UserSig.md +0 -306
  88. package/resource/doc/chatuikit/flutter/integrate_tuikit_Flutter.md +0 -133
  89. package/resource/doc/chatuikit/iOS/generate_UserSig.md +0 -306
  90. package/resource/doc/chatuikit/iOS/integrate_only_tuichat_iOS.md +0 -748
  91. package/resource/doc/chatuikit/iOS/quick_start_iOS.md +0 -163
  92. package/resource/doc/chatuikit/iOS/show_typing_iOS.md +0 -52
  93. package/tools/definitions/get_native_live_extra_features_def.js.map +0 -1
  94. package/tools/definitions/get_native_live_interaction_def.js.map +0 -1
  95. package/tools/live/get_native_live_extra_features.js.map +0 -1
  96. package/tools/live/get_native_live_interaction.js.map +0 -1
  97. /package/resource/doc/chatuikit/android/{integrate_tuikit_Android.md → integration.md} +0 -0
  98. /package/resource/doc/chatuikit/{faq/native_sdk/faq.md → android/workflow.md} +0 -0
  99. /package/resource/doc/chatuikit/{flutter/client_api_Flutter.md → faq/flutter_sdk/client-api.md} +0 -0
  100. /package/resource/doc/chatuikit/iOS/{integrate_tuikit_iOS.md → integration.md} +0 -0
  101. /package/resource/doc/chatuikit/react/components/{chatheader.md → chat-header.md} +0 -0
  102. /package/resource/doc/chatuikit/vue/components/{chatheader.md → chat-header.md} +0 -0
@@ -0,0 +1,175 @@
1
+ ## Function Description
2
+
3
+ This article will introduce how to add background music during a call. [Experience demo](https://web.sdk.qcloud.com/trtc/webrtc/demo/api-sample/improve-audio-mixer.html?roomID=43222).
4
+
5
+ ## Prerequisites
6
+
7
+ TRTC version 5.1+
8
+
9
+ The following platforms support adding background music during a call:
10
+
11
+ | Operating System | Browser Type | Minimum Browser Version |
12
+ |------------------|---------------------|-------------------------|
13
+ | Mac OS | Desktop Chrome | 56+ |
14
+ | Mac OS | Desktop Safari | 11+ |
15
+ | Mac OS | Desktop Firefox | 56+ |
16
+ | Mac OS | Desktop Edge | 80+ |
17
+ | Windows | Desktop Chrome | 56+ |
18
+ | Windows | Desktop QQ Browser | 10.4+ |
19
+ | Windows | Desktop Firefox | 56+ |
20
+ | Windows | Desktop Edge | 80+ |
21
+ | iOS | Mobile Safari | 14+ |
22
+ | iOS | WeChat Embedded Web | ✖ |
23
+ | Android | Mobile Chrome | 81+ |
24
+ | Android | WeChat Embedded Web | ✔ |
25
+ | Android | Mobile QQ Browser | ✖ |
26
+
27
+ ## Implementation Process
28
+
29
+ ### Start Background Music
30
+
31
+ > !
32
+ >
33
+ > - When playing online sound effect files, the sound effect files must support `CORS` and the access protocol must be `https`.
34
+ > - Supported formats include MP3, AAC (and other audio formats supported by browsers).
35
+ > - Before any user interaction, browsers prohibit web pages from playing media with sound. It is recommended to guide users to perform a click action before calling this interface.
36
+ > - Reference: [Autoplay_guide](https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide).
37
+
38
+ ```javascript
39
+ await trtc.startPlugin('AudioMixer', {
40
+ id: 'count',
41
+ url: '../assets/count.mp3',
42
+ loop: true,
43
+ volume: 0.2
44
+ })
45
+ ```
46
+
47
+ ### Update Background Music
48
+ Perform operations on the background music.
49
+
50
+ ```javascript
51
+ // disable loop playback
52
+ await trtc.updatePlugin('AudioMixer', {
53
+ id: 'count',
54
+ loop: false
55
+ })
56
+ // volume setting
57
+ await trtc.updatePlugin('AudioMixer', {
58
+ id: 'count',
59
+ volume: 1
60
+ })
61
+ // pause music `count`
62
+ await trtc.updatePlugin('AudioMixer', {
63
+ id: 'count',
64
+ loop: true,
65
+ volume: 0.2,
66
+ operation: 'pause'
67
+ })
68
+ // resume music `count`
69
+ await trtc.updatePlugin('AudioMixer', {
70
+ id: 'count',
71
+ operation: 'resume'
72
+ })
73
+ // play `count` from 5s
74
+ await trtc.updatePlugin('AudioMixer', {
75
+ id: 'count',
76
+ seekFrom: 5
77
+ })
78
+ ```
79
+
80
+ ### Stop Background Music
81
+
82
+ Stop a background music that is not needed.
83
+
84
+ ```javascript
85
+ await trtc.stopPlugin('AudioMixer', {
86
+ id: 'count'
87
+ })
88
+ ```
89
+
90
+ ## API
91
+
92
+ ### trtc.startPlugin('AudioMixer', options)
93
+
94
+ Start background music.
95
+
96
+ #### options
97
+
98
+ | Name | Type | Attributes | Description |
99
+ |--------|-----------|--------------|---------------------------------------------|
100
+ | id | `string` | | Set a unique ID for each incoming music URL |
101
+ | url | `string` | | Music file URL. One of url and track must be passed in. If both are passed in, the url will be selected first. |
102
+ | track | `MediaStreamAudioTrack` | | Since v5.4.3+, one of url and track must be passed in. can pass in a track extracted from the `<audio/>` tag. If both are passed in, the url will be selected first. |
103
+ | loop | `boolean` | `<optional>` | Whether to loop play, default is false |
104
+ | volume | `number` | `<optional>` | Set the initial volume, default is 1 (0-1). Not support iOS. |
105
+ | playbackRate | `number` | `<optional>` | Set the playback rate, the default is 1.0 |
106
+ | onDurationChange | `function` | `<optional>` | Callback function, which will be executed after the music is loaded. The parameter is (duration: number) which indicates the total duration of the music |
107
+ | onTimeUpdate | `function` | `<optional>` | Callback function, which will be executed after the music is loaded. The parameter is (duration: number) which indicates the total duration of the music |
108
+ | onEnded | `function` | `<optional>` | Callback function, executed when the music ends (note that it will not be executed every time the music ends during loop), no parameters |
109
+
110
+ ```javascript
111
+ await trtc.startPlugin('AudioMixer', {
112
+ id: 'count',
113
+ url: '../assets/count.mp3',
114
+ loop: true,
115
+ volume: 0.2
116
+ })
117
+ ```
118
+
119
+ ### trtc.updatePlugin('AudioMixer', options)
120
+
121
+ Update background music.
122
+
123
+ #### options
124
+
125
+ | Name | Type | Attributes | Description |
126
+ |-----------|-----------|--------------|-------------------------------------------------------------------------|
127
+ | id | `string` | | The unique ID for each incoming music URL you set when call startPlugin |
128
+ | loop | `boolean` | `<optional>` | Whether to loop play, default is false |
129
+ | volume | `number` | `<optional>` | Set the initial volume, default is 1 (0-1) |
130
+ | seekFrom | `number` | `<optional>` | Start seeking playback from which second, this parameter requires the music resource file to support [HTTP range requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests). |
131
+ | operation | `number` | `<optional>` | Operation on the background music: 'pause' | 'resume' | 'stop' |
132
+
133
+ **Example:**
134
+
135
+ ```javascript
136
+ await trtc.updatePlugin('AudioMixer', {
137
+ id: 'count',
138
+ loop: true,
139
+ volume: 0.2,
140
+ operation: 'pause'
141
+ })
142
+ ```
143
+
144
+ ### trtc.stopPlugin('AudioMixer', options)
145
+
146
+ Stop a background music that is not needed.
147
+
148
+ #### options
149
+
150
+ | Name | Type | Attributes | Description |
151
+ |------|----------|------------|-------------------------------------------------------------------------|
152
+ | id | `string` | | The unique ID for each incoming music URL you set when call startPlugin |
153
+
154
+ **Example:**
155
+
156
+ ```javascript
157
+ await trtc.stopPlugin('AudioMixer', {
158
+ id: 'count'
159
+ })
160
+ ```
161
+
162
+ ## Frequently Asked Questions
163
+
164
+ **1. Cross-Origin Error**
165
+
166
+ For example: Access to audio at XXX from origin XXX has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is
167
+ present on the requested resource.
168
+
169
+ Solution: You need to configure the CORS protocol for your online music files.
170
+
171
+ **2. Incorrect Audio Format, Unable to Play in Browser**
172
+
173
+ For example: NotSupportedError: The operation is not supported.
174
+
175
+ Solution: You need to use an audio format supported by the browser.
@@ -0,0 +1,221 @@
1
+ ## Browser Environment Check
2
+
3
+ Before calling the communication capabilities of the SDK, we recommend you use the `{@link TRTC.isSupported TRTC.isSupported}` API to check whether the SDK supports the current browser first, and if not, please recommend the user to use a supported browser(Chrome 56+, Edge 80+, Firefox 56+, Safari 11+).
4
+
5
+ ```javascript
6
+ TRTC.isSupported().then(checkResult => {
7
+ // Not supported, guide the user to use a supported browser(Chrome 56+, Edge 80+, Firefox 56+, Safari 11+).
8
+ if (!checkResult.result) {}
9
+ // Not support to publish video
10
+ if (!checkResult.detail.isH264EncodeSupported) {}
11
+ // Not support to subscribe video
12
+ if (!checkResult.detail.isH264DecodeSupported) {}
13
+ })
14
+ ```
15
+
16
+ ⚠️ If the check result returned by `TRTC.isSupported` is `false`, this may be because:
17
+
18
+ 1. The web page uses the http protocol. Browsers do not allow http protocol sites to capture cameras and microphones, you need to deploy your page using the https protocol.
19
+ 2. The current browser does not support WebRTC, you need to guide the user to use the recommended browser {@tutorial 05-info-browser}.
20
+ 3. Firefox browser needs to load H264 codec dynamically after installation, so the detection result will be false for a short period of time, please wait and try again or guide to use other browsers.
21
+
22
+ ## Media Device Test
23
+
24
+ ### Option 1: Use Device Detector Plugin (including default UI)
25
+
26
+ The device detector plugin is used to test the user's media device(camera, microphone, speaker) and network which is recommended to be used before the user enters the room.
27
+
28
+ > - Support TRTC Web SDK version >= v5.8.0
29
+ > - The plugin includes a default UI. If the UI does not meet your product design requirements, you can refer to Option 2 for a custom UI implementation.
30
+
31
+ #### Usage
32
+
33
+ ```javascript
34
+ import { DeviceDetector } from 'trtc-sdk-v5/plugins/device-detector';
35
+ const trtc = TRTC.create({ plugins: [DeviceDetector] });
36
+
37
+ // 1. Test Media Device Only
38
+ const result = await trtc.startPlugin('DeviceDetector');
39
+
40
+ // 2. Test Media Device & Network Quality
41
+ const options = {
42
+ networkDetect: { sdkAppId, userId, userSig }
43
+ }
44
+ const resultWithNetwork = await trtc.startPlugin('DeviceDetector', options);
45
+ ```
46
+
47
+ #### API Description
48
+
49
+ ##### trtc.startPlugin('DeviceDetector', options)
50
+
51
+ ##### options
52
+
53
+ | Name | Type | Attributes | Description |
54
+ | --------------- | ------ | ---------- | ------------------------------------------------------------ |
55
+ | language | 'auto' \| 'zh' \| 'en' | Optional | Optional. Set the language of the UI, supporting Chinese and English. The default is 'auto', which means automatically judging based on the current browser language. 'zh' means using Chinese, 'en' means using English.|
56
+ | allowSkip | boolean | Optional | Optional. The default value is true, which will display the skip button. If false, the skip button will not be displayed, and the user must complete each step of the detection before proceeding to the next step.|
57
+ | cameraDetect | object | Optional | Optional. Camera detection options, see cameraDetect options below|
58
+ | networkDetect | object | Optional | Optional. Network detection options, see networkDetect options below|
59
+
60
+
61
+ ###### options.mirror(optional)
62
+
63
+ Enable the mirror checkbox during camera detection
64
+
65
+ ###### options.cameraDetect(optional)
66
+ | Name | Type | Attributes | Description |
67
+ | ------ | ------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
68
+ | mirror | boolean | Optional | Optional. When true, the mirror image will be enabled during the camera detection phase, and a checkbox for the mirror image will be displayed |
69
+
70
+ ###### options.networkDetect(optional)
71
+
72
+ | Name | Type | Attributes | Description |
73
+ | --------------- | ------ | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
74
+ | sdkAppId | string | required | Your sdkAppId |
75
+ | userId | string | required | The userId for testing uplink network quality. It should be different from downlinkUserId. |
76
+ | userSig | string | required | The [UserSig](https://trtc.io/document/35166) of the userId. |
77
+ | downlinkUserId | string | required | The userId for testing downlink network quality. It should be different from userId. Fill in downlinkUserId and downlinkUserSig will perform a downlink network test. |
78
+ | downlinkUserSig | string | required | The [UserSig](https://trtc.io/document/35166) of the downlinkUserId. |
79
+ | roomId | number | optional | Optional. The default value is 8080. The value must be an integer of [1, 4294967294] |
80
+
81
+ ##### trtc.stopPlugin('DeviceDetector')
82
+
83
+ | Name | Type | Description |
84
+ | -------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
85
+ | **camera** | `object` | { isSuccess: boolean, device: { deviceId: string, groupId: string, kind: "videoinput", label: string }} |
86
+ | **microphone** | `object` | { isSuccess: boolean, device: { deviceId: string, groupId: string, kind: "audioinput", label: string }} |
87
+ | **speaker** | `object` | { isSuccess: boolean, device: { deviceId: string, groupId: string, kind: "audiooutput", label: string }} |
88
+ | **network** | `object` | { isSuccess: boolean, result: { quality: number , rtt: number }}<br />The quality is uplink network quality. When the downlinkUserId and downlinkUserSig passed, the quality is the worse one of the upstream and downstream network quality<br />**Network Quality Values**<br />0: The network quality is unknown, indicating that the current TRTC instance has not established a media connection<br />1: The network quality is excellent<br />2: The network quality is good<br />3: The network quality is average<br />4: The network quality is poor<br />5: The network quality is extremely poor<br />6: The network connection has been disconnected. |
89
+
90
+ #### Plugin Demo
91
+
92
+ <iframe allow="microphone; camera; display-capture;" height="700" style="width:100%" scrolling="no" title="Device Detector" src="https://codepen.io/TRTC/embed/eYwVVja?default-tab=" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">
93
+ See the Pen <a href="https://codepen.io/TRTC/pen/eYwVVja">
94
+ Device Detector</a> by TRTC (<a href="https://codepen.io/TRTC">@TRTC</a>)
95
+ on <a href="https://codepen.io">CodePen</a>.
96
+ </iframe>
97
+
98
+ ### Option 2: Implement Device Detection Based on SDK API (Custom UI)
99
+
100
+ If the default UI of the device detection plugin in Option 1 does not meet your requirements, you can choose Option 2 to customize the UI.
101
+
102
+ #### 1. Check Device Permission
103
+
104
+ Since v5.13.0+, SDK provides the `TRTC.getPermissions` interface, which is used to check, request, and listen to device permissions.
105
+
106
+ ```javascript
107
+ const { camera, microphone } = await TRTC.getPermissions({
108
+ request: true, // If true, the interface may temporarily open the camera to obtain the camera permission, and then the SDK will automatically release the capture.
109
+ types: ['camera', 'microphone'] // The types of permission to request.
110
+ });
111
+ console.log(camera, microphone); // 'granted' | 'denied' | 'prompt' | null. null means the permission is not supported query.
112
+
113
+ // Listen to device permission changes
114
+ trtc.on(TRTC.EVENT.PERMISSION_STATE_CHANGE, event => {
115
+ console.log(event.camera, event.microphone);
116
+ });
117
+ // Release the listener
118
+ trtc.off(TRTC.EVENT.PERMISSION_STATE_CHANGE);
119
+ ```
120
+
121
+ #### 2. Device Connection
122
+
123
+ The device connection checks if the user's device has a camera, microphone, and speaker. It also verifies the network connection. If the camera and microphone are present, the system will attempt to access the audio/video streams and prompt the user to grant permission for camera and microphone access.
124
+
125
+ + Check whether the device has a camera, microphone device
126
+
127
+ ```javascript
128
+ import TRTC from 'trtc-sdk-v5';
129
+
130
+ const cameraList = await TRTC.getCameraList();
131
+ const micList = await TRTC.getMicrophoneList();
132
+ const hasCameraDevice = cameraList.some(camera => camera.deviceId !== '');
133
+ const hasMicrophoneDevice = micList.some(mic => mic.deviceId !== '');
134
+ // Mobile devices do not support getting speaker devices, so mobile devices can skip getting speaker devices
135
+ const speakerList = await TRTC.getSpeakerList();
136
+ const hasSpeakerDevice = speakerList.some(speaker => speaker.deviceId !== '');
137
+ ```
138
+
139
+ #### 3. Camera Detection
140
+
141
+ Detection principle: Turn on the camera and render the camera image on the page. You can provide two buttons on the page to allow the user to confirm whether they can see the camera image.
142
+
143
+ + Turn on the camera
144
+
145
+ ```javascript
146
+ trtc.startLocalVideo({ view: 'camera-video', publish: false });
147
+ ```
148
+
149
+ + Switch the camera
150
+
151
+ ```javascript
152
+ trtc.updateLocalVideo({ option: { cameraId } });
153
+ ```
154
+
155
+ + Close the camera after detection is completed
156
+
157
+ ```javascript
158
+ trtc.stopLocalVideo();
159
+ ```
160
+
161
+ #### 4. Microphone Detection
162
+
163
+ Detection principle: Open the microphone and obtain the microphone volume. Listen to the microphone volume event and render the real-time volume to the page, guide the user to speak, and confirm whether they can see the volume bar change.
164
+
165
+ + Turn on the microphone
166
+
167
+ ```javascript
168
+ trtc.on(TRTC.EVENT.AUDIO_VOLUME, event => {
169
+ event.result.forEach(({ userId, volume }) => {
170
+ const isMe = userId === '';
171
+ if (isMe) {
172
+ console.log(`my volume: ${volume}`);
173
+ // Render the microphone volume to your page.
174
+ }
175
+ })
176
+ });
177
+ // 开启音量回调,并设置每 200ms 触发一次事件
178
+ trtc.enableAudioVolumeEvaluation(200);
179
+ trtc.startLocalAudio({ publish: false });
180
+ ```
181
+
182
+ + Switch the microphone
183
+
184
+ ```javascript
185
+ trtc.updateLocalAudio({ option: { microphoneId }});
186
+ ```
187
+
188
+ + Release the microphone usage after detection is completed
189
+
190
+ ```javascript
191
+ trtc.stopLocalAudio();
192
+ ```
193
+
194
+ #### 5. Speaker Detection
195
+
196
+ Detection principle: Play an mp3 media file through an audio tag
197
+
198
+ + Create an audio tag, remind the user to turn up the playback volume, play the mp3 to confirm whether the speaker device is normal.
199
+
200
+ ```html
201
+ <audio id="audio-player" src="xxxxx" controls></audio>
202
+ ```
203
+
204
+ + Stop playback after detection is completed
205
+
206
+ ```javascript
207
+ const audioPlayer = document.getElementById('audio-player');
208
+ if (!audioPlayer.paused) {
209
+ audioPlayer.pause();
210
+ }
211
+ audioPlayer.currentTime = 0;
212
+ ```
213
+
214
+ #### 6. Network Detection
215
+
216
+ Reference: [Network Quality Detection before enterRoom](./tutorial-24-advanced-network-quality.html)
217
+
218
+ ## TRTC Capability Detection Page
219
+
220
+ You can use the [TRTC Detection Page](https://web.sdk.qcloud.com/trtc/webrtc/demo/detect/index.html) where you are currently using the TRTC SDK to detect the current environment. You can also click the "Generate Report" button to get a report of the current environment for environment detection or troubleshooting.
221
+
@@ -0,0 +1,140 @@
1
+
2
+ Before entering the room or during the call, you can check the user's network quality to determine the current network quality. If the user's network quality is too poor, it is recommended that the user change the network environment to ensure normal call quality.
3
+
4
+ This article mainly introduces how to implement network quality detection before the call or during the call based on the [NETWORK_QUALITY](./module-EVENT.html#.NETWORK_QUALITY) event.
5
+
6
+ ## Detect network quality during the call
7
+
8
+ See: {@link module:EVENT.NETWORK_QUALITY NETWORK_QUALITY}
9
+
10
+ ```js
11
+ const trtc = TRTC.create();
12
+ trtc.on(TRTC.EVENT.NETWORK_QUALITY, event => {
13
+ console.log(`network-quality, uplinkNetworkQuality:${event.uplinkNetworkQuality}, downlinkNetworkQuality: ${event.downlinkNetworkQuality}`)
14
+ console.log(`uplink rtt:${event.uplinkRTT} loss:${event.uplinkLoss}`)
15
+ console.log(`downlink rtt:${event.downlinkRTT} loss:${event.downlinkLoss}`)
16
+ })
17
+ ```
18
+
19
+ ## Detect network quality before the call
20
+
21
+ ### Implementation process
22
+
23
+ 1. Call [TRTC.create](./TRTC.html#.createTRTC) to create two TRTC objects, referred to as uplinkTRTC and downlinkTRTC.
24
+ 2. Both TRTC objects enter the same room.
25
+ 3. Use uplinkTRTC to startLocalVideo, and listen to the [NETWORK_QUALITY](./module-EVENT.html#.NETWORK_QUALITY) event to detect the uplink network quality.
26
+ 4. Use downlinkTRTC to startRemoteVideo, and listen to the [NETWORK_QUALITY](./module-EVENT.html#.NETWORK_QUALITY) event to detect the downlink network quality.
27
+ 5. The entire process lasts for about 15 seconds, and finally takes the average network quality to roughly determine the uplink and downlink network conditions.
28
+
29
+ > !
30
+ > - The detection process will generate a small amount of [basic service fees](https://trtc.io/document/59806?platform=android&product=rtcengine&menulabel=coresdk). If the push stream resolution is not specified, it defaults to pushing the stream with a resolution of 640*480.
31
+
32
+ ### API call sequence
33
+
34
+ ![network-quality-call-sequence](./assets/network-quality-call-sequence.png)
35
+
36
+ ### Code example
37
+
38
+ ```js
39
+ let uplinkTRTC = null; // Used to detect uplink network quality
40
+ let downlinkTRTC = null; // Used to detect downlink network quality
41
+ let localStream = null; // Stream used for testing
42
+ let testResult = {
43
+ // Record uplink network quality data
44
+ uplinkNetworkQualities: [],
45
+ // Record downlink network quality data
46
+ downlinkNetworkQualities: [],
47
+ average: {
48
+ uplinkNetworkQuality: 0,
49
+ downlinkNetworkQuality: 0
50
+ }
51
+ }
52
+
53
+ // 1. Test uplink network quality
54
+ async function testUplinkNetworkQuality() {
55
+ uplinkTRTC = TRTC.create();
56
+
57
+ uplinkTRTC.enterRoom({
58
+ roomId: 8080,
59
+ sdkAppId: 0, // Fill in sdkAppId
60
+ userId: 'user_uplink_test',
61
+ userSig: '', // userSig of uplink_test
62
+ scene: 'rtc'
63
+ })
64
+
65
+ uplinkTRTC.on(TRTC.EVENT.NETWORK_QUALITY, event => {
66
+ const { uplinkNetworkQuality } = event;
67
+ testResult.uplinkNetworkQualities.push(uplinkNetworkQuality);
68
+ });
69
+
70
+ uplinkTRTC.startLocalVideo();
71
+ }
72
+
73
+
74
+
75
+ // 2. Detect downlink network quality
76
+ async function testDownlinkNetworkQuality() {
77
+ downlinkTRTC = TRTC.create();
78
+ downlinkTRTC.enterRoom({
79
+ roomId: 8080,
80
+ sdkAppId: 0, // Fill in sdkAppId
81
+ userId: 'user_downlink_test',
82
+ userSig: '', // userSig
83
+ scene: 'rtc',
84
+ autoReceiveVideo: true
85
+ });
86
+
87
+ downlinkTRTC.on(TRTC.EVENT.NETWORK_QUALITY, event => {
88
+ const { downlinkNetworkQuality } = event;
89
+ testResult.downlinkNetworkQualities.push(downlinkNetworkQuality);
90
+ })
91
+ }
92
+
93
+ // 3. Start detection
94
+ testUplinkNetworkQuality();
95
+ testDownlinkNetworkQuality();
96
+
97
+ // 4. Stop detection after 15s and calculate the average network quality
98
+ setTimeout(() => {
99
+ // Calculate the average uplink network quality
100
+ const validUplinkNetworkQualitiesList = testResult.uplinkNetworkQualities.filter(value => value >= 1 && value <= 5);
101
+ if (validUplinkNetworkQualitiesList.length > 0) {
102
+ testResult.average.uplinkNetworkQuality = Math.ceil(
103
+ validUplinkNetworkQualitiesList.reduce((value, current) => value + current, 0) / validUplinkNetworkQualitiesList.length
104
+ );
105
+ }
106
+
107
+ const validDownlinkNetworkQualitiesList = testResult.uplinkNetworkQualities.filter(value => value >= 1 && value <= 5);
108
+ if (validDownlinkNetworkQualitiesList.length > 0) {
109
+ // Calculate the average downlink network quality
110
+ testResult.average.downlinkNetworkQuality = Math.ceil(
111
+ validDownlinkNetworkQualitiesList.reduce((value, current) => value + current, 0) / validDownlinkNetworkQualitiesList.length
112
+ );
113
+ }
114
+
115
+ // Detection is over, clean up related states.
116
+ uplinkTRTC.exitRoom();
117
+ downlinkTRTC.exitRoom();
118
+ }, 15 * 1000);
119
+ ```
120
+
121
+ ## Result Analysis
122
+
123
+ After the above steps, you can get the average uplink network quality and the average downlink network quality. The enumeration values of network quality are as follows:
124
+
125
+ | Value | Meaning |
126
+ | :--- | :----------------------------------------------------------- |
127
+ | 0 | The network condition is unknown, indicating that the current TRTC instance has not established an uplink/downlink connection |
128
+ | 1 | The network condition is excellent |
129
+ | 2 | The network condition is good |
130
+ | 3 | The network condition is average |
131
+ | 4 | The network condition is poor |
132
+ | 5 | The network condition is extremely poor |
133
+ | 6 | The network connection has been disconnected. Note: If the downlink network quality is this value, it means that all downlink connections have been disconnected. |
134
+
135
+ > Suggestion: When the network quality is greater than 3, it is recommended to guide the user to check the network and try to change the network environment, otherwise it is difficult to ensure normal audio and video communication.
136
+ > You can also reduce bandwidth consumption through the following strategies:
137
+ > - If the uplink network quality is greater than 3, you can reduce the bitrate through the [TRTC.updateLocalVideo()](./TRTC.html#updateLocalVideo) interface or close the video through the [TRTC.stopLocalVideo()](./TRTC.html#stopLocalVideo) method to reduce uplink bandwidth consumption.
138
+ > - If the downlink network quality is greater than 3, you can reduce the downlink bandwidth consumption by subscribing to a small stream (refer to: [Enable Small Stream Transmission](./tutorial-27-advanced-small-stream.html)) or only subscribing to audio.
139
+
140
+
@@ -0,0 +1,99 @@
1
+
2
+ ## Function Description
3
+
4
+ This article mainly introduces how to detect the behavior of users inserting, unplugging, and starting devices. And how to handle device collection exceptions.
5
+
6
+ > **About SDK automatic recovery collection**<br>
7
+ > The SDK will detect the insertion and removal behavior of the camera and microphone, and automatically recover the collection at the appropriate time. The specific logic is as follows:
8
+ > 1. If the currently streaming camera/microphone is unplugged, the SDK will try to use the remaining available media devices to restore the collection.
9
+ > 2. If the camera/microphone is unplugged and there are no available media devices, the SDK will detect the device insertion behavior. If a new available media device is inserted, the SDK will try to use the newly inserted media device to restore the collection and push the stream.
10
+ > 3. If the recovery fails, an error [TRTC.ERROR_CODE.DEVICE_ERROR](./module-ERROR_CODE.html#.DEVICE_ERROR) will be thrown, and the extraCode will be 5308 and 5309.
11
+
12
+
13
+ ## Implementation Process
14
+
15
+ ### Detect device insertion, removal, and startup
16
+
17
+ ```js
18
+ trtc.on(TRTC.EVENT.DEVICE_CHANGED, (event) => {
19
+ // Device insertion
20
+ if (event.action === 'add') {
21
+ // Camera insertion
22
+ if (event.type === 'camera') {}
23
+ } else if (event.action === 'remove') {
24
+ // Device unplugged
25
+ } else if (event.action === 'active') {
26
+ // Device startup
27
+ }
28
+ console.log(`${event.type}(${event.device.label}) ${event.action}`);
29
+ });
30
+ ```
31
+
32
+ ### Check if the currently used device is unplugged
33
+
34
+ ```js
35
+ trtc.on(TRTC.EVENT.DEVICE_CHANGED, (event) => {
36
+ if (event.action === 'remove') {
37
+ if (event.type === 'camera') {
38
+ const currentCameraId = trtc.getVideoTrack()?.getSettings()?.deviceId;
39
+ if (event.device.deviceId === currentCameraId) {
40
+ // The currently used camera is unplugged.
41
+ }
42
+ } else if (event.type === 'microphone') {
43
+ const currentMicId = trtc.getAudioTrack()?.getSettings()?.deviceId;
44
+ if (event.device.deviceId === currentMicId) {
45
+ // The currently used microphone is unplugged.
46
+ }
47
+ }
48
+ }
49
+ });
50
+ ```
51
+
52
+ ### Automatically switch to using new devices when users insert new devices.
53
+
54
+ ```js
55
+ trtc.on(TRTC.EVENT.DEVICE_CHANGED, (event) => {
56
+ if (event.action === 'add') {
57
+ if (event.type === 'camera') {
58
+ // After inserting the camera, automatically switch to the new camera
59
+ trtc.updateLocalVideo({ option: { cameraId: event.device.deviceId }});
60
+ }
61
+ }
62
+ });
63
+ ```
64
+
65
+ ### Handling device collection exceptions
66
+
67
+ Listen for device collection exception events
68
+
69
+ ```js
70
+ trtc.on(TRTC.EVENT.VIDEO_PLAY_STATE_CHANGED, event => {
71
+ // Local camera collection exception, at this time the SDK will try to automatically recover the collection, you can guide the user to check whether the camera is normal.
72
+ if (event.userId === '' && event.streamType === TRTC.TYPE.STREAM_TYPE_MAIN && (event.reason === 'mute' || event.reason === 'ended')) {}
73
+ });
74
+
75
+ trtc.on(TRTC.EVENT.AUDIO_PLAY_STATE_CHANGED, event => {
76
+ // Local microphone collection exception, at this time the SDK will try to automatically recover the collection, you can guide the user to check whether the microphone is normal.
77
+ if (event.userId === '' && (event.reason === 'mute' || event.reason === 'ended')) {}
78
+ });
79
+ ```
80
+
81
+ Listen for SDK automatic recovery collection failure events
82
+ ```js
83
+ trtc.on(TRTC.EVENT.ERROR, error => {
84
+ if (error.code === TRTC.ERROR_CODE.DEVICE_ERROR) {
85
+ // Camera recovery collection failed
86
+ if (error.extraCode === 5308) {
87
+ // After guiding the user to check the device, call updateLocalVideo and pass in cameraId to recollect.
88
+ trtc.updateLocalVideo({ option: { cameraId: '' }});
89
+ }
90
+
91
+ // Microphone recovery collection failed
92
+ if (error.extraCode === 5309) {
93
+ // After guiding the user to check the device, call updateLocalAudio and pass in microphoneId to recollect.
94
+ trtc.updateLocalAudio({ option: { microphoneId: '' }});
95
+ }
96
+ }
97
+ })
98
+ ```
99
+