@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,681 @@
1
+ ---
2
+ product: iot
3
+ framework:
4
+ - linux
5
+ types:
6
+ - feature
7
+ retrievable_scope: always
8
+ feature_domain: device
9
+ ---
10
+
11
+ TWeCall 是腾讯云物联网开发平台提供的设备与微信小程序之间的双向音视频通话能力。设备端一键呼叫,微信小程序端持续响铃提醒,接通后即可进行音视频通话,达到微信原生通话体验。
12
+
13
+ 本文将介绍设备如何实现**获取小程序联系人列表**、**呼叫微信小程序**、**响应通话状态回调**与**挂断通话**,帮助您快速完成 TWeCall(微信通话)的设备端接入。
14
+
15
+ ## 前提条件
16
+ - 已完成 登录与注册 文档中的登录功能,设备能够成功 `tc_iot_login` 并保持在线。
17
+
18
+ - 已在物联网开发平台完成 TWeCall 服务激活与小程序授权,详见 [微信通话服务(TWeCall)](https://cloud.tencent.com/document/product/1081/135239#ce474e1e-601f-439d-9249-7600bcb6fa2b)。
19
+
20
+ - 已完成小程序接入文档 设备呼叫小程序 中授权小程序音视频通话。
21
+
22
+ ## 接入步骤
23
+
24
+ TWeCall 设备端接入分为以下步骤:
25
+ 1. 注册通话事件回调。
26
+
27
+ 2. 获取联系人列表。
28
+
29
+ 3. 发起呼叫。
30
+
31
+ 4. 处理通话状态回调。
32
+
33
+ 5. 创建通话推流通道并推送音视频帧。
34
+
35
+ 6. 挂断通话。
36
+
37
+ ### 步骤 1:注册通话事件回调
38
+
39
+ 调用 `tc_iot_av_init` 初始化音视频模块并注册通话事件回调。设备作为主叫时,需要关注对端的接听、拒绝、超时、挂断回调;设备作为被叫时,需要关注来电请求回调。
40
+ ``` c
41
+ tc_iot_error_e tc_iot_av_init(const tc_iot_av_observer_s *observer);
42
+ ```
43
+
44
+ **observer 回调说明**
45
+ | 回调 | 触发时机 | 说明 |
46
+ | --- | --- | --- |
47
+ | <code>on_call_requested</code> | 收到对端(小程序)发起的来电请求。 | 设备作为被叫时触发,在此回调中调用<br><code>tc_iot_av_accept</code> 接听或 <code>tc_iot_av_reject</code> 拒绝。 |
48
+ | <code>on_call_accepted</code> | 对端接听呼叫。 | 设备作为主叫时触发,此时可开始推送音视频。 |
49
+ | <code>on_call_rejected</code> | 对端拒绝呼叫。 | 设备作为主叫时触发。 |
50
+ | <code>on_call_timeout</code> | 对端无人接听,呼叫超时。 | 设备作为主叫时触发。 |
51
+ | <code>on_call_hangup</code> | 对端主动挂断。 | 通话过程中对端挂断时触发。 |
52
+ | <code>on_audio_frame_received</code> | 收到对端音频帧。 | 用于播放对端音频。 |
53
+ | <code>on_video_frame_received</code> | 收到对端视频帧。 | 用于播放对端视频。 |
54
+
55
+ > **注意:**
56
+ > `observer` 在 `tc_iot_av_init` 时会被 SDK 内部拷贝,传入栈变量即可,无需长期保活。
57
+ >
58
+
59
+ ``` c
60
+ // 通话状态回调
61
+ static void on_call_accepted(const tc_iot_contact_s *contact) {
62
+ printf("[twecall] on_call_accepted: user_id=%s\n", contact->user_id);
63
+ // 对端已接听,开始上推音视频(见步骤 5)
64
+ start_call_streams();
65
+ }
66
+
67
+ static void on_call_rejected(const tc_iot_contact_s *contact) {
68
+ printf("[twecall] on_call_rejected: user_id=%s\n", contact->user_id);
69
+ // 对端拒接,清理本地状态
70
+ }
71
+
72
+ static void on_call_timeout(const tc_iot_contact_s *contact) {
73
+ printf("[twecall] on_call_timeout: user_id=%s\n", contact->user_id);
74
+ // 呼叫超时,清理本地状态
75
+ }
76
+
77
+ static void on_call_hangup(const tc_iot_contact_s *contact) {
78
+ printf("[twecall] on_call_hangup: user_id=%s\n", contact->user_id);
79
+ // 对端挂断,停止推流并清理通道(见步骤 5/6)
80
+ stop_call_streams();
81
+ }
82
+
83
+ // 被叫:收到来电请求
84
+ static void on_call_requested(const tc_iot_contact_s *contact, tc_iot_call_option_t option) {
85
+ printf("[twecall] on_call_requested: user_id=%s media=%d quality=%d\n",
86
+ contact->user_id, option.media_content, option.video_quality);
87
+ // 这里选择接听,也可调用 tc_iot_av_reject 拒绝
88
+ tc_iot_av_accept(contact, NULL);
89
+ }
90
+
91
+ // 初始化
92
+ tc_iot_av_observer_s observer;
93
+ memset(&observer, 0, sizeof(observer));
94
+ observer.on_call_requested = on_call_requested;
95
+ observer.on_call_accepted = on_call_accepted;
96
+ observer.on_call_rejected = on_call_rejected;
97
+ observer.on_call_timeout = on_call_timeout;
98
+ observer.on_call_hangup = on_call_hangup;
99
+
100
+ tc_iot_error_e rc = tc_iot_av_init(&observer);
101
+ if (rc != TC_IOT_ERR_SUCCESS) {
102
+ printf("tc_iot_av_init failed: %d\n", rc);
103
+ }
104
+ ```
105
+
106
+ ### 步骤 2:获取联系人列表
107
+
108
+ 调用 `tc_iot_av_get_contacts` 拉取可呼叫的微信小程序联系人列表。接口采用游标(cursor)分页,首次调用传 `NULL`,后续传入上一次回调返回的 `next_cursor` 继续拉取,直到 `next_cursor` 为 `NULL` 表示已到末尾。
109
+
110
+ > **说明:**
111
+ > 如果设备调用 `tc_iot_av_get_contacts` 后获取到联系人列表为空,说明小程序没有正常完成音视频授权。建议用户将小程序删除,重新添加小程序。小程序第一次授权时,会有如下弹窗提示。
112
+ >
113
+ >
114
+
115
+ ``` c
116
+ tc_iot_error_e tc_iot_av_get_contacts(const char *cursor, uint32_t limit,
117
+ tc_iot_av_contacts_cb callback);
118
+ ```
119
+
120
+ |参数|说明|
121
+ |---------|---------|
122
+ |`cursor`|分页游标,首次传 `NULL`(SDK 内部等价于 `"0"`),后续传入上次回调的 `next_cursor`。|
123
+ |`limit`|本次拉取数量,有效范围 (0, 1024]。|
124
+ |`callback`|结果回调,原型见下。|
125
+
126
+ **回调原型**
127
+ ``` c
128
+ typedef void (*tc_iot_av_contacts_cb)(tc_iot_error_e error_code, const char *error_message,
129
+ const tc_iot_contact_s *contacts, uint32_t count,
130
+ const char *next_cursor);
131
+ ```
132
+
133
+ |参数|说明|
134
+ |---------|---------|
135
+ |`error_code`|`TC_IOT_ERR_SUCCESS` 表示成功,其余为失败码。|
136
+ |`contacts`|联系人数组指针,失败时为 `NULL`。|
137
+ |`count`|本次返回的联系人数量,`0` 表示已无更多联系人。|
138
+ |`next_cursor`|下一页游标,`NULL` 表示已是最后一页,无需继续拉取。|
139
+
140
+ **联系人结构体**
141
+ ``` c
142
+ typedef struct {
143
+ const char *user_id; // 呼叫目标标识,格式 "modelId/wxAppId/openId"
144
+ const char *user_name; // 用户昵称(可能为空)
145
+ const char *avatar_url; // 头像 URL(可能为空)
146
+ } tc_iot_contact_s;
147
+ ```
148
+
149
+ > **说明:**
150
+ > `user_id` 是发起呼叫的关键标识,由 `modelId`、`wxAppId`、`openId` 三段以 `/` 拼接而成。该字符串内存由 SDK 在回调期间管理,回调返回后会被释放,如需长期使用请自行拷贝。
151
+ >
152
+
153
+ **示例:完整拉取所有联系人**
154
+ ``` c
155
+ static const char *g_target_user_id = NULL;
156
+
157
+ static void on_get_contacts(tc_iot_error_e error_code, const char *error_message,
158
+ const tc_iot_contact_s *contacts, uint32_t count,
159
+ const char *next_cursor) {
160
+ printf("[twecall] get_contacts: code=%d count=%u next_cursor=%s\n",
161
+ error_code, count, next_cursor ? next_cursor : "(end)");
162
+
163
+ if (error_code != TC_IOT_ERR_SUCCESS) {
164
+ printf("get_contacts failed: %s\n", error_message ? error_message : "");
165
+ return;
166
+ }
167
+
168
+ for (uint32_t i = 0; i < count; i++) {
169
+ printf(" [%u] user_id=%s name=%s\n", i, contacts[i].user_id,
170
+ contacts[i].user_name ? contacts[i].user_name : "");
171
+ // 记录第一个联系人作为呼叫目标
172
+ if (g_target_user_id == NULL) {
173
+ g_target_user_id = strdup(contacts[i].user_id);
174
+ }
175
+ }
176
+
177
+ // next_cursor 非空说明还有更多联系人,继续翻页
178
+ if (next_cursor != NULL) {
179
+ tc_iot_av_get_contacts(next_cursor, 50, on_get_contacts);
180
+ }
181
+ }
182
+
183
+ // 首次拉取,每页 50 条
184
+ tc_iot_av_get_contacts(NULL, 50, on_get_contacts);
185
+ ```
186
+
187
+ ### 步骤 3:发起呼叫
188
+
189
+ #### 呼叫体验版小程序(重要)
190
+
191
+ > **特别强调:**
192
+ >
193
+ > - 开发调试阶段,设备端**必须**在**初始化之后、登录之前**调用 `tc_iot_call_experiment_api` 显式指定呼叫的小程序版本为体验版(DEMO)或开发版(DEBUG),否则会因小程序版本不匹配导致**呼叫失败或无法接通**。
194
+
195
+ > ``
196
+ > `/* `
197
+ > ` "DEBUG" 开发版 `
198
+ > ` "DEMO" 体验版`
199
+ > `*/`
200
+ > `tc_iot_call_experiment_api("set_wx_miniapp_flavor", "DEMO", NULL);`
201
+ > ``> - 待完成体验版功能自测后,将设备寄送至微信团队进行验证。验证通过后,小程序的 VoIP 音视频能力方可正式上线发布,小程序 VoIP 音视频**正式上线**后,无需再调用此接口,SDK 将默认呼叫线上版小程序。
202
+
203
+ 选定联系人后,调用 `tc_iot_av_call` 向该联系人(微信小程序)发起呼叫。接口为异步调用,结果通过 `callback` 返回。
204
+ ``` c
205
+ tc_iot_error_e tc_iot_av_call(const tc_iot_contact_s *contact, tc_iot_call_option_t option,
206
+ tc_iot_av_operation_cb callback);
207
+ ```
208
+
209
+ |参数|说明|
210
+ |---------|---------|
211
+ |`contact`|呼叫目标,`contact.user_id` 必填(取自 `tc_iot_av_get_contacts` 返回的 `user_id`)。|
212
+ |`option`|呼叫选项,见下表。|
213
+ |`callback`|操作结果回调:`TC_IOT_ERR_SUCCESS` 表示呼叫请求已成功发出,对端是否接听需等待 步骤4 的状态回调。|
214
+
215
+ **呼叫选项** `tc_iot_call_option_t`
216
+
217
+ |字段|说明|
218
+ |---------|---------|
219
+ |`media_content`|媒体内容,见下表枚举。|
220
+ |`video_quality`|视频清晰度,见下表枚举。|
221
+ |`custom_data`|自定义数据(最长256字节),随呼叫信令透传到小程序端。|
222
+
223
+ **媒体内容枚举** `tc_iot_media_content_e`
224
+
225
+ |取值|说明|
226
+ |---------|---------|
227
+ |`TC_IOT_MEDIA_CONTENT_AUDIO`|仅音频通话。|
228
+ |`TC_IOT_MEDIA_CONTENT_VIDEO`|仅视频通话。|
229
+ |`TC_IOT_MEDIA_CONTENT_AUDIO_VIDEO`|音视频通话(默认推荐)。|
230
+
231
+ **清晰度枚举** `tc_iot_video_quality_e`
232
+
233
+ |取值|说明|
234
+ |---------|---------|
235
+ |`TC_IOT_VIDEO_QUALITY_LD`|流畅(低清晰度)。|
236
+ |`TC_IOT_VIDEO_QUALITY_SD`|标清。|
237
+ |`TC_IOT_VIDEO_QUALITY_HD`|高清。|
238
+ |`TC_IOT_VIDEO_QUALITY_FHD`|超清(全高清)。|
239
+
240
+ **示例**
241
+ ``` c
242
+ static void on_call_op(tc_iot_error_e error_code, const char *error_message) {
243
+ printf("[twecall] call op: code=%d msg=%s\n", error_code, error_message ? error_message : "");
244
+ }
245
+
246
+ // 使用联系人列表中的 user_id 发起音视频呼叫
247
+ tc_iot_contact_s contact = {0};
248
+ contact.user_id = g_target_user_id; // 取自步骤 2
249
+ contact.user_name = "";
250
+ contact.avatar_url = "";
251
+
252
+ tc_iot_call_option_t option = {0};
253
+ option.media_content = TC_IOT_MEDIA_CONTENT_AUDIO_VIDEO;
254
+ option.video_quality = TC_IOT_VIDEO_QUALITY_SD;
255
+
256
+ tc_iot_error_e rc = tc_iot_av_call(&contact, option, on_call_op);
257
+ if (rc != TC_IOT_ERR_SUCCESS) {
258
+ printf("tc_iot_av_call failed: %d\n", rc);
259
+ }
260
+ ```
261
+
262
+ > **注意:**
263
+ > `tc_iot_av_call` 返回 `TC_IOT_ERR_SUCCESS` 仅表示呼叫信令已发出,并不代表通话已建立。需等待 `on_call_accepted` 回调后,通话才算真正接通,此时再开始上推音视频。
264
+ >
265
+
266
+ ### 步骤 4:处理通话状态回调
267
+
268
+ 呼叫发出后,设备会依次收到以下回调,业务侧需在对应回调中管理本地状态:
269
+
270
+ |回调|业务建议处理|
271
+ |---------|---------|
272
+ |`on_call_accepted`|通话接通,**创建推流通道并开始推送音视频帧**(步骤5)。|
273
+ |`on_call_rejected`|对端拒接,清理呼叫状态,恢复待机。|
274
+ |`on_call_timeout`|无人接听,清理呼叫状态,可重试或提示用户。|
275
+ |`on_call_hangup`|通话中挂断,**销毁推流通道**(步骤6),停止采集。|
276
+
277
+ **示例:状态机式处理**
278
+ ``` c
279
+ static bool g_in_call = false;
280
+ static tc_iot_av_channel_t *g_video_channel = NULL;
281
+ static tc_iot_av_channel_t *g_audio_channel = NULL;
282
+
283
+ static void on_call_accepted(const tc_iot_contact_s *contact) {
284
+ printf("[twecall] on_call_accepted: user_id=%s\n", contact->user_id);
285
+ g_in_call = true;
286
+ start_call_streams(); // 见步骤 5
287
+ }
288
+
289
+ static void on_call_rejected(const tc_iot_contact_s *contact) {
290
+ printf("[twecall] on_call_rejected: user_id=%s\n", contact->user_id);
291
+ g_in_call = false;
292
+ }
293
+
294
+ static void on_call_timeout(const tc_iot_contact_s *contact) {
295
+ printf("[twecall] on_call_timeout: user_id=%s\n", contact->user_id);
296
+ g_in_call = false;
297
+ }
298
+
299
+ static void on_call_hangup(const tc_iot_contact_s *contact) {
300
+ printf("[twecall] on_call_hangup: user_id=%s\n", contact->user_id);
301
+ g_in_call = false;
302
+ stop_call_streams(); // 见步骤 6
303
+ }
304
+ ```
305
+
306
+ > **说明:**
307
+ > 建议在收到 `on_call_accepted` 后再启动编码器与推流,避免对端尚未接听就占用编码资源。`on_call_rejected`、`on_call_timeout`、`on_call_hangup` 均表示通话结束,应统一做资源清理。
308
+ >
309
+
310
+ ### 步骤 5:创建通话推流通道并推送音视频帧
311
+
312
+ 通话接通后(`on_call_accepted` 触发),创建音视频发送通道并向 SDK 推送编码后的音视频裸流。
313
+ ``` c
314
+ tc_iot_av_channel_t *tc_iot_create_video_channel(int channel_id, tc_iot_video_quality_e quality);
315
+ tc_iot_av_channel_t *tc_iot_create_audio_channel();
316
+
317
+ tc_iot_error_e tc_iot_push_video_frame(tc_iot_av_channel_t *av_channel, const tc_iot_video_frame *frame);
318
+ tc_iot_error_e tc_iot_push_audio_frame(tc_iot_av_channel_t *av_channel, const tc_iot_audio_frame *frame);
319
+
320
+ tc_iot_error_e tc_iot_destroy_video_channel(tc_iot_av_channel_t *av_channel);
321
+ tc_iot_error_e tc_iot_destroy_audio_channel(tc_iot_av_channel_t *av_channel);
322
+ ```
323
+
324
+ |接口|说明|
325
+ |---------|---------|
326
+ |`tc_iot_create_video_channel`|创建视频发送通道,`channel_id` 通话场景固定为 `0`。|
327
+ |`tc_iot_create_audio_channel`|创建音频发送通道,无需传 `channel_id`。|
328
+ |`tc_iot_push_video_frame`|推送一帧编码后的视频。|
329
+ |`tc_iot_push_audio_frame`|推送一帧编码后的音频。|
330
+ |`tc_iot_destroy_video_channel`|销毁视频通道。|
331
+ |`tc_iot_destroy_audio_channel`|销毁音频通道。|
332
+
333
+ **视频帧** `tc_iot_video_frame`
334
+
335
+ |字段|说明|
336
+ |---------|---------|
337
+ |`codec`|视频编码格式,`H264` , `H265 或 MJPEG`。|
338
+ |`type`|帧类型,`IDR` 关键帧或 `P` 帧。|
339
+ |`rotation`|画面旋转角度(0/90/180/270)。|
340
+ |`width` / `height`|画面宽高(像素)。|
341
+ |`data` / `data_size`|编码后视频裸流数据指针与长度。|
342
+ |`pts_ms`|帧时间戳(毫秒),传0的话由 SDK 内部填写。|
343
+
344
+ **音频帧** `tc_iot_audio_frame`
345
+
346
+ |字段|说明|
347
+ |---------|---------|
348
+ |`codec`|音频编码格式,推荐 `PCM` ,`OPUS` ,`AAC`,`G722`。|
349
+ |`sample_rate`|采样率,推荐 `16000`。|
350
+ |`channels`|声道数,推荐 `MONO`(单声道)。|
351
+ |`frame_duration_ms`|单帧时长(毫秒),推荐 `20ms`。|
352
+ |`data` / `data_size`|编码后音频裸流数据指针与长度。|
353
+ |`pts_ms`|帧时间戳(毫秒)。|
354
+
355
+ > **注意:**
356
+ > - 设备通常只有一路麦克风采集源,`tc_iot_create_audio_channel` 建议全局只创建一次,多路复用。
357
+ > - 建议推送第一个 IDR 关键帧之后才开始持续推流,以保证对端能快速解码出画面。
358
+
359
+ **示例**
360
+ ``` c
361
+ static void start_call_streams(void) {
362
+ // 视频通道:通话场景 channel_id = 0
363
+ g_video_channel = tc_iot_create_video_channel(0, TC_IOT_VIDEO_QUALITY_SD);
364
+ // 音频通道:全局唯一
365
+ g_audio_channel = tc_iot_create_audio_channel();
366
+ // 之后由采集线程持续调用 push 推流
367
+ }
368
+
369
+ // 推送一帧视频(在视频采集/编码线程中调用)
370
+ static void push_one_video_frame(void) {
371
+ tc_iot_video_frame frame = {0};
372
+ frame.codec = TC_IOT_VIDEO_CODEC_H264;
373
+ frame.type = TC_IOT_VIDEO_FRAME_TYPE_IDR; // 首帧用 IDR
374
+ frame.rotation = TC_IOT_VIDEO_ROTATION_0;
375
+ frame.width = 640;
376
+ frame.height = 480;
377
+ frame.data = encoded_video_buf;
378
+ frame.data_size = encoded_video_len;
379
+ frame.pts_ms = current_time_ms();
380
+ tc_iot_push_video_frame(g_video_channel, &frame);
381
+ }
382
+
383
+ // 推送一帧音频(在音频采集线程中调用)
384
+ static void push_one_audio_frame(void) {
385
+ tc_iot_audio_frame frame = {0};
386
+ frame.codec = TC_IOT_AUDIO_CODEC_PCM;
387
+ frame.sample_rate = TC_IOT_AUDIO_SAMPLE_RATE_16000;
388
+ frame.channels = TC_IOT_AUDIO_CHANNEL_MONO;
389
+ frame.frame_duration_ms = 20;
390
+ frame.data = audio_buf;
391
+ frame.data_size = audio_len;
392
+ frame.pts_ms = current_time_ms();
393
+ tc_iot_push_audio_frame(g_audio_channel, &frame);
394
+ }
395
+ ```
396
+
397
+ ### 步骤 6:挂断通话
398
+
399
+ 通话过程中,任意一方均可挂断。设备主动挂断调用 `tc_iot_av_hangup`;对端挂断时设备会收到 `on_call_hangup` 回调。
400
+
401
+ 无论哪种情况,都应销毁推流通道、停止采集。
402
+ ``` c
403
+ tc_iot_error_e tc_iot_av_hangup(const tc_iot_contact_s *contact, tc_iot_av_operation_cb callback);
404
+ ```
405
+
406
+ |参数|说明|
407
+ |---------|---------|
408
+ |`contact`|通话对端,`contact.user_id` 需与呼叫/接听时一致。|
409
+ |`callback`|操作结果回调。|
410
+
411
+ **示例**
412
+ ``` c
413
+ static void on_hangup_op(tc_iot_error_e error_code, const char *error_message) {
414
+ printf("[twecall] hangup op: code=%d msg=%s\n", error_code, error_message ? error_message : "");
415
+ }
416
+
417
+ // 主动挂断
418
+ tc_iot_contact_s contact = {0};
419
+ contact.user_id = g_target_user_id;
420
+ tc_iot_av_hangup(&contact, on_hangup_op);
421
+
422
+ // 销毁通道(主动挂断与收到 on_call_hangup 后均需调用)
423
+ static void stop_call_streams(void) {
424
+ if (g_video_channel) {
425
+ tc_iot_destroy_video_channel(g_video_channel);
426
+ g_video_channel = NULL;
427
+ }
428
+ if (g_audio_channel) {
429
+ tc_iot_destroy_audio_channel(g_audio_channel);
430
+ g_audio_channel = NULL;
431
+ }
432
+ }
433
+ ```
434
+
435
+ > **注意:**
436
+ > `tc_iot_av_hangup` 的 `callback` 用于确认挂断信令发送结果。即使主动挂断,也建议在 `on_call_hangup` 或 `callback` 中统一做通道销毁,避免重复释放。
437
+ >
438
+
439
+ ## 完整示例代码
440
+
441
+ 以下示例整合上述步骤,演示设备拉取联系人、呼叫小程序、接通后推流、挂断的完整流程。
442
+ ``` c
443
+ #include <stdbool.h>
444
+ #include <stdio.h>
445
+ #include <stdlib.h>
446
+ #include <string.h>
447
+
448
+ #include "tc_iot.h"
449
+ #include "tc_iot_av.h"
450
+
451
+ // ==================== 全局状态 ====================
452
+
453
+ static bool g_in_call = false;
454
+ static tc_iot_av_channel_t *g_video_channel = NULL;
455
+ static tc_iot_av_channel_t *g_audio_channel = NULL;
456
+ static char g_target_user_id[128] = {0};
457
+
458
+ // ==================== 工具 ====================
459
+
460
+ static uint64_t current_time_ms(void) {
461
+ struct timespec ts;
462
+ clock_gettime(CLOCK_MONOTONIC, &ts);
463
+ return (uint64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
464
+ }
465
+
466
+ static void start_call_streams(void) {
467
+ g_video_channel = tc_iot_create_video_channel(0, TC_IOT_VIDEO_QUALITY_SD);
468
+ g_audio_channel = tc_iot_create_audio_channel();
469
+ printf("[twecall] call streams started\n");
470
+ }
471
+
472
+ static void stop_call_streams(void) {
473
+ if (g_video_channel) {
474
+ tc_iot_destroy_video_channel(g_video_channel);
475
+ g_video_channel = NULL;
476
+ }
477
+ if (g_audio_channel) {
478
+ tc_iot_destroy_audio_channel(g_audio_channel);
479
+ g_audio_channel = NULL;
480
+ }
481
+ printf("[twecall] call streams stopped\n");
482
+ }
483
+
484
+ // ==================== 通话状态回调 ====================
485
+
486
+ static void on_call_requested(const tc_iot_contact_s *contact, tc_iot_call_option_t option) {
487
+ printf("[twecall] on_call_requested: user_id=%s media=%d quality=%d\n",
488
+ contact->user_id, option.media_content, option.video_quality);
489
+ // 设备作为被叫,这里选择接听
490
+ tc_iot_av_accept(contact, NULL);
491
+ }
492
+
493
+ static void on_call_accepted(const tc_iot_contact_s *contact) {
494
+ printf("[twecall] on_call_accepted: user_id=%s\n", contact->user_id);
495
+ g_in_call = true;
496
+ start_call_streams();
497
+ }
498
+
499
+ static void on_call_rejected(const tc_iot_contact_s *contact) {
500
+ printf("[twecall] on_call_rejected: user_id=%s\n", contact->user_id);
501
+ g_in_call = false;
502
+ }
503
+
504
+ static void on_call_timeout(const tc_iot_contact_s *contact) {
505
+ printf("[twecall] on_call_timeout: user_id=%s\n", contact->user_id);
506
+ g_in_call = false;
507
+ }
508
+
509
+ static void on_call_hangup(const tc_iot_contact_s *contact) {
510
+ printf("[twecall] on_call_hangup: user_id=%s\n", contact->user_id);
511
+ g_in_call = false;
512
+ stop_call_streams();
513
+ }
514
+
515
+ static void on_audio_frame_received(const tc_iot_audio_frame *frame) {
516
+ // 实际接入时:将 frame->data 送入音频播放器
517
+ }
518
+
519
+ static void on_video_frame_received(const tc_iot_video_frame *frame) {
520
+ // 实际接入时:将 frame->data 送入视频解码器/渲染器
521
+ }
522
+
523
+ static void on_av_op(tc_iot_error_e error_code, const char *error_message) {
524
+ printf("[twecall] av op: code=%d msg=%s\n", error_code, error_message ? error_message : "");
525
+ }
526
+
527
+ // ==================== 获取联系人 ====================
528
+
529
+ static void make_call(const char *user_id);
530
+
531
+ static void on_get_contacts(tc_iot_error_e error_code, const char *error_message,
532
+ const tc_iot_contact_s *contacts, uint32_t count,
533
+ const char *next_cursor) {
534
+ printf("[twecall] get_contacts: code=%d count=%u next_cursor=%s\n",
535
+ error_code, count, next_cursor ? next_cursor : "(end)");
536
+
537
+ if (error_code != TC_IOT_ERR_SUCCESS) {
538
+ printf("get_contacts failed: %s\n", error_message ? error_message : "");
539
+ return;
540
+ }
541
+
542
+ for (uint32_t i = 0; i < count; i++) {
543
+ printf(" [%u] user_id=%s name=%s\n", i, contacts[i].user_id,
544
+ contacts[i].user_name ? contacts[i].user_name : "");
545
+ if (g_target_user_id[0] == '\0' && contacts[i].user_id) {
546
+ strncpy(g_target_user_id, contacts[i].user_id, sizeof(g_target_user_id) - 1);
547
+ }
548
+ }
549
+
550
+ // 还有更多联系人,继续翻页
551
+ if (next_cursor != NULL) {
552
+ tc_iot_av_get_contacts(next_cursor, 50, on_get_contacts);
553
+ return;
554
+ }
555
+
556
+ // 拉取完成,呼叫第一个联系人
557
+ if (g_target_user_id[0] != '\0') {
558
+ make_call(g_target_user_id);
559
+ } else {
560
+ printf("[twecall] no contact to call\n");
561
+ }
562
+ }
563
+
564
+ // ==================== 发起呼叫 ====================
565
+
566
+ static void make_call(const char *user_id) {
567
+ printf("[twecall] calling user_id=%s\n", user_id);
568
+
569
+ tc_iot_contact_s contact = {0};
570
+ contact.user_id = user_id;
571
+ contact.user_name = "";
572
+ contact.avatar_url = "";
573
+
574
+ tc_iot_call_option_t option = {0};
575
+ option.media_content = TC_IOT_MEDIA_CONTENT_AUDIO_VIDEO;
576
+ option.video_quality = TC_IOT_VIDEO_QUALITY_SD;
577
+
578
+ tc_iot_error_e rc = tc_iot_av_call(&contact, option, on_av_op);
579
+ if (rc != TC_IOT_ERR_SUCCESS) {
580
+ printf("[twecall] tc_iot_av_call failed: %d\n", rc);
581
+ }
582
+ }
583
+
584
+ // ==================== 挂断 ====================
585
+
586
+ static void hangup_call(void) {
587
+ if (!g_in_call) {
588
+ return;
589
+ }
590
+ tc_iot_contact_s contact = {0};
591
+ contact.user_id = g_target_user_id;
592
+ tc_iot_av_hangup(&contact, on_av_op);
593
+ }
594
+
595
+ // ==================== main ====================
596
+
597
+ int main(int argc, char **argv) {
598
+ // 1) 初始化 + 登录(参考快速接入文档)
599
+ // ... tc_iot_init / tc_iot_login ...
600
+
601
+ // 2) 注册通话事件回调
602
+ tc_iot_av_observer_s observer;
603
+ memset(&observer, 0, sizeof(observer));
604
+ observer.on_call_requested = on_call_requested;
605
+ observer.on_call_accepted = on_call_accepted;
606
+ observer.on_call_rejected = on_call_rejected;
607
+ observer.on_call_timeout = on_call_timeout;
608
+ observer.on_call_hangup = on_call_hangup;
609
+ observer.on_audio_frame_received = on_audio_frame_received;
610
+ observer.on_video_frame_received = on_video_frame_received;
611
+
612
+ tc_iot_error_e rc = tc_iot_av_init(&observer);
613
+ if (rc != TC_IOT_ERR_SUCCESS) {
614
+ printf("tc_iot_av_init failed: %d\n", rc);
615
+ return -1;
616
+ }
617
+
618
+ // 3) 拉取联系人,回调中自动发起呼叫
619
+ tc_iot_av_get_contacts(NULL, 50, on_get_contacts);
620
+
621
+ // 4) 通话结束后挂断
622
+ // hangup_call();
623
+
624
+ // 5) 反初始化
625
+ tc_iot_av_deinit();
626
+ return 0;
627
+ }
628
+ ```
629
+
630
+ > **说明:**
631
+ > 1. 示例中省略了 `tc_iot_init` / `tc_iot_login` 的细节,请参考 登录与注册 完成登录。
632
+ > 2. 实际接入时,音视频帧推送需替换为真实摄像头采集与编码逻辑。
633
+ > 3. SDK 自带 `iot_video_demo` 示例已完整实现上述流程,可参考 `src/demo/iot_video_demo/` 目录。
634
+ > 4. 以上仅为单人通话场景演示。监控/通话及呼叫中接听第二个呼入电话等复杂场景,请参考 `iot_video_demo`。
635
+
636
+ ## 编译并运行
637
+
638
+ SDK 自带的 `iot_video_demo` 已集成 TWeCall 完整流程,可直接编译验证:
639
+ ``` bash
640
+ cd iot
641
+
642
+ # Linux 平台(CC TRTC,功能全)
643
+ bash build.sh --platform=linux --trtc=cc
644
+
645
+ # 将 CC TRTC 动态库加入系统动态库搜索路径
646
+ export LD_LIBRARY_PATH=tc_iot_sdk/sdk/lib:$LD_LIBRARY_PATH
647
+
648
+ # 运行(替换为你的设备三元组)
649
+ ./build/iot_video_demo -p YOUR_PRODUCT_ID -d YOUR_DEVICE_NAME -s 'YOUR_DEVICE_SECRET'
650
+ ```
651
+
652
+ 成功启动后会看到:
653
+ ``` c
654
+ tc_iot_av_init success
655
+ ```
656
+
657
+ 在另一个终端通过命名管道 `/tmp/tciot` 发命令:
658
+ ``` c
659
+ # 拉取联系人列表
660
+ echo "get_contacts -n 50" > /tmp/tciot
661
+
662
+ # 呼叫小程序联系人(user_id 取自联系人列表)
663
+ echo "call -u user_id" > /tmp/tciot
664
+
665
+ # 挂断
666
+ echo "hangup -u user_id" > /tmp/tciot
667
+ ```
668
+
669
+ ## 常见问题
670
+ | 现象 | 排查建议 |
671
+ | --- | --- |
672
+ | <code>get_contacts</code> 回调返回 <code>count=0</code> | 确认设备已完成 TWeCall 激活与小程序授权;确认设备已绑定可呼叫联系人。 |
673
+ | <code>tc_iot_av_call</code> 返回成功但回调中提示 <code>TWeCall device not active</code> | TWeCall 是增值服务,需要在控制台激活。<br>单击 <a href="https://cloud.tencent.com/document/product/1081/106587">TWeCall 激活</a> 查看接口说明。 |
674
+ | <code>tc_iot_av_call</code> 返回成功但回调中提示<br><code>wechat VoIP API error</code> | 检查小程序中设备是否授权 VoIP 音视频通话。 |
675
+ | <code>tc_iot_av_call</code> 返回 <code>TC_IOT_ERR_NOT_INITIALIZED</code> | 确认已调用 <code>tc_iot_av_init</code>,且 <code>tc_iot_login</code> 成功在线。 |
676
+ | <code>tc_iot_av_call</code> 返回成功但长时间无 <code>on_call_accepted</code> | 等待 <code>on_call_timeout</code>;确认 <code>user_id</code> 格式正确(<code>modelId/wxAppId/openId</code>);确认小程序端在线且已授权。 |
677
+ | <code>on_call_accepted</code> 后对端看不到画面 | 确认首帧推送的是 IDR 关键帧;确认视频通道已创建且 <code>channel_id=0</code>;确认 <code>width/height</code> 与编码实际尺寸一致。 |
678
+ | <code>on_call_accepted</code> 后对端听不到声音 | 确认音频通道已创建;确认 <code>sample_rate</code>(推荐 16000)、<code>channels</code>(推荐 MONO)配置正确。 |
679
+ | 多次通话后内存持续增长 | 确认每次 <code>on_call_hangup</code> 后均调用了 <code>tc_iot_destroy_video_channel</code> / <code>tc_iot_destroy_audio_channel</code>。 |
680
+ | <code>tc_iot_av_get_contacts</code> 返回 <code>TC_IOT_ERR_INVALID_ARGUMENT</code> | 确认 <code>limit</code> 在 (0, 1024] 范围内。 |
681
+