@tencentcloud/sdk-mcp 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/package.json +1 -1
  2. package/resource/doc/callkit/core-sdk/android/answer-call.md +942 -0
  3. package/resource/doc/callkit/core-sdk/android/make-call.md +876 -0
  4. package/resource/doc/callkit/core-sdk/android/offline-push.md +368 -0
  5. package/resource/doc/callkit/core-sdk/flutter/answer-call.md +1132 -0
  6. package/resource/doc/callkit/core-sdk/flutter/make-call.md +1206 -0
  7. package/resource/doc/callkit/core-sdk/flutter/offline-push.md +357 -0
  8. package/resource/doc/callkit/core-sdk/ios/answer-call.md +1009 -0
  9. package/resource/doc/callkit/core-sdk/ios/make-call.md +1154 -0
  10. package/resource/doc/callkit/core-sdk/ios/offline-push.md +470 -0
  11. package/resource/doc/callkit/core-sdk/uni-app/answer-call.md +1146 -0
  12. package/resource/doc/callkit/core-sdk/uni-app/make-call.md +1267 -0
  13. package/resource/doc/callkit/preset/android/integration.md +1 -1
  14. package/resource/doc/callkit/preset/flutter/integration.md +1 -1
  15. package/resource/doc/callkit/preset/ios/integration.md +1 -1
  16. package/resource/doc/callkit/preset/react/api.md +1 -1
  17. package/resource/doc/callkit/preset/vue/api.md +1 -1
  18. package/tools/call/get_native_callkit_core_integration.js +67 -0
  19. package/tools/call/get_native_callkit_core_integration.js.map +1 -0
  20. package/tools/common/present_framework_choice.js +1 -1
  21. package/tools/common/present_framework_choice.js.map +1 -1
  22. package/tools/definitions/get_native_call_uikit_integration_def.js +9 -3
  23. package/tools/definitions/get_native_call_uikit_integration_def.js.map +1 -1
  24. package/tools/definitions/get_native_callkit_core_integration_def.js +63 -0
  25. package/tools/definitions/get_native_callkit_core_integration_def.js.map +1 -0
  26. package/tools/index.js +2 -0
  27. package/tools/index.js.map +1 -1
  28. package/utils/report-cls-client.js +1 -1
  29. package/utils/report-es-client.js +1 -1
@@ -0,0 +1,368 @@
1
+ 在 Android 平台,当您的应用进程被杀死或处于后台时,若收到音视频通话邀请,对方将无法收到任何通知,导致通话无法接通。因此,集成离线推送是确保您的音视频通话功能可用的必要条件(用户呼叫始终在线的 Web 端坐席等特殊情况除外)。本文档将指导您完成 FCM Data Message 的推送集成步骤。即使应用未运行,也能将通话邀请等关键信令送达设备,从而唤醒应用并启动通话界面。
2
+
3
+ ## 开通服务
4
+
5
+ 进入 IM 控制台 > 插件市场,单击**立即购买**或**免费试用**(每个应用可免费试用一次,有效期7天)。
6
+
7
+ **注意:**
8
+
9
+ 推送插件试用或购买到期后,将自动停止提供推送服务(包括普通消息离线推送、全员/标签推送等服务)。为避免影响您的业务正常使用,请提前 购买/续费。
10
+
11
+ ## 集成建议 [必看]
12
+
13
+ ### 如何选择推送渠道?
14
+
15
+ 由于 FCM 依赖于 Google 服务,请根据您的业务运营区域选择合适的集成策略:
16
+
17
+ **跨国全球业务(涉及国内外):**为确保全球范围内消息的触达率,建议同时集成国内各厂商推送服务以及 FCM 推送服务。
18
+
19
+ **仅限海外市场(不涉及中国大陆):**无需集成国内厂商服务。请直接参考本文档集成 FCM Data Message 即可。
20
+
21
+ **仅限中国大陆境内:**无需集成 FCM。请参考集成 Notification,按需集成 **Notification** (小米、华为、OPPO、vivo 等国内厂商) 推送即可。
22
+
23
+ ### 如何提高通话触达率?
24
+
25
+ 根据我们的经验,超过 90% 的用户接不到通话通知的原因是手动关闭了应用的通知权限。为确保通话可达率,我们强烈建议:
26
+
27
+ 1. **审慎发送通知:**避免向用户推送低质量或无关联的通知,减少用户因骚扰而关闭通知权限的可能性。
28
+
29
+ 2. **提供精细控制:**借鉴微信等优秀应用的做法,在应用设置内为用户提供独立的开关,分别控制"Notification"和"FCM Data Message",而非引导用户去系统设置中一刀切地关闭所有通知。
30
+
31
+ ## 快速接入
32
+
33
+ ### 步骤1:厂商配置
34
+
35
+ 1. 将您自己的应用注册到 FCM 推送平台,得到 **AppID** 和 **AppKey** 等参数以及 `google-services.json` 文件 ,来实现离线推送功能。
36
+
37
+ 2. 登录 即时通信 IM 控制台,在**推送管理** > **接入设置**功能栏,选择 FCM,添加 FCM 的证书,其中,消息类型选择**透传(数据)消息**。
38
+
39
+ ### 步骤2:接入推送插件
40
+
41
+ 1. **添加配置文件:**完成控制台厂商推送信息填写后,下载并添加配置文件到工程。将下载的 `timpush-configs.json` 文件添加到应用模块的 `assets` 目录下,将 `google-services.json` 添加到工程 `app` 目录下。
42
+
43
+ 2. **集成推送插件:**在项目的 `app` 目录下的`build.gradle`文件中添加如下依赖:
44
+
45
+ ```gradle
46
+ implementation "com.tencent.timpush:timpush:latest.release"
47
+ implementation "com.tencent.timpush:fcm:latest.release"
48
+ ```
49
+
50
+ **说明:**
51
+
52
+ TIMPush 需要集成 IM SDK 在**7.9.5666**版本及以上。TIMPush 的版本号及更新信息,可以在 更新日志 中进行查询。
53
+
54
+ ### 步骤3:工程配置
55
+
56
+ 1. 在项目级 `build.gradle` 文件的 `buildscript` > `dependencies` 下添加以下配置:
57
+
58
+ ```gradle
59
+ buildscript {
60
+ dependencies {
61
+ classpath 'com.google.gms:google-services:4.3.15'
62
+ }
63
+ }
64
+ ```
65
+
66
+ 2. 在项目的 `app` 目录下的`build.gradle`文件中添加下方配置
67
+
68
+ ```gradle
69
+ apply plugin: 'com.google.gms.google-services'
70
+ ```
71
+
72
+ 3. 在项目的 `app` 目录下,找到并打开`build.gradle`文件,将应用包名修改为您的实际应用包名。
73
+
74
+ ```gradle
75
+ applicationId 'com.****.callkit'
76
+ ```
77
+
78
+ ## 自定义来电推送
79
+
80
+ ### 步骤1:监听 FCM 推送
81
+
82
+ 当 FCM 推送唤醒应用时,TIMPush 插件会发送“应用唤醒”广播。收到该广播后,请按以下步骤处理以确保来电通知正常显示:
83
+
84
+ 1. **监听应用唤醒广播:**应用被唤醒,收到 TIMPush 发送的广播。
85
+
86
+ 2. **执行自动登录:**登录后通话服务状态可用,如何登录可参考 [login](https://liteav.sdk.cloudcachetci.com/doc/product/tuikit/atomic-x/android/zh/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.login/-login-store/login.html)。
87
+
88
+ ```kotlin
89
+ import android.content.BroadcastReceiver
90
+ import android.content.Context
91
+ import android.content.Intent
92
+ import android.content.IntentFilter
93
+ import android.os.Bundle
94
+ import androidx.localbroadcastmanager.content.LocalBroadcastManager
95
+
96
+ class PushWakeupReceiver : BroadcastReceiver() {
97
+ override fun onReceive(context: Context?, intent: Intent?) {
98
+ if (intent?.action == "TIMPush.BROADCAST_IM_LOGIN_AFTER_APP_WAKEUP") {
99
+ val bundle = intent.getExtras()
100
+ // 2.执行自动登录
101
+ // autoLogin()
102
+ }
103
+ }
104
+ }
105
+
106
+ class MainActivity : AppCompatActivity() {
107
+ private val wakeupReceiver = PushWakeupReceiver()
108
+ private var callListener: CallListener? = null
109
+
110
+ override fun onCreate(savedInstanceState: Bundle?) {
111
+ super.onCreate(savedInstanceState)
112
+ // 1.监听应用唤醒广播
113
+ observeAppWakeup()
114
+ }
115
+
116
+ private fun observeAppWakeup() {
117
+ val filter = IntentFilter("TIMPush.BROADCAST_IM_LOGIN_AFTER_APP_WAKEUP")
118
+ LocalBroadcastManager.getInstance(this).registerReceiver(wakeupReceiver, filter)
119
+ }
120
+ }
121
+ ```
122
+
123
+ ### 步骤2:自定义来电通知样式
124
+
125
+ 您可以使用 `NotificationManager` 通知管理类显示您定制的来电通知界面,实现方式如下:
126
+
127
+ 1. **创建一个来电通知管理类**(`IncomingCallNotificationManager`):封装推送的创建和显示等逻辑。
128
+
129
+ 2. **自定义来电通知的 UI 样式:**您可以使用 `RemoteViews` 定制通知布局。关于如何使用 `NotificationCompat.Builder` 配置通知的详细参数(如 Channel、PendingIntent、优先级等),请参阅 Android 官方文档: [NotificationCompat.Builder](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder)。
130
+
131
+ ```kotlin
132
+ import android.app.Notification
133
+ import android.app.NotificationChannel
134
+ import android.app.NotificationManager
135
+ import android.content.Context
136
+ import android.content.Intent
137
+ import android.os.Build
138
+ import android.widget.RemoteViews
139
+ import androidx.core.app.NotificationCompat
140
+
141
+ class IncomingCallNotificationManager(private val context: Context) {
142
+ private val channelId = "incoming_call_channel"
143
+ private val channelName = "来电通知"
144
+ private val notificationId = 1001
145
+ private var remoteViews: RemoteViews? = null
146
+ private val notificationManager: NotificationManager =
147
+ context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
148
+
149
+ init {
150
+ // 1.创建通知渠道
151
+ createNotificationChannel()
152
+ }
153
+
154
+ private fun createNotificationChannel() {
155
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
156
+ val channel = NotificationChannel(
157
+ channelId, // 渠道 ID(唯一标识)
158
+ "来电通知", // 渠道名称(用户可见)
159
+ NotificationManager.IMPORTANCE_HIGH // 重要性:高优先级
160
+ ).apply {
161
+ description = "显示来电通知" // 渠道描述(用户可见)
162
+ enableLights(true) // 启用通知灯
163
+ enableVibration(true) // 启用震动
164
+ setShowBadge(false) // 不显示角标
165
+ }
166
+ notificationManager.createNotificationChannel(channel)
167
+ }
168
+ }
169
+
170
+ // 2. 显示自定义来电通知的 UI 样式
171
+ fun showIncomingCallNotification(
172
+ callerName: String,
173
+ callerAvatar: Int?, // Bitmap 或 Int (资源 ID)
174
+ isVideoCall: Boolean
175
+ ) {
176
+ // RemoteViews 用于在通知中显示自定义的布局
177
+ remoteViews = RemoteViews(context.packageName, R.layout.incoming_call_notification)
178
+
179
+ // 设置来电者姓名
180
+ remoteViews?.setTextViewText(R.id.tv_caller_name, callerName)
181
+
182
+ // 设置通话类型描述(视频通话 或 语音通话)
183
+ remoteViews?.setTextViewText(R.id.tv_call_desc, if (isVideoCall) "视频通话" else "语音通话")
184
+
185
+ // 设置通话类型图标
186
+ val callTypeIcon = if (isVideoCall) {R.drawable.ic_video_call} else {R.drawable.ic_audio_call}
187
+ remoteViews?.setImageViewResource(R.id.img_call_type, callTypeIcon)
188
+
189
+ // 设置呼叫用户头像
190
+ remoteViews?.setImageViewResource(R.id.img_avatar, callerAvatar)
191
+
192
+ // 创建通知对象
193
+ val notification = NotificationCompat.Builder(context, channelId)
194
+ .setSmallIcon(R.drawable.ic_notification_small) // 状态栏显示的小图标
195
+ .setContent(remoteViews) // 设置自定义布局
196
+ .setCustomContentView(remoteViews) // 标准视图(通知栏收起时)
197
+ .setCustomBigContentView(remoteViews) // 展开视图(通知栏展开时)
198
+ .setOngoing(true) // 持续通知(用户无法滑动删除)
199
+ .setAutoCancel(true) // 点击后自动取消
200
+ .setCategory(NotificationCompat.CATEGORY_CALL) // 分类为通话通知
201
+ .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) // 锁屏时可见
202
+ .setTimeoutAfter(60000) // 60秒后自动取消
203
+ .build()
204
+
205
+ notificationManager.notify(notificationId, notification)
206
+ }
207
+ }
208
+ ```
209
+
210
+ 上述来电通知样式的布局文件如下( `R.layout.incoming_call_notification` ):
211
+
212
+ ```xml
213
+ <?xml version="1.0" encoding="utf-8"?>
214
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
215
+ android:layout_width="match_parent"
216
+ android:layout_height="wrap_content"
217
+ android:orientation="horizontal"
218
+ android:padding="16dp"
219
+ android:background="#FFFFFF"
220
+ android:gravity="center_vertical">
221
+
222
+ <!-- 用户头像 -->
223
+ <ImageView
224
+ android:id="@+id/img_avatar"
225
+ android:layout_width="56dp"
226
+ android:layout_height="56dp"
227
+ android:layout_gravity="center_vertical"
228
+ android:scaleType="centerCrop"
229
+ android:src="@drawable/callview_ic_avatar"
230
+ android:background="@drawable/avatar_background" />
231
+
232
+ <!-- 用户信息和描述 -->
233
+ <LinearLayout
234
+ android:layout_width="0dp"
235
+ android:layout_height="wrap_content"
236
+ android:layout_weight="1"
237
+ android:layout_gravity="center_vertical"
238
+ android:layout_marginStart="16dp"
239
+ android:orientation="vertical">
240
+
241
+ <TextView
242
+ android:id="@+id/tv_caller_name"
243
+ android:layout_width="wrap_content"
244
+ android:layout_height="wrap_content"
245
+ android:textSize="18sp"
246
+ android:textStyle="bold"
247
+ android:textColor="#212121"
248
+ android:maxLines="1"
249
+ android:ellipsize="end"
250
+ android:text="来电" />
251
+
252
+ <LinearLayout
253
+ android:layout_width="wrap_content"
254
+ android:layout_height="wrap_content"
255
+ android:layout_marginTop="6dp"
256
+ android:orientation="horizontal"
257
+ android:gravity="center_vertical">
258
+
259
+ <ImageView
260
+ android:id="@+id/img_call_type"
261
+ android:layout_width="16dp"
262
+ android:layout_height="16dp"
263
+ android:src="@drawable/ic_audio_call" />
264
+
265
+ <TextView
266
+ android:id="@+id/tv_call_desc"
267
+ android:layout_width="wrap_content"
268
+ android:layout_height="wrap_content"
269
+ android:layout_marginStart="6dp"
270
+ android:textSize="14sp"
271
+ android:textColor="#757575"
272
+ android:text="语音通话" />
273
+ </LinearLayout>
274
+ </LinearLayout>
275
+ </LinearLayout>
276
+ ```
277
+
278
+ ### 步骤3:展示来电通知
279
+
280
+ 您需要监听来电事件,登录成功后(步骤1),如果有离线来电事件,**CallStore** 会自动补发,您可以在该事件中显示定制的推送通知(步骤2),实现方式如下:
281
+
282
+ 1. **监听来电事件:**订阅 [onCallReceived](https://liteav.sdk.cloudcachetci.com/doc/product/tuikit/atomic-x/android/zh/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.call/-call-listener/on-call-received.html) 事件。该事件在收到来电时触发,并包含通话所需的关键信息。
283
+
284
+ 2. **展示来电通知:**当收到 [onCallReceived](https://liteav.sdk.cloudcachetci.com/doc/product/tuikit/atomic-x/android/zh/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.call/-call-listener/on-call-received.html) 事件后,根据该事件携带的通话信息展示通知界面。在 [onCallReceived](https://liteav.sdk.cloudcachetci.com/doc/product/tuikit/atomic-x/android/zh/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.call/-call-listener/on-call-received.html) 回调中,根据事件携带的通话信息,并调用自定义的推送通知(参考步骤 2)进行展示。
285
+
286
+ ```kotlin
287
+ class MainActivity : AppCompatActivity() {
288
+ private val wakeupReceiver = PushWakeupReceiver()
289
+ private var callListener: CallListener? = null
290
+
291
+ override fun onCreate(savedInstanceState: Bundle?) {
292
+ super.onCreate(savedInstanceState)
293
+ // 1.监听来电事件
294
+ observeCallReceived()
295
+ }
296
+
297
+ private fun observeCallReceived() {
298
+ callListener = object : CallListener() {
299
+ override fun onCallReceived(callId: String, mediaType: CallMediaType, userData: String) {
300
+ super.onCallReceived(callId, mediaType, userData)
301
+ // 2.显示来电通知
302
+ showIncomingCallNotification(mediaType)
303
+ }
304
+ }
305
+ callListener?.let { CallStore.shared.addListener(it) }
306
+ }
307
+
308
+ private fun showIncomingCallNotification(mediaType: CallMediaType) {
309
+ try {
310
+ val callerName = CallStore.shared.observerState.activeCall.value.inviterId
311
+ val notificationManager = IncomingCallNotificationManager(this)
312
+ notificationManager.showIncomingCallNotification(
313
+ callerName = callerName,
314
+ callerAvatar = R.drawable.callview_ic_avatar,
315
+ isVideoCall = mediaType == CallMediaType.Video
316
+ )
317
+ } catch (e: Exception) {
318
+ }
319
+ }
320
+ }
321
+ ```
322
+
323
+ **onCallReceived 事件详细说明:**当收到来电事件时触发。
324
+
325
+ | 参数 | 类型 | 说明 |
326
+ |------|------|------|
327
+ | callId | String | 此次通话的唯一标识。 |
328
+ | mediaType | [CallMediaType](https://liteav.sdk.cloudcachetci.com/doc/product/tuikit/atomic-x/android/zh/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.call/-call-media-type/index.html) | 通话媒体类型,用于指定发起音频通话还是视频通话。CallMediaType.Video :视频通话。CallMediaType.Audio :语音通话。 |
329
+
330
+ **activeCall 结构体详细说明:**活跃通话响应式数据,包含通话 ID、主叫 ID 、被叫 ID 列表、通话媒体类型、通话计时等关键信息。
331
+
332
+ | 字段 | 类型 | 说明 |
333
+ |------|------|------|
334
+ | callId | String | 此次通话的唯一标识。 |
335
+ | roomId | String | 此次通话的房间 ID 。 |
336
+ | inviterId | String | 发起通话用户的 ID 。 |
337
+ | inviteeIds | LinkedHashSet<String> | 被叫用户的 ID 列表。 |
338
+ | chatGroupId | String | 此次通话的群组 ID ,与 Chat 配合使用。 |
339
+ | mediaType | CallMediaType | 此次通话的媒体类型。CallMediaType.Video:视频通话。CallMediaType.Audio:语音通话。 |
340
+ | result | CallDirection | 通话结果/方向。CallDirection.Unknown:未知通话。CallDirection.Missed:未接通话。CallDirection.Incoming:来电通话。CallDirection.Outgoing:拨出通话。 |
341
+ | duration | Long | 通话时长。 |
342
+ | startTime | Long | 通话接通的开始时间。 |
343
+
344
+ ### 运行效果
345
+
346
+ 完成以上 3 步以后,来电通知效果如下:
347
+
348
+ ## 常见问题
349
+
350
+ 若在集成过程中遇到问题,请务必先查阅 插件推送 > 常见问题 进行自助排查。
351
+
352
+ ### 应用被杀死后无法弹出来电界面
353
+
354
+ 确认收到了推送,收不到推送需要确认下 IM 控制台是否正确上传证书。参见文档上述**快速接入**的第一步,看下是否添加正确。
355
+
356
+ 确认控制台选择了 FCM 数据消息,对照上述准备条件的第二步。
357
+
358
+ 确认收到数据消息,过滤日志(关键字:TIMPush),检查下述日志是否有打印记录(如果收不到消息,可以使用 IM 控制台的 排查工具 查看原因)。
359
+
360
+ 确认实现了**自动登录**。自动登录后才会去拉取通话请求,才能显示来电界面。
361
+
362
+ ### 怎样强制使用 FCM 通道?
363
+
364
+ 若您的业务想要强制使用 FCM 通道,可调用以下接口:
365
+
366
+ ```java
367
+ TIMPushManager.getInstance().forceUseFCMPushChannel(true);
368
+ ```