@tencentcloud/sdk-mcp 1.7.7 → 1.7.9-beta.1

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 (224) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +7 -9
  3. package/index.js +8 -8
  4. package/knowledge/chunker.js +1 -0
  5. package/knowledge/doc-url-resolver.js +16 -9
  6. package/knowledge/embedding/build-vectors.js +92 -0
  7. package/knowledge/embedding/embed-model.js +41 -0
  8. package/knowledge/embedding/vector-augment.js +126 -0
  9. package/knowledge/embedding/vector-index.js +70 -0
  10. package/knowledge/frontmatter-meta.js +23 -0
  11. package/knowledge/path-meta.js +56 -0
  12. package/knowledge/search/exact-lookup.js +145 -16
  13. package/knowledge/search/filter-pool.js +77 -33
  14. package/knowledge/search/rank-profile.js +25 -0
  15. package/knowledge/search/requires-framework.js +4 -1
  16. package/knowledge/search/search-core.js +74 -13
  17. package/knowledge/search/search-knowledge.js +24 -34
  18. package/knowledge/search/search-pass.js +495 -169
  19. package/knowledge/search/url-row-scorer.js +24 -6
  20. package/package.json +3 -1
  21. package/resource/index/manifest.json +1 -1
  22. package/resource/index/vectors/index.json +4 -0
  23. package/resource/integration/callkit/preset/android/integration.md +0 -2
  24. package/resource/integration/callkit/preset/ios/integration.md +0 -2
  25. package/resource/integration/chat/preset/react/integration.md +9 -5
  26. package/resource/integration/chat/preset/uni-app/integration.md +4 -0
  27. package/resource/integration/chat/preset/vue/integration.md +10 -6
  28. package/resource/integration/livekit/preset/live/android/prepare-integration.md +0 -4
  29. package/resource/integration/livekit/preset/live/ios/prepare-integration.md +0 -4
  30. package/resource/integration/roomkit/preset/vue/integration.md +154 -208
  31. package/resource/knowledge/callkit/best-practice/android/video-chat-dating.md +0 -2
  32. package/resource/knowledge/callkit/core-sdk/android/answer-call.md +0 -2
  33. package/resource/knowledge/callkit/core-sdk/android/make-call.md +0 -2
  34. package/resource/knowledge/callkit/core-sdk/flutter/answer-call.md +0 -4
  35. package/resource/knowledge/callkit/core-sdk/flutter/make-call.md +0 -2
  36. package/resource/knowledge/callkit/core-sdk/flutter/offline-push.md +0 -2
  37. package/resource/knowledge/callkit/core-sdk/ios/answer-call.md +0 -2
  38. package/resource/knowledge/callkit/core-sdk/ios/make-call.md +0 -4
  39. package/resource/knowledge/callkit/core-sdk/ios/offline-push.md +0 -2
  40. package/resource/knowledge/callkit/core-sdk/uni-app/answer-call.md +0 -2
  41. package/resource/knowledge/callkit/core-sdk/uni-app/make-call.md +0 -2
  42. package/resource/knowledge/callkit/faq/ios.md +0 -2
  43. package/resource/knowledge/callkit/faq/uniapp-app.md +0 -2
  44. package/resource/knowledge/callkit/preset/miniprogram/integration.md +2 -3
  45. package/resource/knowledge/callkit/preset/miniprogram/uniapp-integration.md +0 -2
  46. package/resource/knowledge/chat/preset/ios-uikit/integration.md +0 -16
  47. package/resource/knowledge/chat/preset/react/h5/integration.md +16 -5
  48. package/resource/knowledge/chat/preset/vue/features/conversation-list.md +6 -3
  49. package/resource/knowledge/chat/preset/vue/h5/integration.md +7 -4
  50. package/resource/knowledge/iot/app/activate-service.md +95 -0
  51. package/resource/knowledge/iot/app/demo/android.md +93 -0
  52. package/resource/knowledge/iot/app/demo/ios.md +87 -0
  53. package/resource/knowledge/iot/app/demo/miniprogram.md +79 -0
  54. package/resource/knowledge/iot/app/device-binding.md +378 -0
  55. package/resource/knowledge/iot/app/device-sharing.md +414 -0
  56. package/resource/knowledge/iot/app/family-management.md +762 -0
  57. package/resource/knowledge/iot/app/integration/android.md +328 -0
  58. package/resource/knowledge/iot/app/integration/harmonyos.md +326 -0
  59. package/resource/knowledge/iot/app/integration/ios.md +351 -0
  60. package/resource/knowledge/iot/app/integration/miniprogram.md +268 -0
  61. package/resource/knowledge/iot/app/monitor-playback.md +557 -0
  62. package/resource/knowledge/iot/app/remote-control.md +139 -0
  63. package/resource/knowledge/iot/app/video-call.md +559 -0
  64. package/resource/knowledge/iot/app/wechat-call/device-call-miniprogram.md +204 -0
  65. package/resource/knowledge/iot/app/wechat-call/miniprogram-call-device.md +193 -0
  66. package/resource/knowledge/iot/client-api/app/android/txiotcallsession.md +189 -0
  67. package/resource/knowledge/iot/client-api/app/android/txiotcloudstorage.md +77 -0
  68. package/resource/knowledge/iot/client-api/app/android/txiotdevicemanager.md +175 -0
  69. package/resource/knowledge/iot/client-api/app/android/txiotengine.md +172 -0
  70. package/resource/knowledge/iot/client-api/app/android/txiotenginedef.md +163 -0
  71. package/resource/knowledge/iot/client-api/app/android/txiotfamilymanager.md +146 -0
  72. package/resource/knowledge/iot/client-api/app/android/txiotmonitorsession.md +246 -0
  73. package/resource/knowledge/iot/client-api/app/harmonyos/txiotcallsession.md +191 -0
  74. package/resource/knowledge/iot/client-api/app/harmonyos/txiotcloudstorage.md +77 -0
  75. package/resource/knowledge/iot/client-api/app/harmonyos/txiotdevicemanager.md +183 -0
  76. package/resource/knowledge/iot/client-api/app/harmonyos/txiotengine.md +186 -0
  77. package/resource/knowledge/iot/client-api/app/harmonyos/txiotenginedef.md +164 -0
  78. package/resource/knowledge/iot/client-api/app/harmonyos/txiotfamilymanager.md +150 -0
  79. package/resource/knowledge/iot/client-api/app/harmonyos/txiotmonitorsession.md +252 -0
  80. package/resource/knowledge/iot/client-api/app/ios/txiotcallsession.md +199 -0
  81. package/resource/knowledge/iot/client-api/app/ios/txiotcloudstorage.md +76 -0
  82. package/resource/knowledge/iot/client-api/app/ios/txiotdevicemanager.md +173 -0
  83. package/resource/knowledge/iot/client-api/app/ios/txiotengine.md +173 -0
  84. package/resource/knowledge/iot/client-api/app/ios/txiotenginedef.md +171 -0
  85. package/resource/knowledge/iot/client-api/app/ios/txiotfamilymanager.md +146 -0
  86. package/resource/knowledge/iot/client-api/app/ios/txiotmonitorsession.md +250 -0
  87. package/resource/knowledge/iot/client-api/app/miniprogram/txiotcallsession.md +180 -0
  88. package/resource/knowledge/iot/client-api/app/miniprogram/txiotcloudstorage.md +76 -0
  89. package/resource/knowledge/iot/client-api/app/miniprogram/txiotdevicemanager.md +281 -0
  90. package/resource/knowledge/iot/client-api/app/miniprogram/txiotengine.md +183 -0
  91. package/resource/knowledge/iot/client-api/app/miniprogram/txiotenginedef.md +152 -0
  92. package/resource/knowledge/iot/client-api/app/miniprogram/txiotfamilymanager.md +179 -0
  93. package/resource/knowledge/iot/client-api/app/miniprogram/txiotmonitorsession.md +226 -0
  94. package/resource/knowledge/iot/client-api/device/android-smart-device.md +813 -0
  95. package/resource/knowledge/iot/client-api/device/linux-rtos-device.md +2027 -0
  96. package/resource/knowledge/iot/device/activate-service.md +167 -0
  97. package/resource/knowledge/iot/device/ai-voice-chat/advanced-features/custom-agent.md +171 -0
  98. package/resource/knowledge/iot/device/ai-voice-chat/advanced-features/smart-device-control.md +721 -0
  99. package/resource/knowledge/iot/device/ai-voice-chat/integration-guide/android-smart-device.md +247 -0
  100. package/resource/knowledge/iot/device/ai-voice-chat/integration-guide/linux-rtos-device.md +368 -0
  101. package/resource/knowledge/iot/device/ai-voice-chat/overview.md +84 -0
  102. package/resource/knowledge/iot/device/cloud-storage.md +696 -0
  103. package/resource/knowledge/iot/device/data-model.md +972 -0
  104. package/resource/knowledge/iot/device/demo/android-smart-device.md +97 -0
  105. package/resource/knowledge/iot/device/demo/linux-rtos-device.md +106 -0
  106. package/resource/knowledge/iot/device/device-ota-upgrade.md +237 -0
  107. package/resource/knowledge/iot/device/dynamic-registration/android-smart-device.md +275 -0
  108. package/resource/knowledge/iot/device/dynamic-registration/linux-rtos-device.md +297 -0
  109. package/resource/knowledge/iot/device/login-and-register/android-smart-device.md +131 -0
  110. package/resource/knowledge/iot/device/login-and-register/linux-rtos-device.md +291 -0
  111. package/resource/knowledge/iot/device/monitor-pushing/android-smart-device.md +237 -0
  112. package/resource/knowledge/iot/device/monitor-pushing/linux-rtos-device.md +493 -0
  113. package/resource/knowledge/iot/device/video-call/android-smart-device.md +299 -0
  114. package/resource/knowledge/iot/device/video-call/linux-rtos-device.md +465 -0
  115. package/resource/knowledge/iot/device/wechat-call/android-smart-device.md +534 -0
  116. package/resource/knowledge/iot/device/wechat-call/linux-rtos-device.md +681 -0
  117. package/resource/knowledge/iot/kids-watch/overview.md +28 -0
  118. package/resource/knowledge/iot/security-camera/activate-service.md +74 -0
  119. package/resource/knowledge/iot/security-camera/monitor-playback/app-integration.md +302 -0
  120. package/resource/knowledge/iot/security-camera/monitor-playback/device-integration/android.md +237 -0
  121. package/resource/knowledge/iot/security-camera/monitor-playback/device-integration/linux-rtos.md +493 -0
  122. package/resource/knowledge/iot/security-camera/overview.md +31 -0
  123. package/resource/knowledge/iot/security-camera/ptz-control.md +153 -0
  124. package/resource/knowledge/iot/security-camera/recording-and-snapshot.md +182 -0
  125. package/resource/knowledge/iot/security-camera/voice-intercom.md +174 -0
  126. package/resource/knowledge/iot/smart-vision/serviceoverview.md +114 -0
  127. package/resource/knowledge/iot/voice-recorder/app-demo.md +99 -0
  128. package/resource/knowledge/iot/voice-recorder/device-demo.md +189 -0
  129. package/resource/knowledge/iot/voice-recorder/overview.md +64 -0
  130. package/resource/knowledge/livekit/core-sdk/features/android/base-beauty.md +0 -2
  131. package/resource/knowledge/livekit/core-sdk/features/android/gift.md +0 -4
  132. package/resource/knowledge/livekit/core-sdk/features/android/live-list.md +0 -2
  133. package/resource/knowledge/livekit/core-sdk/features/flutter/audio-effect.md +0 -2
  134. package/resource/knowledge/livekit/core-sdk/features/flutter/base-beauty.md +0 -2
  135. package/resource/knowledge/livekit/core-sdk/features/flutter/gift.md +0 -4
  136. package/resource/knowledge/livekit/core-sdk/features/ios/base-beauty.md +0 -2
  137. package/resource/knowledge/livekit/core-sdk/features/ios/gift.md +0 -4
  138. package/resource/knowledge/livekit/core-sdk/features/ios/live-list.md +0 -2
  139. package/resource/knowledge/livekit/core-sdk/features/uni-app/base-beauty.md +0 -2
  140. package/resource/knowledge/livekit/core-sdk/features/uni-app/gift.md +0 -4
  141. package/resource/knowledge/livekit/core-sdk/live/android/co-guest-interaction.md +0 -4
  142. package/resource/knowledge/livekit/core-sdk/live/android/host-interaction.md +0 -10
  143. package/resource/knowledge/livekit/core-sdk/live/android/integration.md +0 -2
  144. package/resource/knowledge/livekit/core-sdk/live/flutter/co-guest-interaction.md +0 -2
  145. package/resource/knowledge/livekit/core-sdk/live/flutter/host-interaction.md +0 -10
  146. package/resource/knowledge/livekit/core-sdk/live/flutter/integration.md +0 -2
  147. package/resource/knowledge/livekit/core-sdk/live/ios/co-guest-interaction.md +0 -4
  148. package/resource/knowledge/livekit/core-sdk/live/ios/host-interaction.md +0 -10
  149. package/resource/knowledge/livekit/core-sdk/live/ios/integration.md +0 -2
  150. package/resource/knowledge/livekit/core-sdk/live/uni-app/co-guest-interaction.md +0 -4
  151. package/resource/knowledge/livekit/core-sdk/live/uni-app/host-interaction.md +0 -4
  152. package/resource/knowledge/livekit/core-sdk/live/uni-app/integration.md +0 -2
  153. package/resource/knowledge/livekit/core-sdk/voice/android/co-guest-interaction.md +0 -2
  154. package/resource/knowledge/livekit/core-sdk/voice/android/host-interaction.md +0 -4
  155. package/resource/knowledge/livekit/core-sdk/voice/android/integration.md +0 -4
  156. package/resource/knowledge/livekit/core-sdk/voice/flutter/integration.md +0 -2
  157. package/resource/knowledge/livekit/core-sdk/voice/ios/co-guest-interaction.md +0 -2
  158. package/resource/knowledge/livekit/core-sdk/voice/ios/host-interaction.md +0 -4
  159. package/resource/knowledge/livekit/core-sdk/voice/ios/integration.md +0 -4
  160. package/resource/knowledge/livekit/core-sdk/voice/uni-app/co-guest-interaction.md +0 -2
  161. package/resource/knowledge/livekit/core-sdk/voice/uni-app/integration.md +0 -2
  162. package/resource/knowledge/livekit/faq/error-code.md +0 -2
  163. package/resource/knowledge/push/config/android/honor.md +16 -1
  164. package/resource/knowledge/push/config/android/huawei.md +20 -4
  165. package/resource/knowledge/push/config/android/meizu.md +19 -5
  166. package/resource/knowledge/push/config/android/vivo.md +20 -1
  167. package/resource/knowledge/push/config/donut.md +0 -2
  168. package/resource/knowledge/push/config/harmonyos.md +21 -5
  169. package/resource/knowledge/push/integration/android.md +0 -5
  170. package/resource/knowledge/push/integration/donut.md +0 -3
  171. package/resource/knowledge/push/integration/flutter.md +1 -4
  172. package/resource/knowledge/push/integration/harmonyos.md +0 -3
  173. package/resource/knowledge/push/integration/ios.md +0 -3
  174. package/resource/knowledge/push/integration/react-native.md +0 -5
  175. package/resource/knowledge/push/integration/uni-app.md +0 -3
  176. package/resource/knowledge/push/integration/unity.md +0 -3
  177. package/resource/knowledge/push/integration/unreal-engine.md +0 -3
  178. package/resource/knowledge/roomkit/core-sdk/android/call-user-to-room.md +0 -2
  179. package/resource/knowledge/roomkit/core-sdk/android/room-participant-state.md +0 -2
  180. package/resource/knowledge/roomkit/core-sdk/android/room-state.md +0 -2
  181. package/resource/knowledge/roomkit/core-sdk/android/schedule-room.md +0 -2
  182. package/resource/knowledge/roomkit/core-sdk/flutter/call-user-to-room.md +0 -2
  183. package/resource/knowledge/roomkit/core-sdk/flutter/room-participant-state.md +0 -2
  184. package/resource/knowledge/roomkit/core-sdk/flutter/room-state.md +0 -2
  185. package/resource/knowledge/roomkit/core-sdk/flutter/schedule-room.md +0 -2
  186. package/resource/knowledge/roomkit/core-sdk/ios/call-user-to-room.md +0 -2
  187. package/resource/knowledge/roomkit/core-sdk/ios/room-participant-state.md +0 -2
  188. package/resource/knowledge/roomkit/core-sdk/ios/room-state.md +0 -2
  189. package/resource/knowledge/roomkit/core-sdk/ios/schedule-room.md +0 -2
  190. package/resource/knowledge/roomkit/core-sdk/vue/room-view.md +0 -3
  191. package/resource/knowledge/roomkit/preset/uniapp-app/integration.md +18 -14
  192. package/resource/knowledge/rtcengine/web/how_to_run_web_sdk_demo.md +0 -2
  193. package/resource/knowledge/rtcengine/web/plugin/23-advanced-support-detection.md +30 -0
  194. package/resource/knowledge/rtcengine/web/plugin/24-advanced-network-quality.md +0 -2
  195. package/resource/knowledge/rtcengine/web/plugin/31-advanced-plugins-overview.md +1 -1
  196. package/resource/knowledge/rtcengine/web/plugin/35-advanced-ai-denoiser.md +1 -1
  197. package/resource/knowledge/rtcengine/web/plugin/36-advanced-virtual-background.md +4 -0
  198. package/resource/knowledge/trtc/android/TRTCCloud.md +94 -85
  199. package/resource/knowledge/trtc/android/TRTCCloudDef.md +48 -46
  200. package/resource/knowledge/trtc/android/TRTCCloudListener.md +48 -48
  201. package/resource/knowledge/trtc/android/TXAudioEffectManager.md +18 -18
  202. package/resource/knowledge/trtc/android/TXDeviceManager.md +4 -4
  203. package/resource/knowledge/trtc/android/TXLiteAVCode.md +1 -0
  204. package/resource/knowledge/trtc/c++/ITRTCCloud.md +90 -90
  205. package/resource/knowledge/trtc/c++/ITXAudioEffectManager.md +18 -18
  206. package/resource/knowledge/trtc/c++/ITXDeviceManager.md +9 -9
  207. package/resource/knowledge/trtc/c++/TRTCCloudCallback.md +47 -47
  208. package/resource/knowledge/trtc/c++/TRTCTypeDef.md +47 -45
  209. package/resource/knowledge/trtc/c++/TXLiteAVCode.md +1 -0
  210. package/resource/knowledge/trtc/ios/TRTCCloud.md +93 -93
  211. package/resource/knowledge/trtc/ios/TRTCCloudDelegate.md +50 -50
  212. package/resource/knowledge/trtc/ios/TXAudioEffectManager.md +8 -8
  213. package/resource/knowledge/trtc/ios/TXDeviceManager.md +9 -9
  214. package/resource/knowledge/trtc/ios/TXLiteAVCode.md +1 -0
  215. package/resource/knowledge/trtc/ios/TXLiveSDKTypeDef.md +48 -46
  216. package/server-config.js +8 -9
  217. package/server.js +1 -1
  218. package/tools/common/finalize_answer.js +1 -1
  219. package/tools/common/present_framework_choice.js +1 -1
  220. package/tools/common/search_trtc_knowledge.js +22 -3
  221. package/tools/definitions/search_trtc_knowledge_def.js +3 -2
  222. package/utils/preflight-route.js +19 -2
  223. package/utils/report-cls-client.js +1 -1
  224. package/utils/report-es-client.js +1 -1
@@ -0,0 +1,534 @@
1
+ ---
2
+ product: iot
3
+ framework:
4
+ - android
5
+ types:
6
+ - feature
7
+ retrievable_scope: always
8
+ feature_domain: device
9
+ ---
10
+
11
+ TWeCall 是腾讯云物联网开发平台提供的设备与微信小程序之间的双向音视频通话能力。设备端一键呼叫,微信小程序端持续响铃提醒,接通后即可进行音视频通话,达到微信原生通话体验。
12
+
13
+ 本文将介绍设备如何在 Android 平台实现获取小程序联系人列表、呼叫微信小程序、响应通话状态回调与挂断通话等,帮助您快速完成 TWeCall(微信通话)的设备端接入。
14
+
15
+ ## 前提条件
16
+ - 已完成 登录与注册 文档中的登录功能,设备能够成功登录并保持在线。
17
+
18
+ - 已在物联网开发平台完成 TWeCall 服务激活与小程序授权。
19
+
20
+ - 设备在 小程序端已授权 VoIP 通话权限(调用 `getContacts` 返回联系人列表非空)。
21
+
22
+ > **说明:**
23
+ >
24
+ > 通话依赖摄像头与麦克风采集,请确保已在 `AndroidManifest.xml` 中声明 `android.permission.CAMERA`、`android.permission.RECORD_AUDIO` 权限,并在运行时向用户申请授权,同时需使用 Android 真机(音视频能力在模拟器上无法正常工作)。
25
+ >
26
+
27
+ ## 接入步骤
28
+
29
+ TWeCall 设备端接入分为以下步骤:
30
+ 1. 注册通话事件回调。
31
+
32
+ 2. 获取联系人列表。
33
+
34
+ 3. 发起呼叫。
35
+
36
+ 4. 处理通话状态回调。
37
+
38
+ 5. 开启摄像头与麦克风推流。
39
+
40
+ 6. 挂断通话。
41
+
42
+ ### 步骤 1:注册通话事件回调
43
+
44
+ 登录成功后,通过 `TXIoTCallSession.getInstance().addListener` 注册 TXIoTCallSession.Listener。设备作为主叫时,需要关注对端的接听、拒绝、超时、挂断回调;设备作为被叫时,需要关注来电请求回调。
45
+
46
+ Listener 回调说明:
47
+
48
+ |回调|触发时机|说明|
49
+ |---------|---------|---------|
50
+ |`onCallRequested`|收到对端(小程序)发起的来电请求。|设备作为被叫时触发,在此回调中调用 `accept` 接听或 `reject` 拒绝。|
51
+ |`onCallAccepted`|对端接听呼叫。|设备作为主叫时触发,此时可开启摄像头与麦克风推流(见 步骤 5)。|
52
+ |`onCallRejected`|对端拒绝呼叫。|设备作为主叫时触发,清理本地状态。|
53
+ |`onCallTimeout`|对端无人接听,呼叫超时。|设备作为主叫时触发,清理本地状态,可重试或提示用户。|
54
+ |`onCallHangup`|对端主动挂断。|通话过程中对端挂断时触发,停止推流并清理采集(见 步骤 6)。|
55
+
56
+ ``` java
57
+ TXIoTCallSession.Listener listener = new TXIoTCallSession.Listener() {
58
+ @Override
59
+ public void onCallRequested(TXIoTCallSession.Contact contact, TXIoTCallSession.Option option) {
60
+ // 被叫:收到来电请求,这里选择接听,也可调用 reject 拒绝
61
+ TXIoTCallSession.getInstance().accept(contact.userId, null);
62
+ }
63
+
64
+ @Override
65
+ public void onCallAccepted(TXIoTCallSession.Contact contact) {
66
+ // 对端已接听,开始推流(见步骤 5)
67
+ }
68
+
69
+ @Override
70
+ public void onCallRejected(TXIoTCallSession.Contact contact) {
71
+ // 对端拒接,清理本地状态
72
+ }
73
+
74
+ @Override
75
+ public void onCallTimeout(TXIoTCallSession.Contact contact) {
76
+ // 呼叫超时,清理本地状态
77
+ }
78
+
79
+ @Override
80
+ public void onCallHangup(TXIoTCallSession.Contact contact) {
81
+ // 对端挂断,停止推流并清理采集
82
+ }
83
+ };
84
+
85
+ TXIoTCallSession.getInstance().addListener(listener);
86
+ ```
87
+
88
+ ### 步骤 2:获取联系人列表
89
+
90
+ 调用 `getContacts` 拉取可呼叫的微信小程序联系人列表。接口采用游标(cursor)分页,首次调用传 `null`,后续传入上一次回调返回的 `nextCursor` 继续拉取,直到 `nextCursor` 为空表示已到末尾,当 `TXIoTValueCallback` 返回的 `List<Contact>`,为空表示已无更多联系人,`nextCursor` 为空表示已是最后一页,无需继续拉取。
91
+ ``` java
92
+ void getContacts(String cursor, int limit, TXIoTValueCallback<ContactsResult> callback);
93
+ ```
94
+
95
+ > **注意:**
96
+ > 返回说明:`Contact` 中的 `userId` 是发起呼叫的关键标识,由 `modelId`、`wxAppId`、`openId` 三段以 `/` 拼接而成。
97
+ >
98
+
99
+ 示例:完整拉取所有联系人
100
+ ``` java
101
+ private static final int PAGE_SIZE = 10;
102
+ private String mTargetUserId;
103
+
104
+ private void fetchAllContacts(String cursor) {
105
+ TXIoTCallSession.getInstance().getContacts(cursor, PAGE_SIZE,
106
+ new TXIoTValueCallback<TXIoTCallSession.ContactsResult>() {
107
+ @Override
108
+ public void onSuccess(TXIoTCallSession.ContactsResult result) {
109
+ if (result == null || result.contacts == null) {
110
+ return;
111
+ }
112
+
113
+ for (TXIoTCallSession.Contact contact : result.contacts) {
114
+ // 记录第一个联系人作为呼叫目标
115
+ if (mTargetUserId == null) {
116
+ mTargetUserId = contact.userId;
117
+ }
118
+ }
119
+
120
+ // nextCursor 非空说明还有更多联系人,继续翻页
121
+ if (result.nextCursor != null && !result.nextCursor.isEmpty()) {
122
+ fetchAllContacts(result.nextCursor);
123
+ } else {
124
+ // 拉取完成,可发起呼叫(见步骤 3)
125
+ makeCall(mTargetUserId);
126
+ }
127
+ }
128
+
129
+ @Override
130
+ public void onError(int code, String desc) {
131
+ Log.e(TAG, "getContacts failed: " + code + ", " + desc);
132
+ }
133
+ });
134
+ }
135
+
136
+ // 首次拉取
137
+ fetchAllContacts(null);
138
+ ```
139
+
140
+ ### 步骤 3:发起呼叫
141
+
142
+ 填写完联系人 `userId` 后,调用 `call` 向该联系人(微信小程序)发起呼叫。若呼叫小程序,`userId` 可取自 `getContacts` 返回的 `userId` 。
143
+
144
+ #### 呼叫体验版小程序(重要)
145
+
146
+ > **特别强调:**
147
+ >
148
+ > 开发调试阶段,设备端**必须**在**初始化之后、登录之前**调用 `callExperimentApi` 显式指定呼叫的小程序版本为体验版(DEMO)或开发版(DEBUG),否则会因小程序版本不匹配导致**呼叫失败或无法接通**。待完成体验版功能自测后,将设备寄送至微信团队进行验证,验证通过后,小程序的 VoIP 音视频能力方可正式上线发布。小程序 VoIP 音视频**正式上线**后,无需再调用此接口,SDK 将默认呼叫线上版小程序。
149
+ >
150
+
151
+ 开发阶段指定体验版的方法如下,在**初始化之后、登录之前**通过 `callExperimentApi` 指定呼叫的小程序版本:
152
+ ``` java
153
+ /*
154
+ 在登录成功之前调用,指定呼叫的小程序版本
155
+ "DEBUG" 开发版
156
+ "DEMO" 体验版
157
+ "RELEASE" 正式版
158
+ */
159
+ TXIoTDeviceEngine.getInstance(context).callExperimentApi(
160
+ "set_wx_miniapp_flavor", "DEBUG", new TXIoTValueCallback<String>() {
161
+ @Override
162
+ public void onSuccess(String response) {
163
+ Log.i(TAG, "set_wx_miniapp_flavor success: " + response);
164
+ }
165
+
166
+ @Override
167
+ public void onError(int code, String desc) {
168
+ Log.e(TAG, "set_wx_miniapp_flavor failed: " + code + ", " + desc);
169
+ }
170
+ });
171
+ ```
172
+
173
+ 呼叫调用接口:
174
+ ``` java
175
+ void call(String userId, Option option, TXIoTCallback callback);
176
+ ```
177
+
178
+ 呼叫选项 `Option`
179
+
180
+ |字段|说明|
181
+ |---------|---------|
182
+ |`mediaContent`|媒体内容,见下表枚举。|
183
+ |`customData`|自定义数据,随呼叫信令透传到小程序端。|
184
+
185
+ 媒体内容枚举 `MediaContent`
186
+
187
+ |取值|说明|
188
+ |---------|---------|
189
+ |`MediaContent.AUDIO`|仅音频通话。|
190
+ |`MediaContent.VIDEO`|仅视频通话。|
191
+ |`MediaContent.AUDIO_VIDEO`|音视频通话(默认推荐)。|
192
+
193
+ 示例
194
+ ``` java
195
+ TXIoTCallSession.Option option = new TXIoTCallSession.Option();
196
+ option.mediaContent = TXIoTCallSession.MediaContent.AUDIO_VIDEO;
197
+ option.customData = "";
198
+
199
+ TXIoTCallSession.getInstance().call(userId, option, new TXIoTCallback() {
200
+ @Override
201
+ public void onSuccess() {
202
+ Log.i(TAG, "call request sent");
203
+ }
204
+
205
+ @Override
206
+ public void onError(int code, String desc) {
207
+ Log.e(TAG, "call failed: " + code + ", " + desc);
208
+ }
209
+ });
210
+ ```
211
+
212
+ > **注意:**
213
+ > `call` 回调返回 `onSuccess` 仅表示呼叫信令已发出,并不代表通话已建立。需等待 `onCallAccepted` 回调后,通话才算真正接通,此时再开启摄像头与麦克风推流。
214
+ >
215
+
216
+ ### 步骤 4:处理通话状态回调
217
+
218
+ 呼叫发出后,设备会依次收到以下回调,业务侧需在对应回调中管理本地状态:
219
+
220
+ |回调|业务建议处理|
221
+ |---------|---------|
222
+ |`onCallAccepted`|通话接通,开启摄像头与麦克风推流(步骤 5)。|
223
+ |`onCallRejected`|对端拒接,清理呼叫状态,恢复待机。|
224
+ |`onCallTimeout`|无人接听,清理呼叫状态,可重试或提示用户。|
225
+ |`onCallHangup`|通话中挂断,关闭摄像头与麦克风(步骤 6),停止采集。|
226
+
227
+ 示例:状态机式处理
228
+ ``` java
229
+ private boolean mInCall = false;
230
+
231
+ @Override
232
+ public void onCallAccepted(TXIoTCallSession.Contact contact) {
233
+ Log.i(TAG, "onCallAccepted: " + contact.userId);
234
+ mInCall = true;
235
+ startCallStreams(); // 见步骤 5
236
+ }
237
+
238
+ @Override
239
+ public void onCallRejected(TXIoTCallSession.Contact contact) {
240
+ Log.i(TAG, "onCallRejected: " + contact.userId);
241
+ mInCall = false;
242
+ }
243
+
244
+ @Override
245
+ public void onCallTimeout(TXIoTCallSession.Contact contact) {
246
+ Log.i(TAG, "onCallTimeout: " + contact.userId);
247
+ mInCall = false;
248
+ }
249
+
250
+ @Override
251
+ public void onCallHangup(TXIoTCallSession.Contact contact) {
252
+ Log.i(TAG, "onCallHangup: " + contact.userId);
253
+ mInCall = false;
254
+ stopCallStreams(); // 见步骤 6
255
+ }
256
+ ```
257
+
258
+ > **说明:**
259
+ > 建议在收到 `onCallAccepted` 后再开启摄像头与麦克风,避免对端尚未接听就占用采集资源。`onCallRejected`、`onCallTimeout`、`onCallHangup` 均表示通话结束,应统一做资源清理。
260
+ >
261
+
262
+ ### 步骤 5:开启摄像头与麦克风推流
263
+
264
+ 通话接通后(`onCallAccepted` 触发),Android SDK 已封装摄像头采集、编码与推流,无需手动推送裸帧。只需调用以下接口即可:
265
+ ``` java
266
+ int openCamera(boolean frontCamera, TXCloudVideoView view);
267
+ int openMicrophone();
268
+ int startRemoteView(String userId, TXCloudVideoView view);
269
+ ```
270
+
271
+ 示例
272
+ ``` java
273
+ private TXCloudVideoView mLocalView; // 布局中放置 <com.tencent.rtmp.ui.TXCloudVideoView/>
274
+ private TXCloudVideoView mRemoteView;
275
+
276
+ private void startCallStreams() {
277
+ // 开启摄像头采集并推流,同时在本地控件预览(默认前置)
278
+ TXIoTCallSession.getInstance().openCamera(true, mLocalView);
279
+ // 开启麦克风采集并推流
280
+ TXIoTCallSession.getInstance().openMicrophone();
281
+ // 渲染对端画面
282
+ TXIoTCallSession.getInstance().startRemoteView(mTargetUserId, mRemoteView);
283
+ }
284
+ ```
285
+
286
+ > **注意:**
287
+ > 开启摄像头与麦克风前,请确保已获得 `CAMERA` 与 `RECORD_AUDIO` 运行时权限,否则采集会失败导致对端无画面或无声音。
288
+ >
289
+
290
+ ### 步骤 6:挂断通话
291
+
292
+ 通话过程中,任意一方均可挂断。设备主动挂断调用 `hangup`;对端挂断时设备会收到 `onCallHangup` 回调。
293
+
294
+ 无论哪种情况,都应关闭摄像头与麦克风、停止采集。
295
+ ``` java
296
+ void hangup(String userId, TXIoTCallback callback);
297
+
298
+ // 关闭采集(主动挂断与收到 onCallHangup 后均需调用)
299
+ private void stopCallStreams() {
300
+ TXIoTCallSession.getInstance().stopRemoteView(mTargetUserId);
301
+ TXIoTCallSession.getInstance().closeCamera();
302
+ TXIoTCallSession.getInstance().closeMicrophone();
303
+ }
304
+ ```
305
+
306
+ 示例
307
+ ``` java
308
+ private void hangupCall() {
309
+ if (!mInCall) {
310
+ return;
311
+ }
312
+ TXIoTCallSession.getInstance().hangup(mTargetUserId, new TXIoTCallback() {
313
+ @Override
314
+ public void onSuccess() {
315
+ Log.i(TAG, "hangup request sent");
316
+ }
317
+
318
+ @Override
319
+ public void onError(int code, String desc) {
320
+ Log.e(TAG, "hangup failed: " + code + ", " + desc);
321
+ }
322
+ });
323
+ }
324
+
325
+ // 关闭采集(主动挂断与收到 onCallHangup 后均需调用)
326
+ private void stopCallStreams() {
327
+ TXIoTCallSession.getInstance().stopRemoteView(mTargetUserId);
328
+ TXIoTCallSession.getInstance().closeCamera();
329
+ TXIoTCallSession.getInstance().closeMicrophone();
330
+ }
331
+ ```
332
+
333
+ > **注意:**
334
+ > `hangup` 的 `callback` 用于确认挂断信令发送结果。即使主动挂断,也建议在 `onCallHangup` 或 `callback` 中统一做采集清理,避免重复释放。
335
+ >
336
+
337
+ ## 完整示例代码
338
+
339
+ 以下示例整合上述步骤,演示设备拉取联系人、呼叫小程序、接通后推流、挂断的完整流程。设备登录与初始化。
340
+ ``` java
341
+ package com.example.iotdemo;
342
+
343
+ import android.os.Bundle;
344
+ import android.util.Log;
345
+ import androidx.annotation.Nullable;
346
+ import androidx.appcompat.app.AppCompatActivity;
347
+
348
+ import com.tencent.liteav.iot.TXIoTCallback;
349
+ import com.tencent.liteav.iot.TXIoTCallSession;
350
+ import com.tencent.liteav.iot.TXIoTError;
351
+ import com.tencent.liteav.iot.TXIoTValueCallback;
352
+ import com.tencent.rtmp.ui.TXCloudVideoView;
353
+
354
+ public class CallActivity extends AppCompatActivity {
355
+
356
+ private static final String TAG = "CallActivity";
357
+ private static final int PAGE_SIZE = 50;
358
+
359
+ private TXIoTCallSession mCallSession;
360
+ private TXCloudVideoView mLocalView;
361
+ private TXCloudVideoView mRemoteView;
362
+
363
+ private boolean mInCall = false;
364
+ private String mTargetUserId;
365
+
366
+ private final TXIoTCallSession.Listener mListener = new TXIoTCallSession.Listener() {
367
+ @Override
368
+ public void onCallRequested(TXIoTCallSession.Contact contact, TXIoTCallSession.Option option) {
369
+ Log.i(TAG, "onCallRequested: " + contact.userId);
370
+ // 被叫:这里选择接听,也可调用 reject 拒绝
371
+ mTargetUserId = contact.userId;
372
+ mCallSession.accept(contact.userId, null);
373
+ }
374
+
375
+ @Override
376
+ public void onCallAccepted(TXIoTCallSession.Contact contact) {
377
+ Log.i(TAG, "onCallAccepted: " + contact.userId);
378
+ mTargetUserId = contact.userId;
379
+ mInCall = true;
380
+ startCallStreams();
381
+ }
382
+
383
+ @Override
384
+ public void onCallRejected(TXIoTCallSession.Contact contact) {
385
+ Log.i(TAG, "onCallRejected: " + contact.userId);
386
+ mInCall = false;
387
+ }
388
+
389
+ @Override
390
+ public void onCallTimeout(TXIoTCallSession.Contact contact) {
391
+ Log.i(TAG, "onCallTimeout: " + contact.userId);
392
+ mInCall = false;
393
+ }
394
+
395
+ @Override
396
+ public void onCallHangup(TXIoTCallSession.Contact contact) {
397
+ Log.i(TAG, "onCallHangup: " + contact.userId);
398
+ mInCall = false;
399
+ stopCallStreams();
400
+ }
401
+ };
402
+
403
+ @Override
404
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
405
+ super.onCreate(savedInstanceState);
406
+ setContentView(R.layout.activity_call);
407
+ mLocalView = findViewById(R.id.local_view);
408
+ mRemoteView = findViewById(R.id.remote_view);
409
+
410
+ // 前提:SDK 已完成初始化并登录成功(参见「登录与注册」)
411
+ mCallSession = TXIoTCallSession.getInstance();
412
+ mCallSession.addListener(mListener);
413
+
414
+ // 拉取联系人,回调中自动发起呼叫
415
+ fetchAllContacts(null);
416
+ }
417
+
418
+ private void fetchAllContacts(String cursor) {
419
+ mCallSession.getContacts(cursor, PAGE_SIZE,
420
+ new TXIoTValueCallback<TXIoTCallSession.ContactsResult>() {
421
+ @Override
422
+ public void onSuccess(TXIoTCallSession.ContactsResult result) {
423
+ if (result == null || result.contacts == null) {
424
+ return;
425
+ }
426
+ for (TXIoTCallSession.Contact contact : result.contacts) {
427
+ Log.i(TAG, "contact: " + contact.userId + " / " + contact.userName);
428
+ if (mTargetUserId == null) {
429
+ mTargetUserId = contact.userId;
430
+ }
431
+ }
432
+ if (result.nextCursor != null && !result.nextCursor.isEmpty()) {
433
+ fetchAllContacts(result.nextCursor);
434
+ } else if (mTargetUserId != null) {
435
+ makeCall(mTargetUserId);
436
+ }
437
+ }
438
+
439
+ @Override
440
+ public void onError(int code, String desc) {
441
+ Log.e(TAG, "getContacts failed: " + code + ", " + desc);
442
+ }
443
+ });
444
+ }
445
+
446
+ private void makeCall(String userId) {
447
+ TXIoTCallSession.Option option = new TXIoTCallSession.Option();
448
+ option.mediaContent = TXIoTCallSession.MediaContent.AUDIO_VIDEO;
449
+
450
+ mCallSession.call(userId, option, new TXIoTCallback() {
451
+ @Override
452
+ public void onSuccess() {
453
+ Log.i(TAG, "call request sent");
454
+ }
455
+
456
+ @Override
457
+ public void onError(int code, String desc) {
458
+ Log.e(TAG, "call failed: " + code + ", " + desc);
459
+ }
460
+ });
461
+ }
462
+
463
+ private void startCallStreams() {
464
+ int ret = mCallSession.openCamera(true, mLocalView);
465
+ if (ret != TXIoTError.SUCCESS) {
466
+ Log.e(TAG, "openCamera failed: " + ret);
467
+ }
468
+ ret = mCallSession.openMicrophone();
469
+ if (ret != TXIoTError.SUCCESS) {
470
+ Log.e(TAG, "openMicrophone failed: " + ret);
471
+ }
472
+ ret = mCallSession.startRemoteView(mTargetUserId, mRemoteView);
473
+ if (ret != TXIoTError.SUCCESS) {
474
+ Log.e(TAG, "startRemoteView failed: " + ret);
475
+ }
476
+ }
477
+
478
+ private void stopCallStreams() {
479
+ if (mTargetUserId != null) {
480
+ mCallSession.stopRemoteView(mTargetUserId);
481
+ }
482
+ mCallSession.closeCamera();
483
+ mCallSession.closeMicrophone();
484
+ }
485
+
486
+ private void hangupCall() {
487
+ if (!mInCall || mTargetUserId == null) {
488
+ return;
489
+ }
490
+ mCallSession.hangup(mTargetUserId, null);
491
+ }
492
+
493
+ @Override
494
+ protected void onDestroy() {
495
+ stopCallStreams();
496
+ mCallSession.removeListener(mListener);
497
+ super.onDestroy();
498
+ }
499
+ }
500
+ ```
501
+
502
+ > **说明:**
503
+ > 1. 示例中省略了登录与初始化的细节,请参考 登录与注册 完成登录。
504
+ > 2. 以上仅为单人通话场景演示。监控/通话及通话中接听第二个呼入电话等复杂场景,请参考 SDK 自带 Demo 的 `CallActivity`。
505
+
506
+ ## 编译并运行
507
+
508
+ Demo 已开源,仓库地址:[github.com/Tencent-RTC/Tencent_IoT_Device](https://github.com/Tencent-RTC/Tencent_IoT_Device),Android Demo 位于顶层 `Android/` 目录。
509
+ 1. 使用 `git clone` 将开源 Demo 从 GitHub 克隆到本地。
510
+
511
+ 2. 打开 Android Studio,点击 Open 导入工程,等待 Gradle Sync 完成。
512
+
513
+ 3. 连接 Android 真机,点击工具栏 Run 编译运行。进入应用后完成登录,即可在首页进入 `ContactsActivity` 选择联系人发起通话。
514
+
515
+ ``` bash
516
+ # 也可在控制台打包 APK 后发送到手机安装
517
+ ./gradlew :app:assembleDebug
518
+ ```
519
+
520
+ ## 常见问题
521
+
522
+ |现象|排查建议|
523
+ |---------|---------|
524
+ |`getContacts` 回调返回联系人列表为空。|确认设备已完成 TWeCall 激活与小程序授权;确认设备已绑定可呼叫联系人。|
525
+ |`call` 返回成功但回调提示 `tweCall device not active`。|TWeCall 是增值服务,需要在控制台激活,详见 [TWeCall 激活](https://cloud.tencent.com/document/product/1081/106587)。|
526
+ |`call` 返回成功但回调提示 `WeChat VoIP API error`。|检查小程序中设备是否授权 VoIP 音视频通话。|
527
+ |`call` 返回 `NOT_INITIALIZED`(-4)或 `NOT_LOGGED_IN`(-15)。|确认 SDK 已初始化且登录成功在线(参见 登录与注册)。|
528
+ |`call` 返回成功但长时间无 `onCallAccepted`。|等待 `onCallTimeout`;确认 `userId` 格式正确(`modelId/wxAppId/openId`);确认小程序端在线且已授权。|
529
+ |`onCallAccepted` 后对端看不到画面。|确认已调用 `openCamera` 且返回 `TXIoTError.SUCCESS`;确认已获得 `CAMERA` 运行时权限;确认摄像头未被其他应用占用。|
530
+ |`onCallAccepted` 后对端听不到声音。|确认已调用 `openMicrophone` 且返回 `TXIoTError.SUCCESS`;确认已获得 `RECORD_AUDIO` 运行时权限。|
531
+ |设备端看不到对端画面。|确认已调用 `startRemoteView` 且 `userId` 与通话对端一致;确认 `TXCloudVideoView` 已正确添加到布局。|
532
+ |通话结束后摄像头/麦克风仍被占用。|确认在 `onCallHangup` 回调及页面销毁(`onDestroy`)时调用了 `closeCamera` 与 `closeMicrophone` 释放采集资源。|
533
+ |`getContacts` 返回 `INVALID_ARGUMENT`(-3)。|确认 `limit` 在 (0, 1024] 范围内。|
534
+