跳过内容

Getting Started

GitHub

您可以使用我们的AI辅助设置来安装插件。将Capgo技能添加到您的AI工具中,使用以下命令:

终端窗口
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

然后使用以下提示:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-incoming-call-kit` plugin in my project.

如果您更喜欢手动设置,请运行以下命令安装插件,并按照以下平台特定的说明进行操作:

  1. 安装包

    终端窗口
    bun add @capgo/capacitor-incoming-call-kit
  2. 同步本机项目

    终端窗口
    bunx cap sync
  3. 选择您的环源 决定是否来自后端的呼叫事件、一个像Twilio或Stream这样的SDK,还是一个本机推送路径,如FCM或PushKit。

本插件仅负责原生来电展示。您的应用程序仍然负责传输、身份验证和实际媒体会话。

常见的生产模式是:

  1. 您的后端或呼叫SDK发出振铃事件。
  2. 您的应用程序调用 showIncomingCall().
  3. 该插件展示原生来电UI。
  4. callAccepted 告诉您的应用程序加入实际房间或VoIP会话。
  5. callDeclined, callEndedcallTimedOut 告诉您的应用程序清理远程状态。
import { IncomingCallKit } from '@capgo/capacitor-incoming-call-kit';
await IncomingCallKit.requestPermissions();
await IncomingCallKit.requestFullScreenIntentPermission();
await IncomingCallKit.addListener('callAccepted', async ({ call }) => {
console.log('Accepted', call.callId, call.extra);
// Start or join your real call session here.
});
await IncomingCallKit.addListener('callDeclined', ({ call }) => {
console.log('Declined', call.callId);
// Tell your backend or SDK that the user declined.
});
await IncomingCallKit.addListener('callTimedOut', ({ call }) => {
console.log('Timed out', call.callId);
// Clear ringing state in your backend or SDK.
});
await IncomingCallKit.showIncomingCall({
callId: 'call-42',
callerName: 'Ada Lovelace',
handle: '+39 555 010 020',
appName: 'Capgo Phone',
hasVideo: true,
timeoutMs: 45_000,
extra: {
roomId: 'room-42',
callerUserId: 'user_ada',
},
android: {
channelId: 'calls',
channelName: 'Incoming Calls',
showFullScreen: true,
},
ios: {
handleType: 'phoneNumber',
},
});

重要选项

重要选项
  • callId: 稳定标识符在后面会被重复使用 endCall()
  • timeoutMs: 最佳努力超时
  • extra: 回传给监听器的任意 JSON
  • android.channelIdandroid.channelName: Android 通知频道调节
  • android.showFullScreen: 请求 Android 全屏 incoming-call 活动
  • ios.handleType: 选择 generic, phoneNumber, or emailAddress for CallKit
const { calls } = await IncomingCallKit.getActiveCalls();
await IncomingCallKit.endCall({
callId: 'call-42',
reason: 'remote-ended',
});
await IncomingCallKit.endAllCalls({
reason: 'session-reset',
});
  • incomingCallDisplayed: 本地 UI 已成功显示
  • callAccepted: 用户从本地 UI 中接受
  • callDeclined: 用户在加入之前拒绝
  • callEnded: 您的应用或平台结束了跟踪的电话
  • callTimedOut: 电话一直未接 timeoutMs

每个事件都携带标准化的 call 负载和您的原始 extra 对象。

平台备注

Platform notes
  • Read the iOS指南 在将CallKit集成到PushKit或APNs流程之前,先阅读iOS指南。
  • Read the Android指南 在Android 14及后续版本中依赖全屏意图之前,先阅读Android指南。
  • 不支持Web

如果您正在使用 从Getting Started开始 为计划仪表板和API操作,连接它 使用@capgo/capacitor-incoming-call-kit 使用@capgo/capacitor-incoming-call-kit中的本地能力 API概述 查看API概述的实现细节 介绍 查看介绍的实现细节 API密钥 查看API密钥的实现细节 设备 查看设备的实现细节