@tencentcloud/sdk-mcp 1.3.0 → 1.3.2

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 (67) hide show
  1. package/index.js +5 -1
  2. package/index.js.map +1 -1
  3. package/package.json +2 -2
  4. package/resource/doc/chatuikit/faq/web_sdk/faq.md +117 -0
  5. package/resource/doc/chatuikit/flutter/client_api_Flutter.md +100 -179
  6. package/resource/doc/chatuikit/flutter/faq.md +17 -112
  7. package/resource/doc/chatuikit/flutter/integrate_tuikit_Flutter.md +272 -1281
  8. package/resource/doc/chatuikit/react/integration.md +516 -48
  9. package/resource/doc/chatuikit/react/workflow.md +254 -0
  10. package/resource/doc/chatuikit/uniapp-app/faq.md +0 -0
  11. package/resource/doc/chatuikit/uniapp-app/integration.md +619 -0
  12. package/resource/doc/chatuikit/uniapp-app/workflow.md +576 -0
  13. package/resource/doc/chatuikit/vue/integration.md +511 -129
  14. package/resource/doc/chatuikit/vue/workflow.md +395 -0
  15. package/resource/doc/roomkit/vue/features/call-user-to-room.md +256 -0
  16. package/resource/doc/roomkit/vue/features/device-detection.md +388 -0
  17. package/resource/doc/roomkit/vue/features/device-state.md +480 -0
  18. package/resource/doc/roomkit/vue/features/free-beauty-panel.md +238 -0
  19. package/resource/doc/roomkit/vue/features/room-chat.md +427 -0
  20. package/resource/doc/roomkit/vue/features/room-participant-state.md +407 -0
  21. package/resource/doc/roomkit/vue/features/room-state.md +291 -0
  22. package/resource/doc/roomkit/vue/features/room-view.md +338 -0
  23. package/resource/doc/roomkit/vue/features/schedule-room.md +349 -0
  24. package/resource/doc/roomkit/vue/features/screen-share.md +333 -0
  25. package/resource/doc/roomkit/vue/features/virtual-background.md +281 -0
  26. package/resource/doc/roomkit/vue/features/workflow.md +553 -0
  27. package/resource/doc/roomkit/vue/integration.md +479 -0
  28. package/resource/doc/roomkit/vue/workflow.md +487 -0
  29. package/resource/doc/tuicallkit/react/api.md +16 -0
  30. package/resource/doc/tuicallkit/vue/api.md +16 -0
  31. package/tools/chat/get-web-chat-integration.js +31 -14
  32. package/tools/chat/get-web-chat-integration.js.map +1 -1
  33. package/tools/definitions/get_web_chat_uikit_integration_def.js +18 -11
  34. package/tools/definitions/get_web_chat_uikit_integration_def.js.map +1 -1
  35. package/tools/definitions/get_web_live_uikit_integration_def.js +1 -1
  36. package/tools/definitions/get_web_room_feature_detail_def.js +95 -0
  37. package/tools/definitions/get_web_room_feature_detail_def.js.map +1 -0
  38. package/tools/definitions/get_web_room_uikit_integration_def.js +44 -0
  39. package/tools/definitions/get_web_room_uikit_integration_def.js.map +1 -0
  40. package/tools/definitions/present_framework_choice_def.js +1 -1
  41. package/tools/definitions/record_result_def.js +1 -1
  42. package/tools/definitions/record_result_def.js.map +1 -1
  43. package/tools/index.js +4 -4
  44. package/tools/index.js.map +1 -1
  45. package/tools/live/get-web-live-uikit-integration.js +1 -1
  46. package/tools/room/get-web-room-feature-detail.js +68 -0
  47. package/tools/room/get-web-room-feature-detail.js.map +1 -0
  48. package/tools/room/get-web-room-integration.js +43 -0
  49. package/tools/room/get-web-room-integration.js.map +1 -0
  50. package/utils/generate-structured-result.js +2 -2
  51. package/utils/generate-structured-result.js.map +1 -1
  52. package/utils/report-cls-client.js +1 -1
  53. package/utils/report-es-client.js +1 -1
  54. package/resource/doc/chatuikit/react/chat_window_integration.md +0 -83
  55. package/resource/doc/chatuikit/vue/chat_window_integration.md +0 -131
  56. package/resource/doc/roomkit/vue/states/device-state.md +0 -316
  57. package/resource/doc/roomkit/vue/states/login-state.md +0 -51
  58. package/resource/doc/roomkit/vue/states/room-list-state.md +0 -287
  59. package/resource/doc/roomkit/vue/states/room-participant-state.md +0 -307
  60. package/tools/chat/get-web-chat-window-integration.js +0 -28
  61. package/tools/chat/get-web-chat-window-integration.js.map +0 -1
  62. package/tools/definitions/get_web_chat_window_integration_def.js +0 -26
  63. package/tools/definitions/get_web_chat_window_integration_def.js.map +0 -1
  64. package/tools/definitions/get_web_room_state_detail_def.js +0 -19
  65. package/tools/definitions/get_web_room_state_detail_def.js.map +0 -1
  66. package/tools/room/get-web-room-state-detail.js +0 -31
  67. package/tools/room/get-web-room-state-detail.js.map +0 -1
@@ -0,0 +1,407 @@
1
+ 本篇文档将指导您如何管理房间内的参会者。Atomicx 提供了开箱即用的列表组件 `RoomParticipantList` 用于快速集成,并暴露了 [useRoomParticipantState](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#module-RoomParticipantState) Hook,方便您实现自定义的成员控制逻辑。
2
+
3
+ ## 功能介绍
4
+
5
+ 成员管理模块涵盖了房间内用户信息展示以及权限处理的全套能力:
6
+ - **实时列表展示:**动态呈现房间内所有成员的昵称、角色、音视频状态及音量波动。
7
+
8
+ - **权限控制:**支持房主或管理员执行踢人、全员禁言、转让房主等管理操作。
9
+
10
+ - **分级管理:**支持对房主、管理员及普通成员实现差异化的权限策略。
11
+
12
+
13
+ ## 前提条件
14
+ - 用户已经通过 [useLoginState](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#module-LoginState) 完成登录鉴权,请参考 [接入概览](https://write.woa.com/document/197379797539790848)。
15
+
16
+ - 用户已经通过 [useRoomState](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#module-RoomState) 进入房间,请参考 [房间管理](https://write.woa.com/document/197379861957083136)。
17
+
18
+
19
+ ## 集成成员管理组件
20
+
21
+ 如果您需要快速构建成员列表界面,推荐直接使用 `RoomParticipantList` 组件。`RoomParticipantList` 是一个开箱即用的参会者列表组件,内置了完整的成员管理 UI 和交互。
22
+
23
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027337918/9407bc54dbe911f0a4f35254007c27c5.png)
24
+
25
+
26
+ 集成 `RoomParticipantList` 组件示例代码:
27
+ ``` typescript
28
+ <template>
29
+ <div class="room-page">
30
+ <!-- 参会者列表侧边栏 -->
31
+ <aside class="sidebar">
32
+ <div class="sidebar-header">
33
+ <span>参会者 ({{ currentRoom.participantCount }})</span>
34
+ <IconClose />
35
+ </div>
36
+
37
+ <!-- 参会者列表组件 -->
38
+ <RoomParticipantList />
39
+ </aside>
40
+ </div>
41
+ </template>
42
+
43
+ <script setup lang="ts">
44
+ import { ref } from 'vue';
45
+ import { IconClose } from '@tencentcloud/uikit-base-component-vue3';
46
+ import {
47
+ RoomView,
48
+ RoomParticipantList,
49
+ useRoomState,
50
+ useRoomParticipantState
51
+ } from 'tuikit-atomicx-vue3/room';
52
+
53
+ const { currentRoom } = useRoomState();
54
+ const { participantList } = useRoomParticipantState();
55
+ </script>
56
+
57
+ <style scope>
58
+ .room-page {
59
+ width: 100vw;
60
+ height: 100vh;
61
+ min-width: 1150px;
62
+ display: flex;
63
+ flex-direction: row;
64
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
65
+ position: relative;
66
+ overflow: hidden;
67
+ }
68
+
69
+ .sidebar {
70
+ position: absolute;
71
+ top: 0;
72
+ right: 0;
73
+ width: 400px;
74
+ height: 100%;
75
+ box-sizing: border-box;
76
+ }
77
+
78
+ .sidebar-header {
79
+ display: flex;
80
+ height: 60px;
81
+ justify-content: space-between;
82
+ align-items: center;
83
+ padding: 0px 20px;
84
+ }
85
+ </style>
86
+ ```
87
+
88
+ > **说明:**
89
+ >
90
+ > - `RoomParticipantList` 会自动占满父容器的高度和宽度,请确保其父容器具备明确的尺寸。
91
+ > - 使用 `RoomParticipantList` 组件请确保在 `App.vue` 中配置全局 `UIKitProvider`,具体请参考 [配置 App.vue](https://cloud.tencent.com/document/product/647/81962#ce98ee15-b0cb-43af-81da-70f51231430e)。
92
+
93
+
94
+ ## 实现成员管理功能
95
+
96
+ 如果您需要自定义成员列表 UI 或在特定业务中触发管理行为,请使用 [useRoomParticipantState](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#module-RoomParticipantState)。
97
+
98
+ ### 步骤1:获取成员列表
99
+
100
+ 通过 [getParticipantList](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#getParticipantList) 获取响应式的成员数据 [participantList](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#participantList)。
101
+ ``` typescript
102
+ import { useRoomState, useRoomParticipantState } from 'tuikit-atomicx-vue3/room';
103
+
104
+ const { currentRoom } = useRoomState();
105
+ const { participantList, participantListCursor, getParticipantList } = useRoomParticipantState();
106
+
107
+ // 在进房成功之后获取房间内用户列表
108
+ watch(() => currentRoom.value?.roomId, async () => {
109
+ await getParticipantList();
110
+ })
111
+
112
+ // 当列表滚动到底部时,加载更多用户
113
+ const handleLoadMore = async () => {
114
+ if (participantListCursor.value) {
115
+ await getParticipantList({ cursor: participantListCursor.value });
116
+ }
117
+ };
118
+ ```
119
+
120
+ > **说明:**
121
+ >
122
+
123
+ > `getParticipantList` 接口拉取成功的数据会自动维护在 `participantList` 中,UI 只需要渲染 `participantList` 的数据即可。
124
+ >
125
+
126
+
127
+ ### 步骤2:渲染参会者信息
128
+
129
+ 开发者可以使用 [participantList](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#participantList) 数据自定义渲染用户信息列表。
130
+ ``` typescript
131
+ <template>
132
+ <div class="participant-list">
133
+ <div class="list-header">
134
+ <h3>参会者 ({{ participantList.length }})</h3>
135
+ <button @click="handleRefresh">
136
+ <IconRefresh />
137
+ </button>
138
+ </div>
139
+ <div class="list-content">
140
+ <div
141
+ v-for="participant in participantList"
142
+ :key="participant.userId"
143
+ class="participant-item"
144
+ >
145
+ <!-- 头像 -->
146
+ <Avatar
147
+ :user-id="participant.userId"
148
+ :avatar-url="participant.avatarUrl"
149
+ />
150
+
151
+ <!-- 用户信息 -->
152
+ <div class="user-info">
153
+ <div class="user-name">
154
+ <span>{{ participant.userName }}</span>
155
+ <span v-if="participant.userId === localParticipant.userId" class="badge">我</span>
156
+ <span
157
+ v-if="participant.role === RoomParticipantRole.Owner"
158
+ class="role-badge owner"
159
+ >
160
+ 房主
161
+ </span>
162
+ <span
163
+ v-else-if="participant.role === RoomParticipantRole.Admin"
164
+ class="role-badge admin"
165
+ >
166
+ 管理员
167
+ </span>
168
+ </div>
169
+ </div>
170
+
171
+ <!-- 设备状态 -->
172
+ <div class="device-status">
173
+ <IconMicOn
174
+ size="20"
175
+ v-if="participant.microphoneStatus === DeviceStatus.On"
176
+ class="icon-on"
177
+ />
178
+ <IconMicOff size="20" v-else class="icon-off" />
179
+ <IconCameraOn
180
+ size="20"
181
+ v-if="participant.cameraStatus === DeviceStatus.On"
182
+ class="icon-on"
183
+ />
184
+ <IconCameraOff size="20" v-else class="icon-off" />
185
+ </div>
186
+ </div>
187
+ </div>
188
+ </div>
189
+ </template>
190
+
191
+ <script setup lang="ts">
192
+ import { computed } from 'vue';
193
+ import { IconRefresh, IconMicOn, IconMicOff, IconCameraOn, IconCameraOff } from '@tencentcloud/uikit-base-component-vue3';
194
+ import {
195
+ useRoomParticipantState,
196
+ Avatar,
197
+ RoomParticipantRole,
198
+ DeviceStatus
199
+ } from 'tuikit-atomicx-vue3/room';
200
+
201
+ const {
202
+ localParticipant,
203
+ participantList,
204
+ getParticipantList,
205
+ transferOwner
206
+ } = useRoomParticipantState();
207
+
208
+ const handleRefresh = async () => {
209
+ await getParticipantList({ cursor: '' });
210
+ };
211
+ </script>
212
+
213
+ <style scoped>
214
+ .participant-list { display: flex; flex-direction: column; width: 400px; height: 100%; background-color: white;}.list-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid #e0e0e0;}.list-header h3 { margin: 0; font-size: 16px; font-weight: 600;}.list-content { flex: 1; overflow-y: auto; padding: 8px;}.participant-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 8px; transition: background-color 0.2s;}.participant-item:hover { background-color: #f5f5f5;}.participant-item.is-local { background-color: #e3f2fd;}.user-info { flex: 1; min-width: 0;}.user-name { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 500;}.badge { padding: 2px 6px; background-color: #4caf50; color: white; border-radius: 3px; font-size: 12px;}.role-badge { padding: 2px 6px; border-radius: 3px; font-size: 12px;}.role-badge.owner { background-color: #ff9800; color: white;}.role-badge.admin { background-color: #2196f3; color: white;}.device-status { display: flex; gap: 8px;}.icon-on { color: #4caf50;}.icon-off { color: #999;}.action-button { padding: 4px 8px; background: transparent; border: none; cursor: pointer; border-radius: 4px; color: #666;}.action-button:hover { background-color: #f0f0f0;}
215
+ </style>
216
+ ```
217
+
218
+ ### 步骤3:设置用户自定义信息
219
+
220
+ 开发者可以使用 [updateParticipantMetaData](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#updateParticipantMetaData) 接口设置用户的自定义数据,用于**实现职务**、**购买状态**等能力。更新之后 `metaData` 信息将被维护在 `participantList` 对应用户的响应式数据中。
221
+ ``` typescript
222
+ <template>
223
+ <div v-for="participant in participantList" :key="participant.userId">
224
+ <span>{{ participant.userName }}</span>
225
+ <span v-if="participant.metaData">
226
+ {{ JSON.parse(participant.metaData).level }}
227
+ </span>
228
+ </div>
229
+ </template>
230
+
231
+ <script setup lang="ts">
232
+ import { computed } from 'vue';
233
+ import { IconRefresh, IconMicOn, IconMicOff, IconCameraOn, IconCameraOff } from '@tencentcloud/uikit-base-component-vue3';
234
+ import {
235
+ useRoomParticipantState,
236
+ } from 'tuikit-atomicx-vue3/room';
237
+
238
+ const {
239
+ updateParticipantMetaData,
240
+ } = useRoomParticipantState();
241
+
242
+ await updateParticipantMetaData({
243
+ userId: '', // 指定用户 id
244
+ metaData: JSON.stringify({ level: 1 }), // 业务自定义信息
245
+ })
246
+ </script>
247
+ ```
248
+
249
+ ### 步骤4:管理成员身份
250
+
251
+ 房主可以通过 [setAdmin](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#setAdmin) 接口变更用户角色为管理员, 通过 [revokeAdmin](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#revokeAdmin) 方法撤销用户管理员身份。
252
+ ``` typescript
253
+ const { setAdmin, revokeAdmin } = useRoomParticipantState();
254
+
255
+ // 将普通用户设置为管理员
256
+ await setAdmin({ userId });
257
+
258
+ // 将管理员设置为普通用户
259
+ await revokeAdmin({ userId });
260
+ ```
261
+
262
+ ### 步骤5:管理成员媒体设备
263
+
264
+ 房主及管理员可以通过 [closeParticipantDevice](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#closeParticipantDevice) 接口远程控制其他成员的媒体设备,以维持会议环境的安静及有序。
265
+ ``` typescript
266
+ import { useRoomParticipantState, DeviceType } from 'tuikit-atomicx-vue3/room';
267
+ const { closeParticipantDevice } = useRoomParticipantState();
268
+
269
+ // 强制关闭指定成员的麦克风
270
+ async function handleCloseUserMicrophone(userId: string) {
271
+ await closeParticipantDevice({
272
+ userId,
273
+ deviceType: DeviceType.Microphone,
274
+ });
275
+ }
276
+
277
+ // 强制关闭指定成员的摄像头
278
+ async function handleCloseUserCamera(userId: string) {
279
+ await closeParticipantDevice({
280
+ userId,
281
+ deviceType: DeviceType.Camera,
282
+ });
283
+ }
284
+ ```
285
+
286
+ ### 步骤6:开启全局状态管理
287
+
288
+ 房主及管理员可通过 [disableAllDevices](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#disableAllDevices) 及 [disableAllMessages](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#disableAllMessages) 接口开启房间全局状态管理。
289
+
290
+ #### **禁用房间内所有普通用户的媒体设备**
291
+ ``` typescript
292
+ import { useRoomParticipantState, DeviceType } from 'tuikit-atomicx-vue3/room';
293
+ const { closeParticipantDevice } = useRoomParticipantState();
294
+
295
+ // 强制关闭所有普通成员的麦克风
296
+ async function handleDisableAllMicrophone() {
297
+ await disableAllDevices({
298
+ deviceType: DeviceType.Microphone,
299
+ disable: true,
300
+ });
301
+ }
302
+
303
+ // 解除全员麦克风禁用
304
+ async function handleEnableAllMicrophone() {
305
+ await disableAllDevices({
306
+ deviceType: DeviceType.Microphone,
307
+ disable: false,
308
+ });
309
+ }
310
+
311
+ // 强制关闭所有普通成员的摄像头
312
+ async function handleDisableAllCamera() {
313
+ await disableAllDevices({
314
+ deviceType: DeviceType.Camera,
315
+ disable: true,
316
+ });
317
+ }
318
+
319
+ // 解除全员摄像头禁用
320
+ async function handleEnableAllCamera() {
321
+ await disableAllDevices({
322
+ deviceType: DeviceType.Camera,
323
+ disable: false,
324
+ });
325
+ }
326
+ ```
327
+
328
+ #### **禁用房间内所有普通用户的会中聊天**
329
+ ``` typescript
330
+ import { useRoomParticipantState, DeviceType } from 'tuikit-atomicx-vue3/room';
331
+ const { disableAllMessages } = useRoomParticipantState();
332
+
333
+ // 强制禁用所有普通成员的聊天能力
334
+ async function handleDisableAllMessage() {
335
+ await disableAllMessages({
336
+ disable: true,
337
+ });
338
+ }
339
+ ```
340
+
341
+ ### **步骤7:**监控成员发言状态
342
+
343
+ 通过 [speakingUsers](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#speakingUsers) 可以实时获取房间内正在说话的用户及其音量大小。
344
+ ``` typescript
345
+ const { speakingUsers } = useRoomParticipantState();
346
+
347
+ // 判断用户是否正在说话
348
+ const isSpeaking = (userId: string) => speakingUsers.value.has(userId);
349
+ // 获取用户实时音量 (0-100)
350
+ const getVolume = (userId: string) => speakingUsers.value.get(userId) || 0;
351
+ ```
352
+
353
+ ### 步骤8:踢出房间内成员
354
+
355
+ 房主及管理员可以通过 [kickParticipant](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#kickParticipant) 接口将用户移出房间。
356
+ ``` typescript
357
+ const { kickParticipant } = useRoomParticipantState();
358
+
359
+ // 将用户踢出房间
360
+ await kickParticipant({ userId });
361
+ ```
362
+
363
+ ### 步骤9:邀请其他人加入房间
364
+
365
+ 实际业务中,您可能需要向未进房的用户发起呼叫邀请。Atomicx 提供了完整的呼叫系统支持,请查看 [会中呼叫](https://write.woa.com/document/197380078005506048)。
366
+
367
+ ## API 文档
368
+ <table>
369
+ <tr>
370
+ <td rowspan="1" colSpan="1" >**State/Component**</td>
371
+
372
+ <td rowspan="1" colSpan="1" >**功能描述**</td>
373
+
374
+ <td rowspan="1" colSpan="1" >**API 文档**</td>
375
+ </tr>
376
+
377
+ <tr>
378
+ <td rowspan="1" colSpan="1" >**useRoomParticipantState**</td>
379
+
380
+ <td rowspan="1" colSpan="1" >包含房间内用户数据,用户管理接口。</td>
381
+
382
+ <td rowspan="1" colSpan="1" >[API 文档](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#module-RoomParticipantState)</td>
383
+ </tr>
384
+ </table>
385
+
386
+
387
+ ## 开发建议
388
+
389
+ **权限校验:**在 UI 层建议通过 `participant.role` 判断当前用户的操作权限,对不具备管理权限的用户隐藏**踢人**或**禁言**按钮。
390
+ ``` typescript
391
+ <script setup>
392
+ import { RoomParticipantRole } from 'tuikit-atomicx-vue3/room';
393
+
394
+ const { localParticipant } = useRoomParticipantState();
395
+
396
+ // 判断当前用户是否有管理权限
397
+ const hasAdminPermission = computed(() => {
398
+ return localParticipant.value.role === RoomParticipantRole.Owner ||
399
+ localParticipant.value.role === RoomParticipantRole.Admin;
400
+ });
401
+ </script>
402
+
403
+ // 在模板中使用
404
+ <template>
405
+ <button v-if="hasAdminPermission" @click="handleKick">踢出</button>
406
+ <template>
407
+ ```
@@ -0,0 +1,291 @@
1
+ 本篇文档将详细指导您如何使用 Atomicx 的 [useRoomState](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#module-RoomState) 管理房间的完整生命周期,包括创建、加入、离开以及结束房间,以及处理关键的房间状态通知。以下时序图演示了房间从创建到销毁的主要流程。
2
+
3
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027337918/b5d730a6dfdc11f08775525400bf7822.png)
4
+
5
+
6
+ ## 功能介绍
7
+
8
+ [useRoomState](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#module-RoomState) 是 Atomicx 方案中负责房间管理的核心 Hook。它封装了复杂的底层信令流程,开发者可以通过简单的响应式数据和方法调用来驱动房间状态。
9
+ - **创建与加入:**通过 [createAndJoinRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#createAndJoinRoom) 方法创建并加入房间,或通过 [joinRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#joinRoom) 方法加入已有房间。
10
+
11
+ - **状态实时同步:**`useRoomState`Hook 内部维护 [currentRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#currentRoom) 响应式数据,自动同步房间名称、模式及成员数等信息。
12
+
13
+ - **权限分明的退出机制:**针对不同角色提供了清晰的操作边界。普通成员可以使用 [leaveRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#leaveRoom) 退出;而房主(主持人)则拥有 [endRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#endRoom) 权限,可以一键结束房间并销毁房间资源。
14
+
15
+
16
+ ## **前提条件**
17
+
18
+ 用户已经通过 [useLoginState](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#module-LoginState) 完成登录鉴权,请参考 [接入概览](https://write.woa.com/document/197379797539790848)。
19
+
20
+ ## 实现房间管理
21
+
22
+ ### 步骤1:导入 useRoomState
23
+ ``` typescript
24
+ import { useRoomState } from 'tuikit-atomicx-vue3/room';
25
+
26
+ const {
27
+ createAndJoinRoom,
28
+ joinRoom,
29
+ leaveRoom,
30
+ endRoom,
31
+ currentRoom
32
+ } = useRoomState();
33
+ ```
34
+
35
+ ### 步骤2:创建房间
36
+
37
+ 创建房间(房主):使用 [createAndJoinRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#createAndJoinRoom),调用成功后该用户将自动获得房主权限。
38
+
39
+ > **注意:**
40
+ >
41
+
42
+ > 创建房间时指定的 roomId 建议由业务后台生成并下发,以确保房间 Id 在全局应用中的唯一性与稳定性。
43
+ >
44
+
45
+ - **示例一:用户创建房间**
46
+
47
+ ``` typescript
48
+ import { useRoomState } from 'tuikit-atomicx-vue3/room';
49
+ const { createAndJoinRoom } = useRoomState();
50
+
51
+ await createAndJoinRoom({
52
+ roomId: 'YOUR_ROOM_ID', // 指定房间 Id,由业务后台生成
53
+ })
54
+ ```
55
+ - **示例二:用户创建房间并指定房间名称**
56
+
57
+ ``` typescript
58
+ import { useRoomState } from 'tuikit-atomicx-vue3/room';
59
+ const { createAndJoinRoom } = useRoomState();
60
+
61
+ await createAndJoinRoom({
62
+ roomId: 'YOUR_ROOM_ID', // 指定房间 Id,由业务后台生成
63
+ options: {
64
+ roomName: '我的临时房间'
65
+ }
66
+ })
67
+ ```
68
+ - **示例三:用户创建密码房间**
69
+
70
+ ``` typescript
71
+ import { useRoomState } from 'tuikit-atomicx-vue3/room';
72
+ const { createAndJoinRoom } = useRoomState();
73
+
74
+ await createAndJoinRoom({
75
+ roomId: 'YOUR_ROOM_ID', // 指定房间 Id,由业务后台生成
76
+ options: {
77
+ roomName: '我的临时房间',
78
+ password: '123456',
79
+ }
80
+ })
81
+ ```
82
+
83
+ > **说明:**
84
+ >
85
+
86
+ > 创建者在调用 [createAndJoinRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#createAndJoinRoom) 时会自动加入房间,无需输入密码。
87
+ >
88
+
89
+ - **示例四:用户创建房间并配置成员管理信息**
90
+
91
+ ``` typescript
92
+ import { useRoomState } from 'tuikit-atomicx-vue3/room';
93
+ const { createAndJoinRoom } = useRoomState();
94
+
95
+ await createAndJoinRoom({
96
+ roomId: 'YOUR_ROOM_ID', // 指定房间 Id,由业务后台生成
97
+ options: {
98
+ roomName: '我的临时房间',
99
+ password: '123456',
100
+ isAllMicrophoneDisabled: true, // 开启全员静音
101
+ isAllCameraDisabled: true, // 开启全员静画
102
+ isAllScreenShareDisabled: true, // 开启全员禁止屏幕共享
103
+ isAllMessageDisabled: true, // 开启全员禁止发会中消息
104
+ }
105
+ })
106
+ ```
107
+
108
+ > **说明:**
109
+ >
110
+
111
+ > 成员管理配置信息仅对普通成员生效,房主和管理员不受限制。如需在房间创建后修改成员管理配置或单独管理成员权限,请参考 [成员管理](https://write.woa.com/document/197380064613830656)。
112
+ >
113
+
114
+
115
+ ### 步骤3:用户加入已有房间
116
+
117
+ 登录用户可以调用 [joinRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#joinRoom) 加入已有房间。Atomicx 仅支持用户同时加入一个房间。
118
+ - **示例一:用户加入房间**
119
+
120
+ ``` typescript
121
+ import { useRoomState } from 'tuikit-atomicx-vue3/room';
122
+ const { joinRoom } = useRoomState();
123
+
124
+ await joinRoom({
125
+ roomId: 'YOUR_ROOM_ID', // 指定房间 Id,由业务后台生成
126
+ })
127
+ ```
128
+ - **示例二:用户加入密码房间**
129
+
130
+ ``` typescript
131
+ import { useRoomState } from 'tuikit-atomicx-vue3/room';
132
+ const { joinRoom } = useRoomState();
133
+
134
+ await joinRoom({
135
+ roomId: 'YOUR_ROOM_ID', // 指定房间 Id,由业务后台生成
136
+ password: '123456',
137
+ })
138
+ ```
139
+
140
+ ### 步骤4:更新房间信息
141
+
142
+ 房主可以在创建房间后使用 [updateRoomInfo](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#updateRoomInfo) 更新房间名称和密码。
143
+ ``` typescript
144
+ import { useRoomState } from 'tuikit-atomicx-vue3/room';
145
+ const { updateRoomInfo } = useRoomState();
146
+
147
+ await updateRoomInfo({
148
+ roomId: 'YOUR_ROOM_ID', // 指定房间 Id,由业务后台生成
149
+ options: {
150
+ roomName: '新的房间名称',
151
+ password: '234567',
152
+ },
153
+ })
154
+ ```
155
+
156
+ > **说明:**
157
+ >
158
+
159
+ > 房主必须在房间内才能调用 [updateRoomInfo](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#updateRoomInfo)。如果房主已离开房间,需要重新加入后才能更新房间信息。
160
+ >
161
+
162
+
163
+ ### 步骤5:离开房间
164
+
165
+ 房主及普通用户均可调用 [leaveRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#leaveRoom) 接口离开房间,使用该接口的前提是用户已经通过 [createAndJoinRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#createAndJoinRoom) 或者 [joinRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#joinRoom) 接口加入房间。
166
+ ``` typescript
167
+ import { useRoomState } from 'tuikit-atomicx-vue3/room';
168
+ const { leaveRoom } = useRoomState();
169
+
170
+ await leaveRoom();
171
+ ```
172
+
173
+ ### 步骤6:销毁房间
174
+
175
+ 仅房主可调用 [endRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#endRoom) 接口销毁房间,使用该接口的前提是用户已经通过 [createAndJoinRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#createAndJoinRoom) 创建房间或者已经获取房主身份。
176
+ ``` typescript
177
+ import { useRoomState } from 'tuikit-atomicx-vue3/room';
178
+ const { endRoom } = useRoomState();
179
+
180
+ await endRoom();
181
+ ```
182
+
183
+ > **说明:**
184
+ >
185
+ > - 如果房主离开房间但未调用 [endRoom](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#endRoom),房间将继续存在,直到满足自动回收条件(连续 6 小时无用户)。
186
+ > - 房主可以通过 [transferOwner](https://web.sdk.qcloud.com/trtc/live/web/doc/zh/index.html#transferOwner) 接口将房主身份转移给其他用户。
187
+
188
+
189
+ ### 步骤7:异常退出处理
190
+
191
+ #### 处理房间被销毁事件
192
+
193
+ 普通用户可通过监听 `RoomEvent.onRoomEnded` 事件处理房间被销毁的业务交互。
194
+ ``` typescript
195
+ import { useRoomState, RoomEvent } from 'tuikit-atomicx-vue3/room';
196
+ import { TUIMessageBox } from '@tencentcloud/uikit-base-component-vue3';
197
+ const { subscribeEvent, unsubscribeEvent } = useRoomState();
198
+
199
+ function onRoomEnded() {
200
+ TUIMessageBox.alert({
201
+ title: '通知',
202
+ content: '房主已解散房间',
203
+ });
204
+ }
205
+
206
+ // 在组件加载时监听 RoomEvent
207
+ subscribeEvent(RoomEvent.onRoomEnded, onRoomEnded);
208
+ // 在组件销毁时取消监听 RoomEvent
209
+ unsubscribeEvent(RoomEvent.onRoomEnded, onRoomEnded);
210
+ ```
211
+
212
+ #### 处理用户被踢退房事件
213
+
214
+ 普通用户可通过监听 `RoomParticipantEvent.onKickedFromRoom` 事件处理用户被踢出房间的业务交互。
215
+ ``` typescript
216
+ import { useRoomParticipantState, RoomParticipantEvent, KickedOutOfRoomReason } from 'tuikit-atomicx-vue3/room';
217
+ import { TUIMessageBox } from '@tencentcloud/uikit-base-component-vue3';
218
+
219
+ const { subscribeEvent, unsubscribeEvent } = useRoomParticipantState();
220
+
221
+ function onKickedFromRoom({ reason }: { reason: KickedOutOfRoomReason; message: string }) {
222
+ let notice = '';
223
+ switch (reason) {
224
+ case KickedOutOfRoomReason.KickedByAdmin:
225
+ notice = '您已被房主移出房间';
226
+ break;
227
+ case KickedOutOfRoomReason.ReplacedByAnotherDevice:
228
+ notice = '您的账号已在其他设备登录';
229
+ break;
230
+ case KickedOutOfRoomReason.KickedByServer:
231
+ notice = '您已被服务器移出房间';
232
+ break;
233
+ case KickedOutOfRoomReason.ConnectionTimeout:
234
+ notice = '网络连接超时,正在退出房间';
235
+ break;
236
+ case KickedOutOfRoomReason.InvalidStatusOnReconnect:
237
+ notice = '房间已解散或您在离线期间已被移出';
238
+ break;
239
+ case KickedOutOfRoomReason.RoomLimitExceeded:
240
+ notice = '房间人数已达上限,无法加入';
241
+ break;
242
+ default:
243
+ notice = '您已被移出房间';
244
+ break;
245
+ }
246
+ TUIMessageBox.alert({
247
+ title: '通知',
248
+ content: notice,
249
+ });
250
+ }
251
+
252
+ // 在组件加载时监听 RoomParticipantEvent
253
+ subscribeEvent(RoomParticipantEvent.onKickedFromRoom, onKickedFromRoom);
254
+ // 在组件销毁时取消监听 RoomParticipantEvent
255
+ unsubscribeEvent(RoomParticipantEvent.onKickedFromRoom, onKickedFromRoom);
256
+ ```
257
+
258
+ ## 进阶实现
259
+
260
+ 当前文档介绍的是快速创建并立即加入一个房间,适用于即时多人音视频互通场景。
261
+
262
+ 但在现实商业场景中,我们往往需要提前规划:设置房间的主题、预定特定的开始与结束时间、并邀请参与者。参与者可以在多人音视频房间开始前收到提醒,并准时接入。
263
+
264
+ Atomicx 提供了完整的预约房间能力,包括:
265
+ - **预定房间:**提前设定多人房间时间与参与人名单。
266
+
267
+ - **预约列表**:查看并管理自己名下的所有待开始的多人房间。
268
+
269
+ - **入会提醒:**支持开始前的自动提醒逻辑。
270
+
271
+
272
+ 如果您需要实现上述更复杂的商业多人音视频房间管理逻辑,请参考:[预定房间](https://write.woa.com/document/197380092150673408)。
273
+
274
+
275
+ ## 常见问题
276
+
277
+ ### 房间内已经没有用户但房间未被解散,房间是否会一直存在?
278
+
279
+ 房间内连续 6 小时无用户进入时,后台将尝试回收房间。
280
+
281
+ ### 房间内已经没有用户但房间未被解散,是否会产生费用消耗?
282
+
283
+ 没有用户但是未被解散的房间仅占用套餐群组数,不产生分钟数消耗和额外费用消耗。
284
+
285
+ ### 一个用户可以同时加入多个房间吗?
286
+
287
+ Atomicx 提供的 `useRoomState` 为单例接口,仅支持用户同时加入一个房间。若您需要支持一个用户同时加入多个房间,欢迎 [联系我们](https://cloud.tencent.com/document/product/647/19906) 提交反馈。
288
+
289
+ ### 最多支持多少人同时加入房间?
290
+
291
+ 房间内用户数量上限和您的套餐包相关,具体请查看 [TUIRoomKit 套餐包说明](https://cloud.tencent.com/document/product/647/104842#function)。