Aller directement au contenu

Démarrage

  1. Installer le package

    Fenêtre de terminal
    bun add @capgo/capacitor-incoming-call-kit
  2. Synchroniser les projets natifs

    Fenêtre de terminal
    bunx cap sync
  3. Choisissez votre source de sonnerie Décidez si l'événement appel entrant provient de votre backend, un SDK tel que Twilio ou Stream, ou un chemin de notification native tel que FCM ou PushKit.

Ce plugin n'assume que la présentation native de l'appel entrant. Votre application conserve toujours la gestion du transport, de l'authentification et de la session de médias réelle.

Le modèle de production courant est :

  1. Votre backend ou votre SDK d'appel émet un événement de sonnerie.
  2. Votre application appelle showIncomingCall().
  3. Le plugin présente une interface utilisateur native d'appel entrant.
  4. callAccepted Vous informez votre application de rejoindre la session de communication réelle ou VoIP.
  5. callDeclined, callEndedou callTimedOut indique à votre application de nettoyer l'état distant.
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: identifiant stable réutilisé ultérieurement avec endCall()
  • timeoutMs: temps d'attente non garanti sans réponse
  • extra: JSON arbitraire renvoyé dans les payloads des écouteurs
  • android.channelId et android.channelName: réglage du canal de notification Android
  • android.showFullScreen: demande l'activité d'appel entrant à écran plein sur Android
  • ios.handleType: choisir generic, phoneNumber, ou emailAddress pour CallKit
const { calls } = await IncomingCallKit.getActiveCalls();
await IncomingCallKit.endCall({
callId: 'call-42',
reason: 'remote-ended',
});
await IncomingCallKit.endAllCalls({
reason: 'session-reset',
});
  • incomingCallDisplayed: l'interface utilisateur native a été affichée avec succès
  • callAccepted: l'utilisateur a accepté depuis l'interface utilisateur native
  • callDeclined: l'utilisateur a refusé avant de rejoindre
  • callEnded: votre application ou la plateforme a terminé l'appel suivi
  • callTimedOut: le appel est resté sans réponse jusqu'à timeoutMs

Chaque événement transporte l'objet normalisé call et votre objet original. extra Remarques sur les plateformes

Section intitulée “Remarques sur les plateformes”

Lisez le