@tencent-rtc/mcp 1.6.8 → 1.7.0
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/CHANGELOG.md +25 -0
- package/README.md +53 -39
- package/knowledge/build-index.js +30 -6
- package/knowledge/chunker.js +82 -14
- package/knowledge/chunking-policy.js +100 -0
- package/knowledge/content-loader.js +3 -3
- package/knowledge/frontmatter-meta.js +167 -0
- package/knowledge/path-meta.js +28 -6
- package/knowledge/search/exact-lookup.js +9 -227
- package/knowledge/search/filter-pool.js +12 -29
- package/knowledge/search/framework-fallback.js +22 -0
- package/knowledge/search/intent-router.js +13 -0
- package/knowledge/search/query-normalizer.js +56 -3
- package/knowledge/search/search-core.js +391 -0
- package/knowledge/search/search-knowledge.js +292 -363
- package/knowledge/search/search-message.js +87 -0
- package/knowledge/search/search-pass.js +428 -0
- package/knowledge/search/search-types.js +1 -0
- package/knowledge/search/url-row-scorer.js +258 -0
- package/package.json +1 -1
- package/resource/_schema/feature-aliases.yaml +1 -1
- package/resource/index/manifest.json +1 -1
- package/resource/knowledge/callkit/best-practice/callkit-miniprogram/uniapp-shrink.md +60 -0
- package/resource/knowledge/callkit/best-practice/common/call-autoplay-blocked.md +77 -0
- package/resource/knowledge/callkit/best-practice/common/call-message-in-chat.md +78 -0
- package/resource/knowledge/callkit/best-practice/common/call-vs-calls.md +110 -0
- package/resource/knowledge/callkit/best-practice/common/callengine-call-flow.md +123 -0
- package/resource/knowledge/callkit/best-practice/common/callengine-log-level.md +67 -0
- package/resource/knowledge/callkit/best-practice/common/callkit-get-engine-instance.md +81 -0
- package/resource/knowledge/callkit/best-practice/common/callkit-get-roomid.md +78 -0
- package/resource/knowledge/callkit/best-practice/common/callkit-limitations.md +37 -0
- package/resource/knowledge/callkit/best-practice/common/callkit-user-register-and-kicked.md +98 -0
- package/resource/knowledge/chat/best-practice/common/avchatroom-message-loss-diagnosis.md +65 -0
- package/resource/knowledge/chat/best-practice/common/group-conversation-cleanup-on-system-notice.md +62 -0
- package/resource/knowledge/chat/best-practice/common/image-message-url-lifecycle.md +59 -0
- package/resource/knowledge/chat/best-practice/common/login-repeat-2025-diagnosis.md +61 -0
- package/resource/knowledge/chat/best-practice/common/message-read-report-and-receipt.md +64 -0
- package/resource/knowledge/chat/best-practice/common/message-receive-event.md +65 -0
- package/resource/knowledge/chat/best-practice/common/message-risk-error-and-render.md +65 -0
- package/resource/knowledge/chat/best-practice/common/message-unread-count.md +71 -0
- package/resource/knowledge/chat/best-practice/miniprogram/audio-message-send.md +113 -0
- package/resource/knowledge/chat/best-practice/miniprogram/login-timeout-2801-diagnosis.md +63 -0
- package/resource/knowledge/chat/best-practice/miniprogram/media-upload-fail-diagnosis.md +64 -0
- package/resource/knowledge/chat/best-practice/web/audio-message-send.md +118 -0
- package/resource/knowledge/chat/urls/sdk/web.md +1 -1
- package/resource/knowledge/livekit/best-practice/android/voice-room-anchor-start.md +120 -0
- package/resource/knowledge/livekit/best-practice/common/admin-take-seat.md +73 -0
- package/resource/knowledge/livekit/best-practice/common/audience-leave-live.md +81 -0
- package/resource/knowledge/livekit/best-practice/common/voice-room-no-audio-troubleshoot.md +100 -0
- package/resource/knowledge/livekit/best-practice/common/voice-room-seat-list-change.md +65 -0
- package/resource/knowledge/livekit/best-practice/flutter/voice-room-anchor-start.md +122 -0
- package/resource/knowledge/livekit/best-practice/ios/voice-room-anchor-start.md +126 -0
- package/resource/knowledge/roomkit/best-practice/common/room-ghost-member.md +70 -0
- package/resource/knowledge/roomkit/best-practice/common/room-limit-and-multi.md +83 -0
- package/resource/knowledge/roomkit/best-practice/common/room-screen-share-preview.md +83 -0
- package/resource/knowledge/roomkit/best-practice/common/room-status-after-all-leave.md +69 -0
- package/resource/knowledge/roomkit/best-practice/vue/room-uikit-vs-atomicx.md +111 -0
- package/resource/knowledge/rtcengine/web/plugin/30-advanced-cross-room-link.md +2 -0
- package/resource/knowledge/rtcengine/web/plugin/39-advanced-video-decoder.md +2 -0
- package/server.js +27 -22
- package/tools/common/finalize_answer.js +9 -1
- package/tools/common/search_trtc_knowledge.js +1 -1
- package/tools/definitions/finalize_answer_def.js +2 -2
- package/tools/definitions/integration-boundary.js +2 -1
- package/tools/definitions/search_trtc_knowledge_def.js +1 -1
- package/utils/report-cls-client.js +1 -1
- package/utils/report-es-client.js +1 -1
- package/cursor-setting.png +0 -0
- package/mcp-server-prompt.png +0 -0
- package/resource/knowledge/callkit/best-practice/web/callengine-invitation.md +0 -80
- package/resource/knowledge/callkit/best-practice/web/callengine-log-control.md +0 -24
- package/resource/knowledge/callkit/best-practice/web/callkit-call-vs-calls.md +0 -116
- package/resource/knowledge/callkit/preset/react/uikit-api-reference.md +0 -444
- package/resource/knowledge/callkit/preset/vue/uikit-api-reference.md +0 -464
- package/resource/knowledge/chat/best-practice/web/image-message-url-handling.md +0 -16
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Web/Mini Program Chat SDK: Message Sending Error (80001/80004) and Content Moderation Rendering Strategy(发送消息报错 80001、80004 / 触发审核的消息渲染标识)"
|
|
3
|
+
product: chat
|
|
4
|
+
frameworks: [web, miniprogram]
|
|
5
|
+
scope: platform_common
|
|
6
|
+
tags: [sendMessage, 80001, 80004, hasRiskContent, MESSAGE_MODIFIED, cloud moderation, text moderation, image moderation, async moderation, audio message, video message]
|
|
7
|
+
version_range: ">=3.0.0"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Web/Mini Program Chat SDK: Message Sending Error (80001/80004) and Content Moderation Rendering Strategy
|
|
11
|
+
|
|
12
|
+
## 1. Key Takeaways
|
|
13
|
+
|
|
14
|
+
- Text sending error `80001` indicates the text has hit a sensitive content moderation policy; investigate the message content and cloud-side sensitive word configuration.
|
|
15
|
+
- Image sending error `80004` indicates the image has hit a sensitive content moderation policy; investigate the image content and cloud-side image moderation rules.
|
|
16
|
+
- The standard field for determining whether a message has been flagged by moderation on the UI side is `message.hasRiskContent`.
|
|
17
|
+
- To receive `80001/80004` in `sendMessage`'s `catch` during synchronous moderation, you must enable "Deliver Blocking Error Code" in the IM console (Console > Cloud Moderation > Moderation Result Configuration > Deliver Blocking Error Code).
|
|
18
|
+
|
|
19
|
+
## 2. Field / API Reference
|
|
20
|
+
|
|
21
|
+
| Field / Capability | Purpose | Description |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| Error code `80001` | Text moderation blocking signal | Returned when a text message hits a sensitive policy |
|
|
24
|
+
| Error code `80004` | Image moderation blocking signal | Returned when an image message hits a sensitive policy |
|
|
25
|
+
| `message.hasRiskContent` | Risk content flag | Used by the UI to determine whether a message has been flagged by moderation |
|
|
26
|
+
| `EVENT.MESSAGE_MODIFIED` | Message modified notification event | After async moderation hits, the SDK delivers message field updates via this event |
|
|
27
|
+
| "Deliver Blocking Error Code" switch | Synchronous error return control | Must be enabled for `sendMessage.catch` to receive moderation blocking error codes |
|
|
28
|
+
|
|
29
|
+
## 3. Mechanism & Sequence
|
|
30
|
+
|
|
31
|
+
Text messages use synchronous moderation: send message -> moderation hit -> `sendMessage.catch` returns `80001`; the returned `message.hasRiskContent=true`. In the text synchronous moderation hit scenario, the `EVENT.MESSAGE_MODIFIED` event is not dispatched.
|
|
32
|
+
Image messages default to synchronous moderation: send message -> if moderation completes and hits within 2 seconds -> `sendMessage.catch` returns `80004`; if moderation does not complete within 2 seconds -> automatically switches to async moderation; after async moderation hits, the update is delivered via `EVENT.MESSAGE_MODIFIED`.
|
|
33
|
+
Audio/video messages default to async moderation: send message -> backend performs async moderation -> after moderation hits, the update is delivered via `EVENT.MESSAGE_MODIFIED`.
|
|
34
|
+
|
|
35
|
+
## 4. Standard Usage
|
|
36
|
+
|
|
37
|
+
1. Enable "Deliver Blocking Error Code" in the console to ensure `sendMessage.catch` can detect the error code during synchronous moderation hits.
|
|
38
|
+
2. When sending text/image messages, read the error code and the returned `message` in the `catch` branch; if `message.hasRiskContent=true`, immediately update the on-screen message status.
|
|
39
|
+
3. Listen to `EVENT.MESSAGE_MODIFIED`, iterate over `event.data`, and update the corresponding on-screen message when `message.hasRiskContent=true` is found.
|
|
40
|
+
4. When the text/image hit rate is abnormal, review the sensitive word library and image moderation rules respectively, and coordinate cloud moderation strategy adjustments.
|
|
41
|
+
5. Use `hasRiskContent` uniformly for UI rendering decisions; do not rely on a single error code for long-term state determination.
|
|
42
|
+
|
|
43
|
+
## 5. Expected Results
|
|
44
|
+
|
|
45
|
+
- When text hits a sensitive word, `sendMessage.catch` observes `80001` and the message status is updated to moderation-blocked.
|
|
46
|
+
- When an image hits a sensitive rule, it is received via the synchronous path as `80004`, or via the async path through `MESSAGE_MODIFIED` with `hasRiskContent=true` update.
|
|
47
|
+
- After async moderation hits for audio/video, the UI correctly updates the blocked status via `MESSAGE_MODIFIED`.
|
|
48
|
+
- For the same message, both synchronous and async paths ultimately render a consistent state based on `hasRiskContent`.
|
|
49
|
+
|
|
50
|
+
## 6. Common Pitfalls
|
|
51
|
+
|
|
52
|
+
- Pitfall 1: Not enabling "Deliver Blocking Error Code" but expecting `sendMessage.catch` to always return `80001/80004`.
|
|
53
|
+
- Pitfall 2: Only handling `sendMessage.catch` without listening to `MESSAGE_MODIFIED`, causing missed rendering for async moderation hits.
|
|
54
|
+
- Pitfall 3: Rendering long-term state based solely on error codes without using `hasRiskContent` as the ultimate state source.
|
|
55
|
+
|
|
56
|
+
## 7. Problem Definition (retrieval hint)
|
|
57
|
+
|
|
58
|
+
What causes the Web Chat SDK to return `80001` when sending text and `80004` when sending images? How should the UI determine whether a message has been flagged by content moderation (risk content)?
|
|
59
|
+
|
|
60
|
+
## 8. Alternative Queries (retrieval recall)
|
|
61
|
+
|
|
62
|
+
- What causes text sending failure 80001?
|
|
63
|
+
- What causes image sending failure 80004?
|
|
64
|
+
- How does the frontend identify when a message is blocked by moderation?
|
|
65
|
+
- When does `message.hasRiskContent` get updated?
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Web/Mini Program Chat SDK: Total Unread Message Count and C2C/Group Split Statistics(unreadCount / 未读总数 / 单聊未读 / 群聊未读)"
|
|
3
|
+
product: chat
|
|
4
|
+
frameworks: [web, miniprogram]
|
|
5
|
+
scope: platform_common
|
|
6
|
+
tags: [getTotalUnreadMessageCount, TOTAL_UNREAD_MESSAGE_COUNT_UPDATED, unreadCount, total unread, C2C unread, group unread]
|
|
7
|
+
version_range: ">=3.0.0"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Web/Mini Program Chat SDK: Total Unread Message Count and C2C/Group Split Statistics
|
|
11
|
+
|
|
12
|
+
## 1. Key Takeaways
|
|
13
|
+
|
|
14
|
+
- Use `getTotalUnreadMessageCount` to get the total unread message count.
|
|
15
|
+
- The SDK does not currently provide a direct API for "C2C-only unread total" or "group-only unread total".
|
|
16
|
+
- The recommended pattern is "fetch once on initialization + continuous event updates": call `getTotalUnreadMessageCount` during initialization, then maintain the total unread count via `TOTAL_UNREAD_MESSAGE_COUNT_UPDATED`.
|
|
17
|
+
- `getTotalUnreadMessageCount` depends on the SDK's conversation list data; if the cloud conversation list has not finished syncing when called, the return value may be `0`.
|
|
18
|
+
- The SDK syncs the conversation list in pages; each sync that causes a total unread change dispatches `TOTAL_UNREAD_MESSAGE_COUNT_UPDATED`.
|
|
19
|
+
|
|
20
|
+
## 2. Field / API Reference
|
|
21
|
+
|
|
22
|
+
| Field / Capability | Purpose | Description |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| `getTotalUnreadMessageCount` | Get current total unread count | Depends on the locally synced conversation list state |
|
|
25
|
+
| `TOTAL_UNREAD_MESSAGE_COUNT_UPDATED` | Total unread update event | Triggered after conversation list page sync or unread count changes |
|
|
26
|
+
| `CONVERSATION_LIST_UPDATED` | Conversation list update event | Can be used to get all conversations and perform C2C/group split statistics |
|
|
27
|
+
| `conversation.type` | Conversation type identifier | Used to filter C2C or group conversations |
|
|
28
|
+
| `conversation.unreadCount` | Per-conversation unread count | Summed up to get C2C-dimension or group-dimension total unread count |
|
|
29
|
+
|
|
30
|
+
## 3. Mechanism & Sequence
|
|
31
|
+
|
|
32
|
+
App starts -> SDK syncs conversation list (paginated) -> Business calls `getTotalUnreadMessageCount` during initialization to get the initial value (may be 0) -> Each time a page sync causes total unread change, SDK dispatches `TOTAL_UNREAD_MESSAGE_COUNT_UPDATED` -> Business updates total unread display in real time.
|
|
33
|
+
If C2C/group dimension unread is needed: listen to `CONVERSATION_LIST_UPDATED` -> get all conversations -> filter by `conversation.type` and sum `conversation.unreadCount`.
|
|
34
|
+
|
|
35
|
+
## 4. Standard Usage
|
|
36
|
+
|
|
37
|
+
1. During app initialization, call `getTotalUnreadMessageCount` to get the current available total unread initial value.
|
|
38
|
+
2. Listen to `TOTAL_UNREAD_MESSAGE_COUNT_UPDATED`; use the event value as the continuous update source for total unread count.
|
|
39
|
+
3. Listen to `CONVERSATION_LIST_UPDATED` to get the full conversation list.
|
|
40
|
+
4. Filter by `conversation.type` to separate C2C and group conversations, then sum each conversation's `unreadCount` to get the C2C unread total and group unread total.
|
|
41
|
+
5. When initialization returns `0`, do not immediately conclude "no unread"; use the statistics result after the conversation list sync event as the authoritative value.
|
|
42
|
+
|
|
43
|
+
## 5. Expected Results
|
|
44
|
+
|
|
45
|
+
- `getTotalUnreadMessageCount` has been called during initialization, and the UI displays the initial value.
|
|
46
|
+
- During the conversation list page sync process, `TOTAL_UNREAD_MESSAGE_COUNT_UPDATED` continuously drives total unread changes.
|
|
47
|
+
- C2C and group unread totals are stably derived from the `CONVERSATION_LIST_UPDATED + unreadCount` aggregation result.
|
|
48
|
+
- When `0` appears during initialization, the unread count correctly refreshes to the real value once syncing completes.
|
|
49
|
+
|
|
50
|
+
## 6. Common Pitfalls
|
|
51
|
+
|
|
52
|
+
- Pitfall 1: Assuming the SDK provides a ready-made API for "C2C unread total" or "group unread total".
|
|
53
|
+
- Pitfall 2: Treating the `getTotalUnreadMessageCount` result of `0` during initialization as the final result.
|
|
54
|
+
- Pitfall 3: Only fetching the total unread count once during initialization without listening to `TOTAL_UNREAD_MESSAGE_COUNT_UPDATED`.
|
|
55
|
+
|
|
56
|
+
## 7. Problem Definition (retrieval hint)
|
|
57
|
+
|
|
58
|
+
How does the Web Chat SDK get the total unread message count? Is there an API to get only the C2C unread total or group unread total?
|
|
59
|
+
|
|
60
|
+
## 8. Alternative Queries (retrieval recall)
|
|
61
|
+
|
|
62
|
+
- How to get the total IM unread message count?
|
|
63
|
+
- Is there an official API for "C2C-only unread" or "group-only unread"?
|
|
64
|
+
- Why does `getTotalUnreadMessageCount` return 0 during initialization?
|
|
65
|
+
- Should the total unread count be updated via events or by polling the API?
|
|
66
|
+
|
|
67
|
+
## 9. References
|
|
68
|
+
|
|
69
|
+
- getTotalUnreadMessageCount: `https://web.sdk.qcloud.com/im/doc/v3/zh-cn/SDK.html#getTotalUnreadMessageCount`
|
|
70
|
+
- TOTAL_UNREAD_MESSAGE_COUNT_UPDATED: `https://web.sdk.qcloud.com/im/doc/v3/zh-cn/module-EVENT.html#.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED`
|
|
71
|
+
- CONVERSATION_LIST_UPDATED: `https://web.sdk.qcloud.com/im/doc/v3/zh-cn/module-EVENT.html#.CONVERSATION_LIST_UPDATED`
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Mini Program: Standard Approach for Sending Audio Messages with IM SDK(recorderManager / createAudioMessage / sendMessage / 小程序发送语音消息)"
|
|
3
|
+
product: chat
|
|
4
|
+
frameworks: [miniprogram]
|
|
5
|
+
scope: platform_specific
|
|
6
|
+
tags: [audio, voice, recorderManager, createAudioMessage, sendMessage, aac, miniprogram]
|
|
7
|
+
version_range: ">=3.0.0"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Mini Program: Standard Approach for Sending Audio Messages with IM SDK
|
|
11
|
+
|
|
12
|
+
## 1. Key Takeaways
|
|
13
|
+
|
|
14
|
+
- On the mini program side, use the official WeChat `RecorderManager` for recording, then call `createAudioMessage` in the `onStop` callback to create the audio message.
|
|
15
|
+
- After message creation, send it via `sendMessage`; the send result is determined by the Promise success/failure callback.
|
|
16
|
+
- Using `aac` audio format enables cross-platform interoperability across IM on Android, iOS, Mini Program, and Web.
|
|
17
|
+
- Recording parameters must be explicitly configured: `duration`, `sampleRate`, `numberOfChannels`, `encodeBitRate`, `format`; also listen to `onError` to handle recording exceptions.
|
|
18
|
+
|
|
19
|
+
## 2. Field / API Reference
|
|
20
|
+
|
|
21
|
+
| Field / Capability | Purpose | Description |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| `wx.getRecorderManager()` | Recording entry | Gets the globally unique recorder manager instance |
|
|
24
|
+
| `recordOptions.format` | Audio format control | Set to `aac` for cross-platform interoperability |
|
|
25
|
+
| `recorderManager.onStop(res)` | Recording result callback | Use `res` in the callback to create the audio message |
|
|
26
|
+
| `chat.createAudioMessage({...})` | Create message instance | Generates an audio message object ready for rendering and sending |
|
|
27
|
+
| `chat.sendMessage(message)` | Send message | Returns a Promise; `then` for success, `catch` for failure |
|
|
28
|
+
|
|
29
|
+
## 3. Mechanism & Sequence
|
|
30
|
+
|
|
31
|
+
Initialize `RecorderManager` -> Configure recording parameters -> Start recording -> Listen to `onStop` to get the recording result -> Call `createAudioMessage` to create the audio message -> Call `sendMessage` to send -> Update UI and logs based on send result.
|
|
32
|
+
|
|
33
|
+
## 4. Standard Usage
|
|
34
|
+
|
|
35
|
+
1. Get the recorder manager and configure recording parameters with `format` set to `aac`.
|
|
36
|
+
2. Register `onError` and `onStop` callbacks; create the audio message based on the recording result in `onStop`.
|
|
37
|
+
3. Call `sendMessage` to send the audio message and handle success/failure callbacks.
|
|
38
|
+
4. Render the message instance on screen, and prompt retry on failure.
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
// 示例:使用微信官方的 RecorderManager 进行录音
|
|
42
|
+
// 参考 https://developers.weixin.qq.com/minigame/dev/api/media/recorder/RecorderManager.start.html
|
|
43
|
+
// 1. 获取全局唯一的录音管理器 RecorderManager
|
|
44
|
+
const recorderManager = wx.getRecorderManager();
|
|
45
|
+
|
|
46
|
+
// 录音部分参数
|
|
47
|
+
const recordOptions = {
|
|
48
|
+
duration: 60000, // 录音的时长,单位 ms,最大值 600000(10 分钟)
|
|
49
|
+
sampleRate: 44100, // 采样率
|
|
50
|
+
numberOfChannels: 1, // 录音通道数
|
|
51
|
+
encodeBitRate: 192000, // 编码码率
|
|
52
|
+
format: 'aac' // 音频格式,选择此格式创建的音频消息可以在 IM 全平台互通
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// 2.1 监听录音错误事件
|
|
56
|
+
recorderManager.onError(function(errMsg) {
|
|
57
|
+
console.warn('recorder error:', errMsg);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// 2.2 监听录音结束事件,录音结束后创建并发送音频消息
|
|
61
|
+
recorderManager.onStop(function(res) {
|
|
62
|
+
console.log('recorder stop', res);
|
|
63
|
+
|
|
64
|
+
// 4. 创建消息实例,接口返回的实例可以上屏
|
|
65
|
+
const message = chat.createAudioMessage({
|
|
66
|
+
to: 'user1',
|
|
67
|
+
conversationType: TencentCloudChat.TYPES.CONV_C2C,
|
|
68
|
+
// 消息优先级,用于群聊
|
|
69
|
+
// priority: TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL,
|
|
70
|
+
payload: {
|
|
71
|
+
file: res
|
|
72
|
+
},
|
|
73
|
+
// 消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
|
|
74
|
+
// cloudCustomData: 'your cloud custom data'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// 5. 发送消息
|
|
78
|
+
chat.sendMessage(message).then(function(imResponse) {
|
|
79
|
+
// 发送成功
|
|
80
|
+
console.log(imResponse);
|
|
81
|
+
}).catch(function(imError) {
|
|
82
|
+
// 发送失败
|
|
83
|
+
console.warn('sendMessage error:', imError);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// 3. 开始录音
|
|
88
|
+
recorderManager.start(recordOptions);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 5. Expected Results
|
|
92
|
+
|
|
93
|
+
- After recording ends, `onStop` is triggered reliably and a voice message instance is created successfully.
|
|
94
|
+
- On successful send, the `sendMessage` Promise enters `then` and the message renders on screen.
|
|
95
|
+
- The audio message can be played on Android, iOS, Mini Program, and Web (using `aac` format).
|
|
96
|
+
- On recording exceptions, `onError` provides clear logs with no silent failures.
|
|
97
|
+
|
|
98
|
+
## 6. Common Pitfalls
|
|
99
|
+
|
|
100
|
+
- Pitfall 1: Not creating the message in the `onStop` callback, resulting in no valid audio file at send time.
|
|
101
|
+
- Pitfall 2: Not using `aac` for the audio format, causing cross-platform interoperability issues.
|
|
102
|
+
- Pitfall 3: Only calling `createAudioMessage` without calling `sendMessage`, mistakenly thinking the message has been sent.
|
|
103
|
+
|
|
104
|
+
## 7. Problem Definition (retrieval hint)
|
|
105
|
+
|
|
106
|
+
When integrating IM SDK in a mini program, how to complete voice recording, create an audio message, and send it while ensuring cross-platform interoperability.
|
|
107
|
+
|
|
108
|
+
## 8. Alternative Queries (retrieval recall)
|
|
109
|
+
|
|
110
|
+
- How to send an audio message with the mini program IM SDK?
|
|
111
|
+
- How to use `createAudioMessage` to send a message after recording in a mini program?
|
|
112
|
+
- How to integrate `RecorderManager` recording result with IM sending?
|
|
113
|
+
- What audio format allows interoperability with Android/iOS/Web?
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Mini Program: IM SDK Login Timeout 2801 Diagnosis and Fix(小程序体验版和正式版登录超时 / 开发版正常)"
|
|
3
|
+
product: chat
|
|
4
|
+
frameworks: [miniprogram]
|
|
5
|
+
scope: platform_specific
|
|
6
|
+
tags: [login, timeout, 2801, websocket, domain allowlist, debug mode, ipv6]
|
|
7
|
+
version_range: ">=3.0.0"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Mini Program: IM SDK Login Timeout 2801 Diagnosis and Fix
|
|
11
|
+
|
|
12
|
+
## 1. Key Takeaways
|
|
13
|
+
|
|
14
|
+
- The primary item to check in this scenario is whether the `websocket` domain allowlist is fully configured in the mini program management backend.
|
|
15
|
+
- The validation policies differ between dev builds and preview/production builds; a successful login in the dev build does not guarantee the allowlist is correctly configured.
|
|
16
|
+
- Preview builds can enable debug mode for verification: debug mode bypasses domain allowlist validation and can be used to quickly determine whether the issue is caused by the allowlist.
|
|
17
|
+
- The dedicated domain `wss://${SDKAppID}w4c.my-imcloud.com` requires SDK `v3.4.6` or above.
|
|
18
|
+
- The IPv6 domain `wss://wssv6.im.qcloud.com` requires SDK `v3.4.9` or above.
|
|
19
|
+
|
|
20
|
+
## 2. Field / API Reference
|
|
21
|
+
|
|
22
|
+
| Field / Capability | Purpose | Description |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| Error code `2801` | Login timeout signal | When this occurs in preview/production builds, prioritize checking network connectivity and domain allowlist |
|
|
25
|
+
| `websocket` domain allowlist | Connection access control | Incomplete allowlist configuration causes connection failure or timeout in non-dev builds |
|
|
26
|
+
| Preview build debug mode | Diagnostic tool | Bypasses domain allowlist validation; used to verify whether the allowlist is the root cause |
|
|
27
|
+
| `wss://${SDKAppID}w4c.my-imcloud.com` | Dedicated domain | Supported from SDK `v3.4.6+` |
|
|
28
|
+
| `wss://wssv6.im.qcloud.com` | IPv6 domain | Supported from SDK `v3.4.9+` |
|
|
29
|
+
|
|
30
|
+
## 3. Mechanism & Sequence
|
|
31
|
+
|
|
32
|
+
Dev build can log in -> Preview/production build login times out (2801) -> Check `websocket` domain allowlist in mini program management backend -> Enable debug mode in preview build and retest -> If debug mode resolves the issue, confirm it is an allowlist configuration problem.
|
|
33
|
+
|
|
34
|
+
## 4. Standard Usage
|
|
35
|
+
|
|
36
|
+
1. Log in to the mini program management backend and check whether the `websocket` domain allowlist is fully configured. Reference: `https://cloud.tencent.com/document/product/269/117335`.
|
|
37
|
+
2. Enable debug mode in the preview build and retest login.
|
|
38
|
+
3. If login recovers after enabling debug mode, complete/correct the `websocket` domain configuration per allowlist specifications.
|
|
39
|
+
4. Verify the login path again in both preview and production builds to confirm 2801 no longer occurs.
|
|
40
|
+
|
|
41
|
+
## 5. Expected Results
|
|
42
|
+
|
|
43
|
+
- Preview build can log in stably with debug mode disabled.
|
|
44
|
+
- Production build login no longer shows the 2801 timeout.
|
|
45
|
+
- The mini program backend `websocket` domain allowlist is fully consistent with the current connected domains.
|
|
46
|
+
- If using a dedicated domain or IPv6 domain, the SDK version meets `v3.4.6+` / `v3.4.9+` respectively.
|
|
47
|
+
|
|
48
|
+
## 6. Common Pitfalls
|
|
49
|
+
|
|
50
|
+
- Pitfall 1: Assuming the domain allowlist is correctly configured just because the dev build can log in.
|
|
51
|
+
- Pitfall 2: Only verifying in debug mode and then directly publishing to production.
|
|
52
|
+
- Pitfall 3: Using a dedicated domain or IPv6 domain while ignoring the minimum SDK version requirement.
|
|
53
|
+
|
|
54
|
+
## 7. Problem Definition (retrieval hint)
|
|
55
|
+
|
|
56
|
+
When integrating IM SDK in a mini program, the dev build logs in successfully, but the preview and production builds get a login timeout (2801).
|
|
57
|
+
|
|
58
|
+
## 8. Alternative Queries (retrieval recall)
|
|
59
|
+
|
|
60
|
+
- How to handle IM login 2801 in a preview mini program?
|
|
61
|
+
- Why can the dev build log in but the preview and production builds timeout?
|
|
62
|
+
- Is preview build login timeout related to the websocket domain allowlist?
|
|
63
|
+
- Can a missing websocket allowlist entry cause IM login failure in a mini program?
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Mini Program: IM SDK Media Upload Failure Diagnosis and Fix (Image/Video/Audio/File)(小程序体验版和正式版偶现发送图片、视频、语音、文件失败 / 开发版正常)"
|
|
3
|
+
product: chat
|
|
4
|
+
frameworks: [miniprogram]
|
|
5
|
+
scope: platform_specific
|
|
6
|
+
tags: [upload, media, image, video, audio, file, uploadFile, domain allowlist, debug mode, COS dedicated domain]
|
|
7
|
+
version_range: ">=3.0.0"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Mini Program: IM SDK Media Upload Failure Diagnosis and Fix (Image/Video/Audio/File)
|
|
11
|
+
|
|
12
|
+
## 1. Key Takeaways
|
|
13
|
+
|
|
14
|
+
- The primary item to check in this scenario is whether the `uploadFile` domain allowlist is fully configured in the mini program management backend.
|
|
15
|
+
- The validation policies differ between dev builds and preview/production builds; successful uploads in the dev build do not guarantee the allowlist is correctly configured.
|
|
16
|
+
- Preview builds can enable debug mode for verification: debug mode bypasses domain allowlist validation and can be used to quickly determine whether the issue is caused by the `uploadFile` domain configuration.
|
|
17
|
+
- Starting from 2024-09-10, newly created apps are assigned a COS dedicated domain `https://${SDKAppID}-cn.rich.my-imcloud.com` by default.
|
|
18
|
+
- When using the COS dedicated domain, it must be added to the mini program `uploadFile` allowed domain allowlist.
|
|
19
|
+
|
|
20
|
+
## 2. Field / API Reference
|
|
21
|
+
|
|
22
|
+
| Field / Capability | Purpose | Description |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| `uploadFile` domain allowlist | Upload channel access control | Incomplete allowlist configuration causes upload failures in preview/production builds |
|
|
25
|
+
| Preview build debug mode | Diagnostic tool | Bypasses domain allowlist validation; used to verify whether the allowlist is the root cause |
|
|
26
|
+
| `https://${SDKAppID}-cn.rich.my-imcloud.com` | COS dedicated domain | Assigned by default for new apps; must be added to the `uploadFile` allowlist |
|
|
27
|
+
| Media message types (image/video/audio/file) | Affected scope | All share the `uploadFile` path and are affected by allowlist configuration |
|
|
28
|
+
|
|
29
|
+
## 3. Mechanism & Sequence
|
|
30
|
+
|
|
31
|
+
Dev build uploads successfully -> Preview/production build uploads fail -> Check `uploadFile` domain allowlist in mini program management backend -> Enable debug mode in preview build and retest -> If debug mode resolves the issue, confirm it is an allowlist configuration problem.
|
|
32
|
+
|
|
33
|
+
## 4. Standard Usage
|
|
34
|
+
|
|
35
|
+
1. Log in to the mini program management backend and check whether the `uploadFile` allowed domains are fully configured. Reference: `https://cloud.tencent.com/document/product/269/117335`.
|
|
36
|
+
2. Verify and add the upload domains actually used by the current app, with special attention to confirming that the COS dedicated domain `https://${SDKAppID}-cn.rich.my-imcloud.com` is allowlisted.
|
|
37
|
+
3. Enable debug mode in the preview build and retest image/video/audio/file uploads.
|
|
38
|
+
4. If uploads recover after enabling debug mode, complete/correct the `uploadFile` domain configuration per allowlist specifications.
|
|
39
|
+
5. After disabling debug mode, verify the upload path again in both preview and production builds.
|
|
40
|
+
|
|
41
|
+
## 5. Expected Results
|
|
42
|
+
|
|
43
|
+
- Preview build can upload images/videos/audio/files successfully with debug mode disabled.
|
|
44
|
+
- Production build upload path is stable with no upload failures.
|
|
45
|
+
- The mini program backend `uploadFile` domain allowlist is fully consistent with the current connected domains.
|
|
46
|
+
- COS dedicated domain `https://${SDKAppID}-cn.rich.my-imcloud.com` has been added to the allowlist (applicable for new apps).
|
|
47
|
+
|
|
48
|
+
## 6. Common Pitfalls
|
|
49
|
+
|
|
50
|
+
- Pitfall 1: Assuming the domain allowlist is correctly configured just because the dev build uploads successfully.
|
|
51
|
+
- Pitfall 2: Only verifying in debug mode and then directly publishing to production.
|
|
52
|
+
- Pitfall 3: Only checking `request` or `websocket` allowlists while ignoring the `uploadFile` allowlist.
|
|
53
|
+
- Pitfall 4: After a new app enables the COS dedicated domain, not syncing the `uploadFile` allowlist update.
|
|
54
|
+
|
|
55
|
+
## 7. Problem Definition (retrieval hint)
|
|
56
|
+
|
|
57
|
+
When integrating IM SDK in a mini program, the dev build can upload images/videos/audio/files normally, but the preview and production builds fail to upload.
|
|
58
|
+
|
|
59
|
+
## 8. Alternative Queries (retrieval recall)
|
|
60
|
+
|
|
61
|
+
- How to fix image upload failure in a preview mini program with IM?
|
|
62
|
+
- Why can the dev build upload but the preview and production builds fail?
|
|
63
|
+
- Can a missing `uploadFile` domain allowlist entry cause IM upload failure in a mini program?
|
|
64
|
+
- What does it mean when uploads recover after enabling debug mode in the preview build?
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Web (PC/H5): Standard Approach for Sending Audio Messages with IM SDK(pc/h5发送语音消息)"
|
|
3
|
+
product: chat
|
|
4
|
+
frameworks: [web]
|
|
5
|
+
scope: platform_specific
|
|
6
|
+
tags: [audio, voice, createAudioMessage, sendMessage, Recorder, js-audio-recorder, h5, pc]
|
|
7
|
+
version_range: ">=3.0.0"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Web (PC/H5): Standard Approach for Sending Audio Messages with IM SDK
|
|
11
|
+
|
|
12
|
+
## 1. Key Takeaways
|
|
13
|
+
|
|
14
|
+
- On the Web side, you can use a third-party recording library (e.g., `js-audio-recorder`) to record audio, then convert the recording result to a `File` and call `createAudioMessage`.
|
|
15
|
+
- The `audioFile` must have a `uri` field set (`audioFile.uri = window.URL.createObjectURL(audioFile)`); otherwise the audio message creation and sending pipeline is incomplete.
|
|
16
|
+
- After message creation, send it via `sendMessage`; the send result is determined by the Promise success/failure callback.
|
|
17
|
+
- It is recommended to pass an `onProgress` callback in `createAudioMessage` to monitor audio upload progress in real time.
|
|
18
|
+
|
|
19
|
+
## 2. Field / API Reference
|
|
20
|
+
|
|
21
|
+
| Field / Capability | Purpose | Description |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| `Recorder` | Recording capability | Captures audio data in the browser |
|
|
24
|
+
| `recorder.getWAVBlob()` | Export recording data | Gets WAV binary data for constructing a `File` |
|
|
25
|
+
| `audioFile.uri` | Local accessible address | Required field; generated using `window.URL.createObjectURL(audioFile)` |
|
|
26
|
+
| `chat.createAudioMessage({...})` | Create audio message instance | Generates an audio message object ready for rendering and sending |
|
|
27
|
+
| `chat.sendMessage(message)` | Send message | Returns a Promise; `then` for success, `catch` for failure |
|
|
28
|
+
| `onProgress` | Upload progress callback | Monitors the audio file upload process |
|
|
29
|
+
|
|
30
|
+
## 3. Mechanism & Sequence
|
|
31
|
+
|
|
32
|
+
Start recording -> Stop recording -> Calculate duration and get WAV Blob -> Convert to `File` and add `uri` and `duration` -> Call `createAudioMessage` to create the audio message -> Call `sendMessage` to send -> Update UI and logs based on send result.
|
|
33
|
+
|
|
34
|
+
## 4. Standard Usage
|
|
35
|
+
|
|
36
|
+
1. Start recording with the recorder and record the start timestamp.
|
|
37
|
+
2. After stopping recording, calculate the duration and get the `WAV Blob`.
|
|
38
|
+
3. Convert the `Blob` to a `File` and set `audioFile.uri` and `audioFile.duration`.
|
|
39
|
+
4. Call `createAudioMessage` to create the audio message, passing in the `onProgress` callback.
|
|
40
|
+
5. Call `sendMessage` to send the audio message and handle success and failure branches.
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
// 在 Web 端创建语音消息并发送
|
|
44
|
+
// 示例:使用第三方库 js-audio-recorder 录制音频
|
|
45
|
+
|
|
46
|
+
// 1. 开始录制
|
|
47
|
+
let recorder = new Recorder({
|
|
48
|
+
sampleBits: 16, // 采样位数,支持 8 或 16,默认 16
|
|
49
|
+
sampleRate: 16000, // 采样率
|
|
50
|
+
numChannels: 1 // 声道,支持 1 或 2,默认 1
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
let startTs;
|
|
54
|
+
recorder.start().then(() => {
|
|
55
|
+
// 开始录音,记录起始时间戳
|
|
56
|
+
startTs = Date.now();
|
|
57
|
+
}, (error) => {
|
|
58
|
+
// 出错了
|
|
59
|
+
console.log(`${error.name} : ${error.message}`);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// 2. 结束录制
|
|
63
|
+
recorder.stop();
|
|
64
|
+
|
|
65
|
+
// 3. 计算录音时长,获取 WAV 数据
|
|
66
|
+
let duration = Date.now() - startTs; // 单位:ms
|
|
67
|
+
let wavBlob = recorder.getWAVBlob();
|
|
68
|
+
|
|
69
|
+
// 4. blob 数据转成 File 对象
|
|
70
|
+
let audioFile = new File([wavBlob], 'hello.wav', { type: 'wav' });
|
|
71
|
+
audioFile.uri = window.URL.createObjectURL(audioFile);
|
|
72
|
+
audioFile.duration = duration;
|
|
73
|
+
|
|
74
|
+
// 5. 创建音频消息
|
|
75
|
+
let message = chat.createAudioMessage({
|
|
76
|
+
to: 'user1',
|
|
77
|
+
conversationType: 'C2C',
|
|
78
|
+
payload: {
|
|
79
|
+
file: audioFile
|
|
80
|
+
},
|
|
81
|
+
// 音频上传进度回调
|
|
82
|
+
onProgress: function(event) {
|
|
83
|
+
console.log('file uploading:', event);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// 6. 发送消息
|
|
88
|
+
chat.sendMessage(message).then(function(imResponse) {
|
|
89
|
+
// 发送成功
|
|
90
|
+
console.log(imResponse);
|
|
91
|
+
}).catch(function(imError) {
|
|
92
|
+
// 发送失败
|
|
93
|
+
console.warn('sendMessage error:', imError);
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 5. Expected Results
|
|
98
|
+
|
|
99
|
+
- After recording ends, `wavBlob` is reliably obtained and `audioFile` is constructed successfully.
|
|
100
|
+
- `audioFile.uri` is set, and `createAudioMessage` creates the audio message normally.
|
|
101
|
+
- `sendMessage` enters `then` on success; the audio message renders on screen and is playable.
|
|
102
|
+
- During upload, `onProgress` callbacks are received; on failure, `catch` provides clear error logs.
|
|
103
|
+
|
|
104
|
+
## 6. Common Pitfalls
|
|
105
|
+
|
|
106
|
+
- Pitfall 1: Not setting `audioFile.uri` before sending, causing the message pipeline to fail.
|
|
107
|
+
- Pitfall 2: Only creating the message without sending it, mistakenly thinking the message has been delivered.
|
|
108
|
+
- Pitfall 3: Not correctly calculating the duration or packaging the file after recording ends, causing the audio to be unusable.
|
|
109
|
+
|
|
110
|
+
## 7. Problem Definition (retrieval hint)
|
|
111
|
+
|
|
112
|
+
When integrating IM SDK on Web (PC/H5), how to complete voice recording and reliably send audio messages.
|
|
113
|
+
|
|
114
|
+
## 8. Alternative Queries (retrieval recall)
|
|
115
|
+
|
|
116
|
+
- How to send an audio message with the Web IM SDK?
|
|
117
|
+
- How to call `createAudioMessage` after recording on PC/H5?
|
|
118
|
+
- Why must `audioFile.uri` be set?
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
| Text message (createTextMessage → sendMessage) | `https://trtc.io/document/47993` |
|
|
22
22
|
| Group @ message (createTextAtMessage → sendMessage) | `https://trtc.io/document/47993` |
|
|
23
23
|
| Image message (createImageMessage → sendMessage) | `https://trtc.io/document/47993` |
|
|
24
|
-
|
|
|
24
|
+
| Audio message (createAudioMessage → sendMessage) | `https://trtc.io/document/47993` |
|
|
25
25
|
| Video message (createVideoMessage → sendMessage) | `https://trtc.io/document/47993` |
|
|
26
26
|
| File message (createFileMessage → sendMessage) | `https://trtc.io/document/47993` |
|
|
27
27
|
| Custom message (createCustomMessage → sendMessage) | `https://trtc.io/document/47993` |
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Voice Room Anchor Creates Room and Starts Streaming (Android)(语聊房 / 房主 / 开播 / createLive)"
|
|
3
|
+
product: live
|
|
4
|
+
frameworks: [android]
|
|
5
|
+
scope: platform_specific
|
|
6
|
+
tags: [voice room, anchor, start streaming, publish audio, createLive, openLocalMicrophone, muteMicrophone, unmuteMicrophone, LiveListStore, AudioSalon, keepOwnerOnSeat, seatMode, TakeSeatMode, Android]
|
|
7
|
+
version_range: ">=2.0.0"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Voice Room Anchor Creates Room and Starts Streaming (Android)
|
|
11
|
+
|
|
12
|
+
## 1. Key Takeaways
|
|
13
|
+
|
|
14
|
+
- Voice room streaming flow: construct `LiveInfo` (with `liveID`, `seatTemplate`, `keepOwnerOnSeat`, `seatMode`), call `createLive` to create the room; on success, call `openLocalMicrophone` to capture and publish audio so other users in the room can hear the anchor.
|
|
15
|
+
- `liveID` is required — it is the unique identifier of the live room.
|
|
16
|
+
- Setting `keepOwnerOnSeat` to `true` makes the anchor automatically take a seat upon entering the room (taking a seat is a prerequisite for publishing audio — only seated users can publish audio streams in the room).
|
|
17
|
+
- `seatTemplate` should be set to `SeatLayoutTemplate.AudioSalon(n)`, where n is the maximum seat count supported by the plan or a value less than it.
|
|
18
|
+
- `seatMode` sets the seat-taking mode (e.g., `TakeSeatMode.APPLY` for apply-to-take-seat).
|
|
19
|
+
- `muteMicrophone` pauses publishing local audio; `unmuteMicrophone` resumes publishing local audio.
|
|
20
|
+
|
|
21
|
+
## 2. Field / API Reference
|
|
22
|
+
|
|
23
|
+
| Field / Capability | Purpose | Notes |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| `LiveInfo` | Room information | Contains `liveID`, `liveName`, `seatTemplate`, `keepOwnerOnSeat`, `seatMode`, etc. |
|
|
26
|
+
| `liveID` | Room ID | Required parameter for `createLive` |
|
|
27
|
+
| `liveName` | Room name | Display name of the room |
|
|
28
|
+
| `seatTemplate` | Seat layout template | Use `SeatLayoutTemplate.AudioSalon(seatCount = n)` for voice rooms, where n ≤ max seats in plan |
|
|
29
|
+
| `keepOwnerOnSeat` | Auto-seat the owner | Set to `true` so the anchor automatically takes a seat upon entering |
|
|
30
|
+
| `seatMode` | Seat-taking mode | e.g., `TakeSeatMode.APPLY` for apply-to-take-seat |
|
|
31
|
+
| `createLive(liveInfo, callback)` | Create room (start streaming) | Pass `LiveInfo` and `LiveInfoCompletionHandler` callback |
|
|
32
|
+
| `openLocalMicrophone` | Capture and publish audio | Opens local microphone and publishes audio stream to the room |
|
|
33
|
+
| `muteMicrophone` | Pause audio publishing | Pauses local audio stream while microphone remains open |
|
|
34
|
+
| `unmuteMicrophone` | Resume audio publishing | Resumes local audio stream while microphone remains open |
|
|
35
|
+
|
|
36
|
+
## 3. Mechanism & Sequence
|
|
37
|
+
|
|
38
|
+
Construct `LiveInfo` (`liveID` required, `seatTemplate=AudioSalon(n)`, `keepOwnerOnSeat=true`, `seatMode` as needed) -> call `createLive` to create the room -> `onSuccess` callback fires, anchor is auto-seated -> call `openLocalMicrophone` to capture and publish audio -> other users in the room hear the anchor.
|
|
39
|
+
|
|
40
|
+
Taking a seat is a prerequisite for streaming: `keepOwnerOnSeat=true` ensures the anchor takes a seat before publishing audio. `muteMicrophone` / `unmuteMicrophone` are used to pause/resume during streaming.
|
|
41
|
+
|
|
42
|
+
## 4. Standard Usage
|
|
43
|
+
|
|
44
|
+
1. Construct `LiveInfo`: set `liveID`, `seatTemplate`, `keepOwnerOnSeat`, `seatMode`.
|
|
45
|
+
2. Implement `LiveInfoCompletionHandler` and call `createLive` to start streaming.
|
|
46
|
+
3. In `onSuccess` callback, call `openLocalMicrophone` to capture and publish audio.
|
|
47
|
+
4. Call `muteMicrophone` / `unmuteMicrophone` to pause/resume streaming as needed.
|
|
48
|
+
|
|
49
|
+
```kotlin
|
|
50
|
+
import android.util.Log
|
|
51
|
+
import androidx.appcompat.app.AppCompatActivity
|
|
52
|
+
import io.trtc.tuikit.atomicxcore.api.live.LiveInfo
|
|
53
|
+
import io.trtc.tuikit.atomicxcore.api.live.LiveInfoCompletionHandler
|
|
54
|
+
import io.trtc.tuikit.atomicxcore.api.live.TakeSeatMode
|
|
55
|
+
|
|
56
|
+
class YourAnchorActivity : AppCompatActivity() {
|
|
57
|
+
// ... 其他代码 ...
|
|
58
|
+
|
|
59
|
+
private fun startLive() {
|
|
60
|
+
val liveInfo = LiveInfo().apply {
|
|
61
|
+
// 1. 设置房间基础信息
|
|
62
|
+
liveID = this@YourAnchorActivity.liveID
|
|
63
|
+
liveName = "test 语聊房"
|
|
64
|
+
|
|
65
|
+
// 2. 设置语聊房麦位模板,seatCount 传入所需麦位数(≤ 套餐最大麦位数)
|
|
66
|
+
seatTemplate = SeatLayoutTemplate.AudioSalon(seatCount = 9)
|
|
67
|
+
|
|
68
|
+
// 3. 主播开播后自动上麦(上麦后才能推音频流)
|
|
69
|
+
keepOwnerOnSeat = true
|
|
70
|
+
|
|
71
|
+
// 4. 设置上麦模式(例如申请上麦)
|
|
72
|
+
seatMode = TakeSeatMode.APPLY
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 5. 调用 createLive 创建房间(开播)
|
|
76
|
+
liveListStore.createLive(liveInfo, object : LiveInfoCompletionHandler {
|
|
77
|
+
override fun onFailure(code: Int, desc: String) {
|
|
78
|
+
Log.e("Live", "Response startLive onError: $desc")
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
override fun onSuccess(liveInfo: LiveInfo) {
|
|
82
|
+
Log.d("Live", "Response startLive onSuccess")
|
|
83
|
+
// 6. 房主创建成功后默认自动上麦,此时调用 openLocalMicrophone 采集并发布音频
|
|
84
|
+
liveSeatStore.openLocalMicrophone(null)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 5. Expected Results
|
|
92
|
+
|
|
93
|
+
- `onSuccess` callback fires: room created successfully, anchor is auto-seated.
|
|
94
|
+
- After `openLocalMicrophone`: other users in the room can hear the anchor.
|
|
95
|
+
- After `muteMicrophone`: local audio publishing is paused; after `unmuteMicrophone`: publishing resumes.
|
|
96
|
+
- If `keepOwnerOnSeat` is not set to `true`: the anchor is not auto-seated and cannot publish audio.
|
|
97
|
+
- `onFailure(code, desc)` callback fires: streaming failed, `code` is the error code, `desc` is the error description.
|
|
98
|
+
|
|
99
|
+
## 6. Common Pitfalls
|
|
100
|
+
|
|
101
|
+
- Pitfall 1: Calling `openLocalMicrophone` without calling `createLive` first (cannot publish audio without creating a room).
|
|
102
|
+
- Pitfall 2: Not setting `keepOwnerOnSeat` to `true`, so the anchor is not seated and audio publishing does not work.
|
|
103
|
+
- Pitfall 3: Not setting `seatTemplate` or setting `seatCount` beyond the plan's maximum seat count.
|
|
104
|
+
- Pitfall 4: Confusing `muteMicrophone` (pauses audio stream publishing) with closing the microphone (stops audio capture).
|
|
105
|
+
- Pitfall 5: Reusing `liveID` (it must be globally unique; otherwise creation fails).
|
|
106
|
+
- Pitfall 6: Confusing `onSuccess` and `onFailure` callbacks (both branches require defensive handling).
|
|
107
|
+
|
|
108
|
+
## 7. Problem Definition (retrieval hint)
|
|
109
|
+
|
|
110
|
+
An Android voice room anchor needs to create a room and start audio streaming in the correct order, understanding the call timing and parameter meanings of `createLive`, `openLocalMicrophone`, `muteMicrophone`, and `unmuteMicrophone`.
|
|
111
|
+
|
|
112
|
+
## 8. Alternative Queries (retrieval recall)
|
|
113
|
+
|
|
114
|
+
- How does an Android voice room anchor start streaming?
|
|
115
|
+
- What is the call order of `createLive` and `openLocalMicrophone` on Android?
|
|
116
|
+
- How does an Android anchor take a seat and publish audio?
|
|
117
|
+
- What does the `keepOwnerOnSeat` parameter do?
|
|
118
|
+
- How to set the `AudioSalon` template for `seatTemplate`?
|
|
119
|
+
- What is the difference between `muteMicrophone` and `unmuteMicrophone` on Android?
|
|
120
|
+
- How to publish audio after creating a voice room?
|