{"library":"react-native-callkeep","title":"React Native CallKeep","description":"React Native CallKeep is a library designed to integrate native iOS CallKit and Android ConnectionService frameworks into React Native applications, facilitating the development of VoIP calling features. It provides a unified JavaScript API for managing the incoming and outgoing call UI, handling call actions like answer and end, and ensuring compliance with platform-specific requirements for background calling and permissions. The current stable version is 4.3.16. While the project shows frequent historical updates, recent analysis from sources like Snyk suggests an 'Inactive' maintenance status with no new npm releases in the past 12 months, and low attention from maintainers. Key differentiators include its comprehensive handling of Android 11's foreground service requirements for background audio and the flexibility of early iOS setup via `AppDelegate.m` for capturing pre-JS bridge events.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install react-native-callkeep"],"cli":null},"imports":["import RNCallKeep from 'react-native-callkeep';","import { PermissionsAndroid } from 'react-native';","import { v4 as uuidv4 } from 'uuid'; // or other UUID library\nconst callUUID = uuidv4();"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import RNCallKeep from 'react-native-callkeep';\nimport { PermissionsAndroid, Platform } from 'react-native';\nimport 'react-native-get-random-values'; // Polyfill for crypto for UUID generation\nimport { v4 as uuidv4 } from 'uuid'; // Recommended UUID library\n\nconst setupCallKeep = async () => {\n  const options = {\n    ios: {\n      appName: 'My VoIP App',\n      imageName: 'callkeep_icon', // Optional: image for system UI\n      maximumCallGroups: 1,\n      maximumCallsPerCallGroup: 1,\n      supportsVideo: false,\n      includesCallsInRecents: true, // Show calls in iOS Recents list\n    },\n    android: {\n      alertTitle: 'Permissions required',\n      alertDescription: 'This application needs to access your phone accounts to manage calls and show caller ID.',\n      cancelButton: 'Cancel',\n      okButton: 'Ok',\n      imageName: 'phone_account_icon', // Make sure this icon exists in your drawable folder\n      additionalPermissions: [\n        PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE,\n        PermissionsAndroid.PERMISSIONS.CALL_PHONE,\n        ...(Platform.Version >= 31 ? [PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT] : []), // For Android 12+ Bluetooth\n      ],\n      foregroundService: {\n        channelId: 'com.mycompany.myapp.callservice',\n        channelName: 'VoIP Call Service',\n        notificationTitle: 'My VoIP App is running in the background for calls',\n        notificationIcon: 'ic_launcher_round', // Ensure this icon exists in your Android resources\n      },\n      selfManaged: false, // Set to true for custom incoming call UI on Android\n      // Additional Android 13+ foreground service permissions\n      // 'android.permission.FOREGROUND_SERVICE_PHONE_CALL',\n    },\n  };\n\n  try {\n    // Request necessary Android permissions before setup\n    if (Platform.OS === 'android') {\n      const granted = await PermissionsAndroid.requestMultiple(options.android.additionalPermissions);\n      const allGranted = Object.values(granted).every(status => status === PermissionsAndroid.RESULTS.GRANTED);\n      if (!allGranted) {\n        console.warn('CallKeep permissions not fully granted.');\n        // You might want to show an alert or prevent app functionality here\n        return;\n      }\n    }\n\n    const accepted = await RNCallKeep.setup(options);\n    if (accepted) {\n      console.log('RNCallKeep setup successfully.');\n      // Example: Register an event listener for answering calls\n      RNCallKeep.addEventListener('answerCall', ({ callUUID }) => {\n        console.log(`Call ${callUUID} answered.`);\n        // Implement your logic to connect the call\n      });\n      // Other event listeners like 'endCall', 'setMutedCall', etc.\n    } else {\n      console.warn('RNCallKeep setup was not accepted by the user or failed.');\n    }\n  } catch (err: any) {\n    console.error('Error setting up RNCallKeep:', err.message);\n  }\n};\n\n// Call the setup function when your app initializes, e.g., in your App.js root component's useEffect\n// useEffect(() => { setupCallKeep(); }, []);\n\n// Example of displaying an incoming call (after setup)\nconst displayExampleIncomingCall = (callerName: string) => {\n  const currentCallUUID = uuidv4();\n  RNCallKeep.displayIncomingCall(\n    currentCallUUID,\n    'remote-caller-id-123',\n    callerName,\n    'Generic',\n    true, // hasVideo\n  );\n  console.log(`Displayed incoming call from ${callerName} with UUID: ${currentCallUUID}`);\n  return currentCallUUID;\n};\n\n// To simulate an incoming call (for testing, after setup is complete):\n// const activeCallId = displayExampleIncomingCall('Jane Doe');\n// To end the call (e.g., after 30 seconds):\n// setTimeout(() => { RNCallKeep.endCall(activeCallId); }, 30000);\n","lang":"typescript","description":"This quickstart initializes React Native CallKeep, configures it for both iOS CallKit and Android ConnectionService with proper permissions and foreground service setup, and demonstrates how to display an incoming call. It includes UUID generation as a best practice.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}