|
| 1 | +--- |
| 2 | +title: Getting Started |
| 3 | +description: Install and wire incoming call presentation in Capacitor with a transport-agnostic API. |
| 4 | +sidebar: |
| 5 | + order: 2 |
| 6 | +--- |
| 7 | + |
| 8 | +import { PackageManagers } from 'starlight-package-managers' |
| 9 | +import { Steps } from '@astrojs/starlight/components'; |
| 10 | + |
| 11 | +<Steps> |
| 12 | +1. **Install the package** |
| 13 | + <PackageManagers pkg="@capgo/capacitor-incoming-call-kit" pkgManagers={['npm', 'pnpm', 'yarn', 'bun']} /> |
| 14 | + |
| 15 | +2. **Sync native projects** |
| 16 | + <PackageManagers type="exec" pkg="cap" args="sync" pkgManagers={['npm', 'pnpm', 'yarn', 'bun']} /> |
| 17 | + |
| 18 | +3. **Choose your ring source** |
| 19 | + Decide whether the incoming-call event comes from your backend, an SDK such as Twilio or Stream, or a native push path such as FCM or PushKit. |
| 20 | +</Steps> |
| 21 | + |
| 22 | +## How the integration fits together |
| 23 | + |
| 24 | +This plugin only owns native incoming-call presentation. Your app still owns transport, authentication, and the actual media session. |
| 25 | + |
| 26 | +The common production pattern is: |
| 27 | + |
| 28 | +1. Your backend or calling SDK emits a ring event. |
| 29 | +2. Your app calls `showIncomingCall()`. |
| 30 | +3. The plugin presents native incoming-call UI. |
| 31 | +4. `callAccepted` tells your app to join the actual room or VoIP session. |
| 32 | +5. `callDeclined`, `callEnded`, or `callTimedOut` tells your app to clean up remote state. |
| 33 | + |
| 34 | +## Minimal integration |
| 35 | + |
| 36 | +```ts |
| 37 | +import { IncomingCallKit } from '@capgo/capacitor-incoming-call-kit'; |
| 38 | + |
| 39 | +await IncomingCallKit.requestPermissions(); |
| 40 | +await IncomingCallKit.requestFullScreenIntentPermission(); |
| 41 | + |
| 42 | +await IncomingCallKit.addListener('callAccepted', async ({ call }) => { |
| 43 | + console.log('Accepted', call.callId, call.extra); |
| 44 | + // Start or join your real call session here. |
| 45 | +}); |
| 46 | + |
| 47 | +await IncomingCallKit.addListener('callDeclined', ({ call }) => { |
| 48 | + console.log('Declined', call.callId); |
| 49 | + // Tell your backend or SDK that the user declined. |
| 50 | +}); |
| 51 | + |
| 52 | +await IncomingCallKit.addListener('callTimedOut', ({ call }) => { |
| 53 | + console.log('Timed out', call.callId); |
| 54 | + // Clear ringing state in your backend or SDK. |
| 55 | +}); |
| 56 | + |
| 57 | +await IncomingCallKit.showIncomingCall({ |
| 58 | + callId: 'call-42', |
| 59 | + callerName: 'Ada Lovelace', |
| 60 | + handle: '+39 555 010 020', |
| 61 | + appName: 'Capgo Phone', |
| 62 | + hasVideo: true, |
| 63 | + timeoutMs: 45_000, |
| 64 | + extra: { |
| 65 | + roomId: 'room-42', |
| 66 | + callerUserId: 'user_ada', |
| 67 | + }, |
| 68 | + android: { |
| 69 | + channelId: 'calls', |
| 70 | + channelName: 'Incoming Calls', |
| 71 | + showFullScreen: true, |
| 72 | + }, |
| 73 | + ios: { |
| 74 | + handleType: 'phoneNumber', |
| 75 | + }, |
| 76 | +}); |
| 77 | +``` |
| 78 | + |
| 79 | +## Important options |
| 80 | + |
| 81 | +- `callId`: stable identifier reused later with `endCall()` |
| 82 | +- `timeoutMs`: best-effort unanswered timeout |
| 83 | +- `extra`: arbitrary JSON echoed back in listener payloads |
| 84 | +- `android.channelId` and `android.channelName`: Android notification channel tuning |
| 85 | +- `android.showFullScreen`: requests the Android full-screen incoming-call activity |
| 86 | +- `ios.handleType`: choose `generic`, `phoneNumber`, or `emailAddress` for CallKit |
| 87 | + |
| 88 | +## Managing active calls |
| 89 | + |
| 90 | +```ts |
| 91 | +const { calls } = await IncomingCallKit.getActiveCalls(); |
| 92 | + |
| 93 | +await IncomingCallKit.endCall({ |
| 94 | + callId: 'call-42', |
| 95 | + reason: 'remote-ended', |
| 96 | +}); |
| 97 | + |
| 98 | +await IncomingCallKit.endAllCalls({ |
| 99 | + reason: 'session-reset', |
| 100 | +}); |
| 101 | +``` |
| 102 | + |
| 103 | +## Event model |
| 104 | + |
| 105 | +- `incomingCallDisplayed`: native UI was shown successfully |
| 106 | +- `callAccepted`: user accepted from the native UI |
| 107 | +- `callDeclined`: user declined before joining |
| 108 | +- `callEnded`: your app or the platform ended the tracked call |
| 109 | +- `callTimedOut`: the call stayed unanswered until `timeoutMs` |
| 110 | + |
| 111 | +Each event carries the normalized `call` payload and your original `extra` object. |
| 112 | + |
| 113 | +## Platform notes |
| 114 | + |
| 115 | +- Read the [iOS guide](/docs/plugins/incoming-call-kit/ios/) before wiring CallKit into a PushKit or APNs flow. |
| 116 | +- Read the [Android guide](/docs/plugins/incoming-call-kit/android/) before relying on full-screen intents on Android 14 and later. |
| 117 | +- Web is not supported. |
0 commit comments