### Install Dependencies Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/example/README.md Installs project dependencies using Yarn and installs iOS pods. ```bash # Install dependancies yarn install cd ios pod install ``` -------------------------------- ### Example Setup Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/example/README.md Demonstrates the steps to set up a new Expo project, eject it, add react-native-callkeep, and link the library. ```bash expo init CallKeepDemo expo eject yarn add react-native-callkeep ./node_modules/.bin/react-native link react-native-callkeep ``` -------------------------------- ### Manual Installation: Link Binary Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/ios-installation.md Steps to link the libRNCallKeep.a library in your Xcode project's build phases. ```sh Add libRNCallKeep.a. ``` -------------------------------- ### Start Application Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/example/README.md Starts the Metro bundler and then runs the application on Android or iOS. ```bash # Start metro bundler yarn start # Start the application (in another term) yarn android # or yarn ios ``` -------------------------------- ### Manual Installation: Add Library to Project Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/ios-installation.md Steps to manually add the RNCallKeep.xcodeproj file to your Xcode project. ```sh Choose node_modules/react-native-callkeep/ios/RNCallKeep.xcodeproj then click Add. ``` -------------------------------- ### CocoaPods Installation Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/ios-installation.md Instructions for installing react-native-callkeep using CocoaPods by adding the library to your Podfile. ```ruby pod 'RNCallKeep', :path => '../node_modules/react-native-callkeep' ``` ```sh cd ios pod install ``` -------------------------------- ### Common Steps: Update AppDelegate.m - Handle User Activity Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/ios-installation.md Implementing the `application:continueUserActivity:restorationHandler:` method in AppDelegate.m to handle user activities for calls. ```diff + - (BOOL)application:(UIApplication *)application + continueUserActivity:(NSUserActivity *)userActivity + restorationHandler:(void(^)(NSArray> * __nullable restorableObjects)) + { + return [RNCallKeep application:application + continueUserActivity:userActivity + restorationHandler:restorationHandler]; + } ``` -------------------------------- ### Common Steps: Link Required Libraries Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/ios-installation.md Linking CallKit.framework and Intents.framework in Xcode's 'Link Binary With Libraries' build phase. ```sh Add CallKit.framework and Intents.framework (and mark it Optional). ``` -------------------------------- ### Common Steps: Update AppDelegate.m - Import Library Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/ios-installation.md Importing the RNCallKeep header file into the AppDelegate.m. ```diff + #import "RNCallKeep.h" ``` -------------------------------- ### Automatic Linking Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/ios-installation.md This command links the react-native-callkeep library automatically to your project. ```sh react-native link react-native-callkeep ``` -------------------------------- ### Common Steps: Add Header Search Path Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/ios-installation.md Configuring the Header Search Paths in Xcode to include the react-native-callkeep header files. ```sh Add $(SRCROOT)/../node_modules/react-native-callkeep/ios/RNCallKeep. ``` -------------------------------- ### Common Steps: Allow VoIP Background Mode Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/ios-installation.md Configuring the Info.plist file to allow VoIP background modes for the application. ```xml UIBackgroundModes voip ``` -------------------------------- ### Installation Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Installs the react-native-callkeep library using npm or yarn. ```sh npm install --save react-native-callkeep # or yarn add react-native-callkeep ``` -------------------------------- ### Manual Installation - MainActivity.java Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/android-installation.md Handles permission results for the callkeep module in MainActivity. ```java import io.wazo.callkeep.RNCallKeepModule; // Add these import lines import android.support.annotation.NonNull; import android.support.annotation.Nullable; public class MainActivity extends ReactActivity { // ... // Permission results @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case RNCallKeepModule.REQUEST_READ_PHONE_STATE: RNCallKeepModule.onRequestPermissionsResult(requestCode, permissions, grantResults); break; } } } ``` -------------------------------- ### Manual Installation - MainApplication.java Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/android-installation.md Registers the RNCallKeepPackage within the React Native application. ```java import io.wazo.callkeep.RNCallKeepPackage; // Add this import line //... private static List getPackages() { return Arrays.asList( new MainReactPackage(), new RNCallKeepPackage() // Add this line ); } ``` -------------------------------- ### Manual Installation - Settings Gradle Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/android-installation.md Includes the react-native-callkeep module in the Android project settings. ```java include ':react-native-callkeep' project(':react-native-callkeep').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-callkeep/android') ``` -------------------------------- ### react-native-callkeep Setup Options Reference Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Detailed reference for the configuration options available for RNCallKeep.setup(), covering both iOS and Android specific settings, including parameters for app name, permissions, call handling, and audio session. ```APIDOC RNCallKeep.setup(options) Parameters: options: Object - Configuration object for the CallKeep module. ios: Object (optional) - iOS specific configuration. appName: string (required) - Displayed on system UI for incoming calls. imageName: string (optional) - Image displayed on system UI during the call. ringtoneSound: string (optional) - Custom ringtone for incoming calls. handleType: string|array (optional) - Specifies handle types the app can manage ('generic', 'number', 'email'). Defaults to 'number'. includesCallsInRecents: boolean (optional) - Whether to show calls in recents (iOS 11+). Defaults to true. maximumCallGroups: string (optional) - Maximum number of call groups. Defaults to 3. maximumCallsPerCallGroup: string (optional) - Maximum calls per group for conferencing. Defaults to 1. supportsVideo: boolean (optional) - Whether the app supports video calling. Defaults to true. displayCallReachabilityTimeout: number in ms (optional) - Timeout to check app reachability. Requires calling setReachable(). Defaults to null. audioSession: Object (optional) - Overrides default AVAudioSession settings. categoryOptions: AudioSessionCategoryOption|number (optional) - AVAudioSession category options. mode: AudioSessionMode|string (optional) - AVAudioSession mode. android: Object (required) - Android specific configuration. alertTitle: string (required) - Title for the phone account permission alert. alertDescription: string (required) - Description for the phone account permission alert. cancelButton: string (required) - Label for the cancel button in the alert. okButton: string (required) - Label for the ok button in the alert. imageName: string (optional) - Name of the grayscale PNG image (48x48 HDPI) in drawable resources for the Android Phone app UI. additionalPermissions: [PermissionsAndroid] (optional) - Array of additional permissions to request. selfManaged: boolean (optional) - If true, configures CallKeep as a self-managed connection service. Refer to Google's documentation for details. ``` -------------------------------- ### Manual Installation - App Build Gradle Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/android-installation.md Adds the react-native-callkeep library as a project dependency in the app's build.gradle file. ```java compile project(':react-native-callkeep') ``` -------------------------------- ### Objective-C AppDelegate Setup for react-native-callkeep Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md An alternative method to set up react-native-callkeep directly in the AppDelegate.m file on iOS. This allows capturing events before the React Native bridge is fully initialized and overrides any subsequent JavaScript calls to setup. ```objective-c @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; [RNCallKeep setup:@{ @"appName": @"Awesome App", @"maximumCallGroups": @3, @"maximumCallsPerCallGroup": @1, @"supportsVideo": @NO, }]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.bridge moduleName:@"App" initialProperties:nil]; // ======== OTHER CODE REDACTED ========== return YES; } @end ``` -------------------------------- ### Register Android Events Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Registers Android-specific UI events. This method is called by `setup()` and is useful if you choose not to use `setup()` directly. On iOS, `setup()` must still be called. ```javascript RNCallKeep.registerAndroidEvents(); ``` -------------------------------- ### Automatic Linking Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/android-installation.md Automatically links the react-native-callkeep library to your Android project. ```sh react-native link react-native-callkeep ``` -------------------------------- ### AndroidManifest.xml Permissions and Service Configuration Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/android-installation.md Configures necessary permissions and the ConnectionService for react-native-callkeep in the AndroidManifest.xml. ```xml // Use this to target android >= 14 // ... = 11 android:foregroundServiceType="camera|microphone" // For android < 11 android:foregroundServiceType="phoneCall" > // .... ``` -------------------------------- ### Register Phone Account (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Manually registers an Android phone account. This is typically used for custom permission flows and is called internally by `setup()`. On iOS, `setup()` must still be called. ```javascript RNCallKeep.registerPhoneAccount(options); ``` -------------------------------- ### JavaScript Setup for react-native-callkeep Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Initializes the react-native-callkeep library with configuration options for iOS and Android. This includes app name, permissions, and foreground service settings for Android. ```javascript import RNCallKeep from 'react-native-callkeep'; const options = { ios: { appName: 'My app name', }, android: { alertTitle: 'Permissions required', alertDescription: 'This application needs to access your phone accounts', cancelButton: 'Cancel', okButton: 'ok', imageName: 'phone_account_icon', additionalPermissions: [PermissionsAndroid.PERMISSIONS.example], // Required to get audio in background when using Android 11 foregroundService: { channelId: 'com.company.my', channelName: 'Foreground service for my app', notificationTitle: 'My app is running on background', notificationIcon: 'Path to the resource icon of the notification', }, } }; RNCallKeep.setup(options).then(accepted => {}); ``` -------------------------------- ### Example Usage of reportEndCallWithUUID Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Demonstrates how to use the `reportEndCallWithUUID` function with predefined constants for call end reasons. ```javascript const { CONSTANTS as CK_CONSTANTS, RNCallKeep } = require('react-native-callkeep'); // Example: Reporting a call as failed RNCallKeep.reportEndCallWithUUID(uuid, CK_CONSTANTS.END_CALL_REASONS.FAILED); ``` -------------------------------- ### React Native CallKeep Initialization and Event Handling Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Demonstrates how to initialize RNCallKeep with platform-specific options and set up event listeners for various call states. This includes handling incoming calls, starting calls, answering, ending, muting, holding, and DTMF actions. ```javascript import React from 'react'; import RNCallKeep from 'react-native-callkeep'; import uuid from 'uuid'; class RNCallKeepExample extends React.Component { constructor(props) { super(props); this.currentCallId = null; // Add RNCallKeep Events RNCallKeep.addEventListener('didReceiveStartCallAction', this.didReceiveStartCallAction); RNCallKeep.addEventListener('answerCall', this.onAnswerCallAction); RNCallKeep.addEventListener('endCall', this.onEndCallAction); RNCallKeep.addEventListener('didDisplayIncomingCall', this.onIncomingCallDisplayed); RNCallKeep.addEventListener('didPerformSetMutedCallAction', this.onToggleMute); RNCallKeep.addEventListener('didToggleHoldCallAction', this.onToggleHold); RNCallKeep.addEventListener('didPerformDTMFAction', this.onDTMFAction); RNCallKeep.addEventListener('didActivateAudioSession', this.audioSessionActivated); } // Initialise RNCallKeep setup = () => { const options = { ios: { appName: 'ReactNativeWazoDemo', imageName: 'sim_icon', supportsVideo: false, maximumCallGroups: '1', maximumCallsPerCallGroup: '1' }, android: { alertTitle: 'Permissions Required', alertDescription: 'This application needs to access your phone calling accounts to make calls', cancelButton: 'Cancel', okButton: 'ok', imageName: 'sim_icon', additionalPermissions: [PermissionsAndroid.PERMISSIONS.READ_CONTACTS] } }; try { RNCallKeep.setup(options); RNCallKeep.setAvailable(true); // Only used for Android, see doc above. } catch (err) { console.error('initializeCallKeep error:', err.message); } } // Use startCall to ask the system to start a call - Initiate an outgoing call from this point startCall = ({ handle, localizedCallerName }) => { // Your normal start call action RNCallKeep.startCall(this.getCurrentCallId(), handle, localizedCallerName); }; reportEndCallWithUUID = (callUUID, reason) => { RNCallKeep.reportEndCallWithUUID(callUUID, reason); } // Event Listener Callbacks didReceiveStartCallAction = (data) => { let { handle, callUUID, name } = data; // Get this event after the system decides you can start a call // You can now start a call from within your app }; onAnswerCallAction = (data) => { let { callUUID } = data; // Called when the user answers an incoming call }; onEndCallAction = (data) => { let { callUUID } = data; RNCallKeep.endCall(this.getCurrentCallId()); this.currentCallId = null; }; // Currently iOS only onIncomingCallDisplayed = (data) => { let { error } = data; // You will get this event after RNCallKeep finishes showing incoming call UI // You can check if there was an error while displaying }; onToggleMute = (data) => { let { muted, callUUID } = data; // Called when the system or user mutes a call }; onToggleHold = (data) => { let { hold, callUUID } = data; // Called when the system or user holds a call }; onDTMFAction = (data) => { let { digits, callUUID } = data; // Called when the system or user performs a DTMF action }; audioSessionActivated = (data) => { // you might want to do following things when receiving this event: // - Start playing ringback if it is an outgoing call }; getCurrentCallId = () => { if (!this.currentCallId) { this.currentCallId = uuid.v4(); } return this.currentCallId; }; render() { } } ``` -------------------------------- ### Get Initial Events Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Retrieves events that occurred before the JavaScript context was initialized. This is an alternative to the 'didLoadWithEvents' event. ```javascript RNCallKeep.getInitialEvents(); ``` -------------------------------- ### index.android.js Background Task Registration Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/android-installation.md Registers a headless task to handle background call events in React Native. ```js AppRegistry.registerHeadlessTask('RNCallKeepBackgroundMessage', () => ({ name, callUUID, handle }) => { // Make your call here return Promise.resolve(); }); ``` -------------------------------- ### Start Outgoing Call Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Notifies the device that an outgoing call is occurring. The parameters differ slightly between iOS and Android. ```APIDOC startCall(uuid, handle, contactIdentifier, handleType, hasVideo) uuid: string - A unique identifier for the call, to be reused with stopCall. handle: string - The phone number or identifier of the callee. contactIdentifier: string - The identifier displayed in the native call UI, typically the contact's name. handleType: string (optional, iOS only) - Type of handle ('generic', 'number', 'email'). Defaults to 'number'. hasVideo: boolean (optional, iOS only) - Indicates if the call has video. Defaults to false. iOS specific parameters: startCall(uuid, handle, contactIdentifier, handleType, hasVideo); Android specific parameters: startCall(uuid, handle, contactIdentifier); ``` -------------------------------- ### Android MainActivity.java Update Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/MIGRATION_v2_v3.md Updates required for the MainActivity.java file in Android to support CallKeep v3. This includes adding new imports and modifying the onRequestPermissionsResult method to correctly handle permission requests. ```java import android.support.annotation.NonNull; import android.support.annotation.Nullable; // Permission results @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case RNCallKeepModule.REQUEST_READ_PHONE_STATE: RNCallKeepModule.onRequestPermissionsResult(requestCode, permissions, grantResults); break; } } ``` -------------------------------- ### didReceiveStartCallAction Event Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Triggered when the app is allowed to start a call. Use this to initiate your app's call logic, such as fetching credentials or sending an INVITE to your SIP server. On iOS, you need to generate a `callUUID`. ```javascript RNCallKeep.addEventListener('didReceiveStartCallAction', ({ handle, callUUID, name }) => { }); ``` -------------------------------- ### AndroidManifest.xml Background Messaging Service Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/docs/android-installation.md Configures the background messaging service to handle outgoing calls from the native Phone application. ```xml ``` -------------------------------- ### didLoadWithEvents Listener (iOS) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Handles events that occurred before the JavaScript context was initialized on iOS. This is crucial for managing user actions on incoming calls when the app was in a killed state. It requires setup in `AppDelegate.m` and receives an array of events with their names and associated data. ```javascript RNCallKeep.addEventListener('didLoadWithEvents', (events) => { // `events` is passed as an Array chronologically, handle or ignore events based on the app's logic // see example usage in https://github.com/react-native-webrtc/react-native-callkeep/pull/169 or https://github.com/react-native-webrtc/react-native-callkeep/pull/205 }); // Event structure: // - `name`: string (e.g., 'RNCallKeepPerformAnswerCallAction') // - `data`: object (e.g., ({ callUUID }) for 'answerCall' event) ``` -------------------------------- ### Get Current Calls (iOS) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Returns a Promise that resolves to an array of all current calls and their states. This is an iOS-only feature. ```javascript RNCallKeep.getCalls(); ``` -------------------------------- ### didActivateAudioSession Event Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Fired when the `AudioSession` has been activated by RNCallKeep. This is a good place to start playing ringback tones for outgoing calls. ```javascript RNCallKeep.addEventListener('didActivateAudioSession', () => { // you might want to do following things when receiving this event: // - Start playing ringback if it is an outgoing call }); ``` -------------------------------- ### Android Specific Call Handling Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Provides API documentation for Android-specific features of the React Native CallKeep library, including managing connection states, audio routes, and checking for phone account availability. ```APIDOC setConnectionState(uuid, state) Changes the state of the call on Android. Parameters: uuid: string - The UUID of the current call. state: int - The new connection state (refer to Android's Connection.STATE_* documentation). toggleAudioRouteSpeaker(uuid, routeSpeaker) Updates the audio route to the speaker on Android. Parameters: uuid: string - The UUID of the current call. routeSpeaker: boolean - True to enable speaker, false otherwise. getAudioRoutes() Retrieves a list of available audio routes. Returns: Promise> AudioRoute: { name: string, type: string } setAudioRoute(uuid, routeName) Sets the audio route for a call on Android. Parameters: uuid: string - The UUID of the current call. routeName: string - The name of the audio route to set (from getAudioRoutes). supportConnectionService() Checks if the ConnectionService is available on the device (Android only). Returns: boolean hasPhoneAccount() Checks if the user has enabled the phone account for the application on Android. Returns: Promise ``` -------------------------------- ### Call Management Methods Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Provides API documentation for various methods related to managing call states and user interactions within the React Native CallKeep library. This includes updating call display, ending calls, rejecting calls, and reporting call end reasons. ```APIDOC updateDisplay(uuid, displayName, handle, options) Updates the display for an outgoing call. Parameters: uuid: string - The UUID used for starting or displaying the call. displayName: string (optional) - The name of the caller to display. handle: string - The phone number of the caller. options: object (optional) ios: object hasVideo: boolean (optional) supportsHolding: boolean (optional) supportsDTMF: boolean (optional) supportsGrouping: boolean (optional) supportsUngrouping: boolean (optional) android: object (currently no-op) endCall(uuid) Ends an ongoing incoming or outgoing call. Parameters: uuid: string - The UUID of the call to end. endAllCalls() Ends all ongoing calls. rejectCall(uuid) Rejects an incoming call. Parameters: uuid: string - The UUID of the call to reject. reportEndCallWithUUID(uuid, reason) Reports that a call ended without user initiation. Parameters: uuid: string - The UUID of the call that ended. reason: int - The reason for the call ending (e.g., FAILED, REMOTE_USER_ENDED_CALL). Example: const { CONSTANTS as CK_CONSTANTS, RNCallKeep } = require('react-native-callkeep'); RNCallKeep.reportEndCallWithUUID(uuid, CK_CONSTANTS.END_CALL_REASONS.FAILED); setMutedCall(uuid, muted) Toggles the microphone on or off for a call. Parameters: uuid: string - The UUID of the current call. muted: boolean - True to mute, false to unmute. setOnHold(uuid, hold) Sets a call on or off hold. Parameters: uuid: string - The UUID of the current call. hold: boolean - True to put on hold, false to take off hold. ``` -------------------------------- ### CallKeep API Methods Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md This section details the various methods available in the CallKeep API for managing call states, user interactions, and device call capabilities. It includes methods for handling incoming calls, outgoing calls, call status updates, and platform-specific features. ```APIDOC getInitialEvents() - Returns: Promise - Description: Retrieves any events that were performed by the user before the JavaScript context was created. This serves as an alternative to the 'didLoadWithEvents' event. - Platforms: iOS, Android clearInitialEvents() - Returns: void - Description: Clears all pending actions that were returned by the getInitialEvents() method. - Platforms: iOS, Android setAvailable(available: boolean) - Returns: Promise - Description: Informs the ConnectionService whether the device is ready to make outgoing calls via the native Phone app. Set to `false` when disconnected from a SIP client, when a token expires, or when a user logs out to prevent users from being stuck in the native UI. - Platforms: Android setForegroundServiceSettings(settings: object) - Returns: Promise - Description: Configures settings for the foreground service on Android. - Platforms: Android canMakeMultipleCalls() - Returns: Promise - Description: Checks if the device can handle multiple concurrent calls. - Platforms: Android setCurrentCallActive() - Returns: Promise - Description: Marks the current call as active. - Platforms: Android checkIsInManagedCall() - Returns: Promise - Description: Checks if the application is currently managing a call. - Platforms: Android isCallActive() - Returns: Promise - Description: Checks if there is an active call. - Platforms: iOS getCalls() - Returns: Promise - Description: Retrieves a list of current calls. - Platforms: iOS displayIncomingCall(uuid: string, handle: string, name: string, options: object) - Returns: Promise - Description: Displays an incoming call notification to the user. - Parameters: - uuid: Unique identifier for the call. - handle: The phone number or identifier of the caller. - name: The name of the caller. - options: Additional options for displaying the call. - Platforms: iOS, Android answerIncomingCall() - Returns: Promise - Description: Answers an incoming call. - Platforms: iOS, Android startCall() - Returns: Promise - Description: Initiates a new outgoing call. - Platforms: iOS, Android updateDisplay(uuid: string, options: object) - Returns: Promise - Description: Updates the call display information. - Parameters: - uuid: The unique identifier of the call to update. - options: The updated display information. - Platforms: iOS, Android endCall() - Returns: Promise - Description: Ends the current active call. - Platforms: iOS, Android endAllCalls() - Returns: Promise - Description: Ends all active calls. - Platforms: iOS, Android rejectCall() - Returns: Promise - Description: Rejects an incoming call. - Platforms: iOS, Android reportEndCallWithUUID(uuid: string, reason: string) - Returns: Promise - Description: Reports the end of a call with a specific UUID and reason. - Parameters: - uuid: The unique identifier of the ended call. - reason: The reason for the call ending. - Platforms: iOS, Android setMutedCall(uuid: string, muted: boolean) - Returns: Promise - Description: Sets the muted status for a call. - Parameters: - uuid: The unique identifier of the call. - muted: Boolean indicating if the call is muted. - Platforms: iOS, Android setOnHold(uuid: string, onHold: boolean) - Returns: Promise - Description: Sets the on-hold status for a call. - Parameters: - uuid: The unique identifier of the call. - onHold: Boolean indicating if the call is on hold. - Platforms: iOS, Android setConnectionState(uuid: string, state: string) - Returns: Promise - Description: Sets the connection state for a call. - Parameters: - uuid: The unique identifier of the call. - state: The new connection state (e.g., 'Connected', 'Disconnected'). - Platforms: Android checkIfBusy() - Returns: Promise - Description: Checks if the device is currently busy with another call. - Platforms: iOS checkSpeaker() - Returns: Promise - Description: Checks if the speakerphone is currently active. - Platforms: iOS toggleAudioRouteSpeaker() - Returns: Promise - Description: Toggles the audio route between the earpiece and speakerphone. - Platforms: Android supportConnectionService() - Returns: Promise - Description: Checks if the device supports the ConnectionService API. - Platforms: Android hasPhoneAccount() - Returns: Promise - Description: Checks if a phone account is registered. - Platforms: Android hasOutgoingCall() - Returns: Promise - Description: Checks if the device is capable of making outgoing calls. - Platforms: Android hasDefaultPhoneAccount() - Returns: Promise - Description: Checks if a default phone account is set. - Platforms: Android checkPhoneAccountEnabled() - Returns: Promise - Description: Checks if the phone account is enabled. - Platforms: Android isConnectionServiceAvailable() - Returns: Promise - Description: Checks if the ConnectionService is available. - Platforms: Android backToForeground() - Returns: Promise - Description: Brings the application to the foreground. - Platforms: Android removeEventListener(event: string, callback: function) - Returns: void - Description: Removes an event listener. - Parameters: - event: The name of the event to remove the listener for. - callback: The callback function to remove. - Platforms: iOS, Android registerPhoneAccount() - Returns: void - Description: Registers the phone account with the system. - Platforms: Android registerAndroidEvents() - Returns: void - Description: Registers event listeners for Android-specific events. - Platforms: Android ``` -------------------------------- ### RNCallKeep Events Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Lists the available events that can be listened to within the React Native CallKeep library, indicating their support on iOS and Android platforms. ```APIDOC Events: | Event | iOS | Android | |-----------------------------------------------------------------| :--: | :-----: | | [didReceiveStartCallAction](#didReceiveStartCallAction) | ✅ | ✅ | | [answerCall](#answerCall) | ✅ | ✅ | | [endCall](#endCall) | ✅ | ✅ | | [didActivateAudioSession](#didActivateAudioSession) | ✅ | ✅ | | [didDisplayIncomingCall](#didDisplayIncomingCall) | ✅ | ✅ | | [didPerformSetMutedCallAction](#didPerformSetMutedCallAction) | ✅ | ✅ | | [didToggleHoldCallAction](#didToggleHoldCallAction) | ✅ | ✅ | | [didPerformDTMFAction](#didPerformDTMFAction) | ✅ | ✅ | | [didLoadWithEvents](#didLoadWithEvents) | ✅ | ❌ | | [showIncomingCallUi](#showIncomingCallUi) | ❌ | ✅ | | [silenceIncomingCall](#silenceIncomingCall) | ❌ | ✅ | | [checkReachability](#checkReachability) | ❌ | ✅ | | [didChangeAudioRoute](#didChangeAudioRoute) | ✅ | ✅ | | [onHasActiveCall](#onHasActiveCall) | ❌ | ✅ | ``` -------------------------------- ### Display Incoming Call Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Displays the system UI for an incoming call. Requires a unique UUID for tracking. ```APIDOC displayIncomingCall(uuid, handle, localizedCallerName = '', handleType = 'number', hasVideo = false, options = null) uuid: string - A unique identifier for the call, to be reused with stopCall. handle: string - The phone number or identifier of the caller. localizedCallerName: string (optional) - The name of the caller to display. handleType: string (optional, iOS only) - Type of handle ('generic', 'number', 'email'). Defaults to 'number'. hasVideo: boolean (optional, iOS only) - Indicates if the call has video. Defaults to false. options: object (optional) - Platform-specific options. ios: object supportsHolding: boolean (optional, default true) supportsDTMF: boolean (optional, default true) supportsGrouping: boolean (optional, default true) supportsUngrouping: boolean (optional, default true) android: object (currently no-op) ``` -------------------------------- ### iOS Specific Call Handling Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Provides API documentation for iOS-specific features of the React Native CallKeep library, including checking for active calls and speaker status. ```APIDOC checkIfBusy() Checks if there are any active calls on the device (iOS only). Returns: Promise - True if active calls exist, false otherwise. checkSpeaker() Checks if the device speaker is currently on (iOS only). Returns: Promise - True if the speaker is on, false otherwise. ``` -------------------------------- ### Debug React Native CallKeep Logs (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md This bash command allows you to view verbose logs specifically for the React Native CallKeep module on Android using ADB. This is useful for diagnosing issues related to call handling and notifications on the Android platform. ```bash adb logcat *:S RNCallKeep:V ``` -------------------------------- ### createIncomingConnectionFailed Listener (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Corresponds to the native `onCreateIncomingConnectionFailed` callback on Android for self-managed calls. This event indicates that the incoming SIP INVITE could not be accepted, and the app should reject it with an appropriate status code. It provides the caller's handle, call UUID, and name. ```javascript RNCallKeep.addEventListener('createIncomingConnectionFailed', ({ handle, callUUID, name }) => { }); ``` -------------------------------- ### Configure Foreground Service Settings (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Configures the foreground service for Android 11+ to maintain microphone access in the background. This is an Android-only feature. ```javascript RNCallKeep.setForegroundServiceSettings({ channelId: 'com.company.my', channelName: 'Foreground service for my app', notificationTitle: 'My app is running on background', notificationIcon: 'Path to the resource icon of the notification', }); ``` -------------------------------- ### Handle Incoming VoIP Push Notifications (iOS) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md This Objective-C code snippet demonstrates how to handle incoming VoIP push notifications using PushKit in a React Native application. It processes the push payload and reports the new incoming call to CallKeep, including details like caller name and custom data. ```objective-c - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion { // Process the received push [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type]; // Retrieve information like handle and callerName here // NSString *uuid = /* fetch for payload or ... */ [[[NSUUID UUID] UUIDString] lowercaseString]; // NSString *callerName = @"caller name here"; // NSString *handle = @"caller number here"; // NSDictionary *extra = [payload.dictionaryPayload valueForKeyPath:@"custom.path.to.data"]; /* use this to pass any special data (ie. from your notification) down to RN. Can also be `nil` */ [RNCallKeep reportNewIncomingCall: uuid handle: handle handleType: @"generic" hasVideo: NO localizedCallerName: callerName supportsHolding: YES supportsDTMF: YES supportsGrouping: YES supportsUngrouping: YES fromPushKit: YES payload: extra withCompletionHandler: completion]; } ``` -------------------------------- ### Bring App to Foreground (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Brings the application to the foreground on Android if it was in the background or closed. This ensures the app is visible when a call is active. ```javascript RNCallKeep.backToForeground(); ``` -------------------------------- ### Answer Incoming Call Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Notifies the SDK that a user has answered an incoming call via the app's UI. ```APIDOC answerIncomingCall(uuid) uuid: string - The unique identifier used for startCall or displayIncomingCall. ``` -------------------------------- ### Constants for Call End Reasons Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Defines constants for various reasons why a call might end. These are used to provide specific feedback or logging for call termination events. ```javascript const CONSTANTS = { END_CALL_REASONS: { FAILED: 1, REMOTE_ENDED: 2, UNANSWERED: 3, ANSWERED_ELSEWHERE: 4, DECLINED_ELSEWHERE: 5, MISSED: 6 } }; const { CONSTANTS as CK_CONSTANTS, RNCallKeep } = require('react-native-callkeep'); console.log(CK_CONSTANTS.END_CALL_REASONS.FAILED); // outputs 1 ``` -------------------------------- ### Check and Set Default Phone Account (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Verifies if a default phone account is set on Android. If not, it prompts the user to set one. This is a workaround for issues on certain Samsung devices. ```javascript const options = { alertTitle: 'Default not set', alertDescription: 'Please set the default phone account' }; RNCallKeep.hasDefaultPhoneAccount(options); ``` -------------------------------- ### Check Connection Service Availability (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Verifies if the Android device supports the ConnectionService API, which is essential for call management functionalities. ```javascript RNCallKeep.checkPhoneAccountEnabled(); ``` -------------------------------- ### answerCall Event Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Fired when the user answers an incoming call. Implement your call answering logic within this listener. ```javascript RNCallKeep.addEventListener('answerCall', ({ callUUID }) => { // Do your normal `Answering` actions here. }); ``` -------------------------------- ### didDisplayIncomingCall Event Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Callback for `RNCallKeep.displayIncomingCall`. Handles incoming call display logic and provides details about the caller and call status. Includes error handling for iOS. ```javascript RNCallKeep.addEventListener('didDisplayIncomingCall', ({ error, callUUID, handle, localizedCallerName, hasVideo, fromPushKit, payload }) => { // you might want to do following things when receiving this event: // - Start playing ringback if it is an outgoing call }); ``` -------------------------------- ### Android Manifest Permission for Self Managed Mode Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Specifies the necessary Android permission to enable the 'Self Managed' mode for calling applications. This permission allows the app to access call logs, which is required for managing calls independently. ```xml ``` -------------------------------- ### Set Availability (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Informs the ConnectionService about the device's readiness to make outgoing calls. Crucial for preventing users from being stuck in the native UI when disconnected or logged out. ```javascript RNCallKeep.setAvailable(true); ``` -------------------------------- ### Clear Initial Events Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Clears all pending actions previously returned by `getInitialEvents()`. ```javascript RNCallKeep.clearInitialEvents(); ``` -------------------------------- ### iOS reportNewIncomingCall Signature Update Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/MIGRATION_v3_v4.md This snippet shows the updated signature for the `reportNewIncomingCall` method on iOS in CallKeep v4. It includes parameters for call identification, caller details, and call features. Ensure your AppDelegate.m file uses this new signature for proper incoming call reporting. ```objective-c [RNCallKeep reportNewIncomingCall: uuidString handle: handle handleType: handleType hasVideo: YES localizedCallerName: localizedCallerName supportsHolding: YES supportsDTMF: YES supportsGrouping: YES supportsUngrouping: YES fromPushKit: YES payload: nil withCompletionHandler: nil]; ``` -------------------------------- ### didChangeAudioRoute Event Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Fired when the audio route changes. Provides the output device and additional platform-specific details like reason (iOS) or handle/callUUID (Android). Note the difference in output string casing between iOS and Android. ```javascript RNCallKeep.addEventListener('didChangeAudioRoute', ({ output }) => { }); ``` -------------------------------- ### showIncomingCallUi Listener (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Signals that the app must display an incoming call UI on Android when CallKeep is in self-managed mode. This event fires when the app calls `displayIncomingCall`. It provides the caller's handle, call UUID, and name. ```javascript RNCallKeep.addEventListener('showIncomingCallUi', ({ handle, callUUID, name }) => { }); ``` -------------------------------- ### Manage Multiple Calls (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Disables the 'Add call' button in the ConnectionService UI on Android. By default, multiple calls are enabled. ```javascript RNCallKeep.canMakeMultipleCalls(false); ``` -------------------------------- ### Mark Current Call as Active (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Marks the current call as active, which is necessary for setting correct Android capabilities like hold and mute once the call is active. This should be called when two-way audio is established. ```javascript RNCallKeep.setCurrentCallActive(uuid); ``` -------------------------------- ### checkReachability Listener (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md On Android, this listener checks if the application is reachable, especially when in the background, before initiating a call from the native phone application. It's necessary because the OS might close connections after a delay. The handler typically calls `RNCallKeep.setReachable()`. ```javascript RNCallKeep.addEventListener('checkReachability', () => { RNCallKeep.setReachable(); }); ``` -------------------------------- ### didPerformDTMFAction Event Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Used to handle DTMF tone input during a call. Provides the emitted digits and the associated call UUID. ```javascript RNCallKeep.addEventListener('didPerformDTMFAction', ({ digits, callUUID }) => { }); ``` -------------------------------- ### Check Phone Account Enabled (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Determines if the user's default phone account is set and enabled on Android. This is useful for custom permission prompts and should be used in conjunction with `registerPhoneAccount`. It does not trigger a prompt if no account is set. ```javascript RNCallKeep.checkPhoneAccountEnabled(); ``` -------------------------------- ### silenceIncomingCall Listener (Android) Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Corresponds to the native `onSilence` event on Android for self-managed calls. Implementers should silence the incoming call notification sound when this event is triggered. It passes the caller's handle, call UUID, and name. ```javascript RNCallKeep.addEventListener('silenceIncomingCall', ({ handle, callUUID, name }) => { }); ``` -------------------------------- ### didPerformSetMutedCallAction Event Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Fired when a call is muted by the system or the user. Provides the muted status and the call UUID. ```javascript RNCallKeep.addEventListener('didPerformSetMutedCallAction', ({ muted, callUUID }) => { }); ``` -------------------------------- ### endCall Event Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Triggered when the user ends a call. Use this to perform your application's hang-up actions. ```javascript RNCallKeep.addEventListener('endCall', ({ callUUID }) => { // Do your normal `Hang Up` actions here }); ``` -------------------------------- ### didToggleHoldCallAction Event Source: https://github.com/react-native-webrtc/react-native-callkeep/blob/master/README.md Triggered when a call is held or unheld by the current user. Includes the hold status and the call UUID. ```javascript RNCallKeep.addEventListener('didToggleHoldCallAction', ({ hold, callUUID }) => { }); ```