| ❌ | ✅ |
| removeEventListener() | void | ✅ | ✅ |
| registerPhoneAccount() | void | ❌ | ✅ |
| registerAndroidEvents() | void | ❌ | ✅ |
$3
If there were some actions performed by user before JS context has been created, this method would return early fired events. This is alternative to "didLoadWithEvents" event.
`js
RNCallKeep.getInitialEvents();
`$3
Clear all pending actions returned by
getInitialEvents().`js
RNCallKeep.clearInitialEvents();
`$3
_This feature is available only on Android._Tell _ConnectionService_ that the device is ready to make outgoing calls via the native Phone app.
If not the user will be stuck in the build UI screen without any actions.
Eg: Call it with
false when disconnected from the sip client, when your token expires, when your user log out ...
Eg: When your used log out (or the connection to your server is broken, etc..), you have to call setAvailable(false) so CallKeep will refuse the call and your user will not be stuck in the native UI.`js
RNCallKeep.setAvailable(true);
`$3
_This feature is available only on Android._Configures the Foreground Service used for Android 11 to get microphone access on background.
Similar to set the
foregroundService key in the setup() method.`js
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',
});
`$3
_This feature is available only on Android._Disable the "Add call" button in ConnectionService UI.
`js
RNCallKeep.canMakeMultipleCalls(false); // Enabled by default
`-
active: boolean
- Tell whether the app is ready or not$3
_This feature is available only on Android._Mark the current call as active (eg: when the callee has answered).
Necessary to set the correct Android capabilities (hold, mute) once the call is set as active.
Be sure to set this only after your call is ready for two way audio; used both incoming and outgoing calls.
`js
RNCallKeep.setCurrentCallActive(uuid);
`-
uuid: string
- The uuid used for startCall or displayIncomingCall$3
_This feature is available only on Android._Returns true if there is an active native call
`js
RNCallKeep.checkIsInManagedCall();
`
$3
_This feature is available only on IOS._Returns true if the UUID passed matches an existing and answered call.
This will return true ONLY if the call exists and the user has already answered the call. It will return false
if the call does not exist or has not been answered. This is exposed to both React Native and Native sides.
This was exposed so a call can be canceled if ringing and the user answered on a different device.
`js
RNCallKeep.isCallActive(uuid);
`-
uuid: string
- The uuid used for startCall or displayIncomingCall
$3
_This feature is available only on IOS._
Returns a Promise. The result will be an array with all current calls and their states.
`js
RNCallKeep.getCalls();response:
[{
callUUID: "E26B14F7-2CDF-48D0-9925-532199AE7C48",
hasConnected: true,
hasEnded: false,
onHold: false,
outgoing: false,
}]
`$3
Display system UI for incoming calls
`js
RNCallKeep.displayIncomingCall(uid, handle, localizedCallerName = '', handleType = 'number', hasVideo = false, options = null);
`-
uuid: string
- An uuid that should be stored and re-used for stopCall.
- handle: string
- Phone number of the caller
- localizedCallerName: string (optional)
- Name of the caller to be displayed on the native UI
- handleType: string (optional, iOS only)
- generic
- number (default)
- email
- hasVideo: boolean (optional, iOS only)
- false (default)
- true (you know... when not false)
- options: object (optional)
- 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)$3
Use this to tell the sdk a user answered a call from the app UI.
`js
RNCallKeep.answerIncomingCall(uuid)
`
- uuid: string
- The uuid used for startCall or displayIncomingCall
$3
When you make an outgoing call, tell the device that a call is occurring. The argument list is slightly
different on iOS and Android:
iOS:
`js
RNCallKeep.startCall(uuid, handle, contactIdentifier, handleType, hasVideo);
`Android:
`js
RNCallKeep.startCall(uuid, handle, contactIdentifier);
`-
uuid: string
- An uuid that should be stored and re-used for stopCall.
- handle: string
- Phone number of the callee
- contactIdentifier: string
- The identifier is displayed in the native call UI, and is typically the name of the call recipient.
- handleType: string (optional, iOS only)
- generic
- number (default)
- email
- hasVideo: boolean (optional, iOS only)
- false (default)
- true (you know... when not false)
$3
Use this to update the display after an outgoing call has started.`js
RNCallKeep.updateDisplay(uuid, displayName, handle)
`
- uuid: string
- The uuid used for startCall or displayIncomingCall
- displayName: string (optional)
- Name of the caller to be displayed on the native UI
- handle: string
- 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)$3
When finish an incoming/outgoing call.
(When user actively chooses to end the call from your app's UI.)
`js
RNCallKeep.endCall(uuid);
`-
uuid: string
- The uuid used for startCall or displayIncomingCall$3
End all ongoing calls.
`js
RNCallKeep.endAllCalls();
`$3
When you reject an incoming call.
`js
RNCallKeep.rejectCall(uuid);
`-
uuid: string
- The uuid used for startCall or displayIncomingCall$3
Report that the call ended without the user initiating.
(Not ended by user, is usually due to the following reasons)
`js
RNCallKeep.reportEndCallWithUUID(uuid, reason);
`-
uuid: string
- The uuid used for startCall or displayIncomingCall
- reason: int
- Reason for the end call
- Call failed: 1
- Remote user ended call: 2
- Remote user did not answer: 3
- Call Answered elsewhere: 4
- Call declined elsewhere: 5 (on Android this will map to Remote user ended call if you use the constants)
- Missed: 6 (on iOS this will map to remote user ended call)
- Access reasons as constants
`js
const { CONSTANTS as CK_CONSTANTS, RNCallKeep } from 'react-native-callkeep'; RNCallKeep.reportEndCallWithUUID(uuid, CK_CONSTANTS.END_CALL_REASONS.FAILED);
`$3
Switch the mic on/off.
`js
RNCallKeep.setMutedCall(uuid, true);
`-
uuid: string
- uuid of the current call.
- muted: boolean$3
Set a call on/off hold.
`js
RNCallKeep.setOnHold(uuid, true)
`-
uuid: string
- uuid of the current call.
- hold: boolean$3
_This feature is available only on Android._
Change the state of the call
`js
RNCallKeep.setConnectionState(uuid, state)
`-
uuid: string
- uuid of the current call.
- state: See Connection.STATE_* documentation$3
_This feature is available only on IOS._
Checks if there are any active calls on the device and returns a promise with a boolean value (
true if there're active calls, false otherwise).`js
RNCallKeep.checkIfBusy();
`$3
_This feature is available only on IOS._
Checks if the device speaker is on and returns a promise with a boolean value (
true if speaker is on, false otherwise).`js
RNCallKeep.checkSpeaker();
`$3
_This feature is available only on Android._
Update the audio route of Audio Service on Android with a
routeSpeaker boolean value (true if speaker need on, false otherwise).
When Phone call is active, Android control the audio via connection service. so this function help to toggle the audio to Speaker or wired/ear-piece or vice-versa `js
RNCallKeep.toggleAudioRouteSpeaker(uuid, true);
`-
uuid: string
- uuid of the current call.
- routeSpeaker: boolean$3
Get the list of available audio routes. i.e. bluetooth, wired/ear-piece, speaker and phone.
`js
await RNCallKeep.getAudioRoutes(): AudioRoute;
``
type AudioRoute = {
name: string,
type: string
}
`$3
Set audio route using a route from
getAudioRoutes.`js
await RNCallKeep.setAudioRoute(uuid, routeName);
`-
uuid: string
- uuid of the current call.
- routeName: String
- AudioRoute.name. $3
_This feature is available only on Android._
Tells if
ConnectionService is available on the device (returns a boolean).`js
RNCallKeep.supportConnectionService();
`$3
_This feature is available only on Android._
Checks if the user has enabled the phone account for your application.
A phone account must be enable to be able to display UI screen on incoming call and make outgoing calls from native Contact application.
Returns a promise of a boolean.
`js
await RNCallKeep.hasPhoneAccount();
`$3
_This feature is available only on Android, useful when waking up the application for an outgoing call._
When waking up the Android application in background mode (eg: when the application is killed and the user make a call from the native Phone application).
The user can hang up the call before your application has been started in background mode, and you can lost the
RNCallKeepPerformEndCallAction event.To be sure that the outgoing call is still here, you can call
hasOutgoingCall when you app waken up.
`js
const hasOutgoingCall = await RNCallKeep.hasOutgoingCall();
`$3
_This feature is available only on Android._
Checks if the user has set a default phone account.
If the user has not set a default they will be prompted to do so with an alert.
This is a workaround for an issue affecting some Samsung devices.
`js
const options = {
alertTitle: 'Default not set',
alertDescription: 'Please set the default phone account'
};RNCallKeep.hasDefaultPhoneAccount(options);
`$3
_This feature is available only on Android._
Checks if the user has set a default phone account and it's enabled.
It's useful for custom permission prompts. It should be used in pair with
registerPhoneAccount
Similar to hasDefaultPhoneAccount but without trigering a prompt if the user doesn't have a phone account.
`js
RNCallKeep.checkPhoneAccountEnabled();
`$3
_This feature is available only on Android._
Check if the device support ConnectionService.
`js
RNCallKeep.checkPhoneAccountEnabled();
`$3
_This feature is available only on Android._
Use this to display the application in foreground if the application was in background state.
This method will open the application if it was closed.
`js
RNCallKeep.backToForeground();
`$3
Allows to remove the listener on an event.
`js
RNCallKeep.removeEventListener('checkReachability');
`$3
Registers Android phone account manually, useful for custom permission prompts when you don't want to call
setup().
This method is called by setup, if you already use setup you don't need it._This feature is available only on Android._
_On iOS you still have to call
setup()._`js
RNCallKeep.registerPhoneAccount(options);
`$3
Registers Android UI events, useful when you don't want to call
setup().
This method is called by setup, if you already use setup you don't need it._This feature is available only on Android._
_On iOS you still have to call
setup()._`js
RNCallKeep.registerAndroidEvents();
`Events
| Event | iOS | Android |
| ----------------------------------------------------------------- | :--: | :-----: |
| didReceiveStartCallAction | ✅ | ✅ |
| answerCall | ✅ | ✅ |
| endCall | ✅ | ✅ |
| didActivateAudioSession | ✅ | ✅ |
| didDisplayIncomingCall | ✅ | ✅ |
| didPerformSetMutedCallAction | ✅ | ✅ |
| didToggleHoldCallAction | ✅ | ✅ |
| didPerformDTMFAction | ✅ | ✅ |
| didLoadWithEvents | ✅ | ❌ |
| showIncomingCallUi | ❌ | ✅ |
| silenceIncomingCall | ❌ | ✅ |
| checkReachability | ❌ | ✅ |
| didChangeAudioRoute | ✅ | ✅ |
| onHasActiveCall | ❌ | ✅ |
$3
Device sends this event once it decides the app is allowed to start a call, either from the built-in phone screens (iOS/_Recents_, Android/_Contact_),
or by the app calling
RNCallKeep.startCall.Try to start your app call action from here (e.g. get credentials of the user by
data.handle and/or send INVITE to your SIP server)Note: on iOS
callUUID is not defined as the call is not yet managed by CallKit. You have to generate your own and call startCall.`js
RNCallKeep.addEventListener('didReceiveStartCallAction', ({ handle, callUUID, name }) => {});
`-
handle (string)
- Phone number of the callee
- callUUID (string)
- The UUID of the call that is to be answered
- name (string)
- Name of the callee$3
User answer the incoming call
`js
RNCallKeep.addEventListener('answerCall', ({ callUUID }) => {
// Do your normal Answering actions here.
});
`-
callUUID (string)
- The UUID of the call that is to be answered.$3
User finish the call.
`js
RNCallKeep.addEventListener('endCall', ({ callUUID }) => {
// Do your normal Hang Up actions here
});
`-
callUUID (string)
- The UUID of the call that is to be ended.$3
The
AudioSession has been activated by RNCallKeep.`js
RNCallKeep.addEventListener('didActivateAudioSession', () => {
// you might want to do following things when receiving this event:
// - Start playing ringback if it is an outgoing call
});
`$3
Callback for
RNCallKeep.displayIncomingCall`js
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
});
`-
error (string)
- iOS only.
- errorCode (string)
- iOS only. Possible values: "Unentitled", "CallUUIDAlreadyExists", "FilteredByDoNotDisturb", "FilteredByBlockList", "Unknown". See https://developer.apple.com/documentation/callkit/cxerrorcodeincomingcallerror for more information.
- callUUID (string)
- The UUID of the call.
- handle (string)
- Phone number of the caller
- localizedCallerName (string)
- Name of the caller to be displayed on the native UI
- hasVideo (string)
- 1 (video enabled)
- 0 (video not enabled)
- fromPushKit (string)
- 1 (call triggered from PushKit)
- 0 (call not triggered from PushKit)
- payload (object)
- VOIP push payload.$3
A call was muted by the system or the user:
`js
RNCallKeep.addEventListener('didPerformSetMutedCallAction', ({ muted, callUUID }) => {});
`-
muted (boolean)
- callUUID (string)
- The UUID of the call.$3
A call was held or unheld by the current user
`js
RNCallKeep.addEventListener('didToggleHoldCallAction', ({ hold, callUUID }) => {});
`-
hold (boolean)
- callUUID (string)
- The UUID of the call.$3
Triggered when the audio route has been changed.
`js
RNCallKeep.addEventListener('didChangeAudioRoute', ({ output }) => {});
`-
output (string) ⚠️ Will send Speaker on iOS but SPEAKER on Android.
- reason (number, iOS only) See case's in https://developer.apple.com/documentation/avfaudio/avaudiosession/routechangereason
- handle (string, Android only) Phone number of the incoming caller
- callUUID (string, Android only) The UUID of the call$3
Used type a number on his dialer
`js
RNCallKeep.addEventListener('didPerformDTMFAction', ({ digits, callUUID }) => {});
`-
digits (string)
- The digits that emit the dtmf tone
- callUUID (string)
- The UUID of the call.$3
iOS only.
Called as soon as JS context initializes if there were some actions performed by user before JS context has been created.
Since iOS 13, you must display incoming call on receiving PushKit push notification. But if app was killed, it takes some time to create JS context. If user answers the call (or ends it) before JS context has been initialized, user actions will be passed as events array of this event. Similar situation can happen if user would like to start a call from Recents or similar iOS app, assuming that your app was in killed state.
In order for this event to reliably fire, it's necessary to perform setup in
AppDelegate.mNOTE: You still need to subscribe / handle the rest events as usuall. This is just a helper whcih cache and propagate early fired events if and only if for "the native events which DID fire BEFORE js bridge is initialed", it does NOT mean this will have events each time when the app reopened.
`js
// register didLoadWithEvents somewhere early in your app when it is ready to handle callkeep events.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
});
`-
events Array
- name: string
Native event name like: RNCallKeepPerformAnswerCallAction
- data: object
Object with data passed together with specific event so it can be handled in the same way like original event, for example ({ callUUID }) for answerCall event if name is RNCallKeepPerformAnswerCallAction$3
_Android only. Self Managed only._
Only when CallKeep is setup to be in self managed mode. Signals that the app must show an incoming call UI. The implementor must either call
displayIncomingCall from react native or native android code to make this event fire.`js
RNCallKeep.addEventListener('showIncomingCallUi', ({ handle, callUUID, name }) => {});
`The following values will match those initially passed to
displayIncomingCall-
handle (string)
- Phone number of the incoming caller.
- callUUID (string)
- The UUID of the call.
- name (string)
- Caller Name.$3
_Android only. Self Managed only._
Corresponds to the native onSilence event). The implementor should silence the corresponding incoming calls notification sound when and if this event is fired.
`js
RNCallKeep.addEventListener('silenceIncomingCall', ({ handle, callUUID, name }) => {});
`The following values will match those initially passed to
silenceIncomingCall-
handle (string)
- Phone number of the incoming caller.
- callUUID (string)
- The UUID of the call.
- name (string)
- Caller Name.$3
_Android only. Self Managed only._
Corresponds to the native onCreateIncomingConnectionFailed callback). The implementor should reject the incoming SIP INVITE with an appropriate status code, such as 483 User Busy. Android unfortunately does not provide the exact reason for refusing to let you accept an incoming call, but they do list a set of reasons here
`js
RNCallKeep.addEventListener('createIncomingConnectionFailed', ({ handle, callUUID, name }) => {});
`The following values will match those initially passed to
silenceIncomingCall-
handle (string)
- Phone number of the incoming caller.
- callUUID (string)
- The UUID of the call.
- name (string)
- Caller Name.$3
_Android only._
On Android when the application is in background, after a certain delay the OS will close every connection with informing about it.
So we have to check if the application is reachable before making a call from the native phone application.
`js
RNCallKeep.addEventListener('checkReachability', () => {
RNCallKeep.setReachable();
});`$3
_Android only._
A listener that tells the JS side if a native call has been answered while there was an active self-managed call
`js
RNCallKeep.addEventListener('onHasActiveCall', () => {
// eg: End active app call if native call is answered
});`Example
A full example is available in the example folder.
`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() {
}
}
`
Receiving a call when the application is not reachable.
In some case your application can be unreachable :
- when the user kill the application
- when it's in background since a long time (eg: after ~5mn the os will kill all connections).
To be able to wake up your application to display the incoming call, you can use https://github.com/react-native-webrtc/react-native-voip-push-notification on iOS or BackgroundMessaging from react-native-firebase-(Optional)(Android-only)-Listen-for-FCM-messages-in-the-background).
You have to send a push to your application, like with Firebase for Android and with a library supporting PushKit pushes for iOS.
PushKit
Since iOS 13, you'll have to report the incoming calls that wakes up your application with a VoIP push. Add this in your
AppDelegate.m if you're using VoIP pushes to wake up your application :`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];
}
`Android 11
Since Android 11, your application requires to start a foregroundService in order to access the microphone in background.
You'll need to upgrade your
compileSdkVersion to 30 to be able to use this feature.You have to set the
foregroundService key in the setup() method and add a foregroundServiceType in the AndroidManifest file.Debug
$3
`
adb logcat *:S RNCallKeep:V
`Troubleshooting
- Ensure that you construct a valid uuid by importing the uuid library and running uuid.v4() as shown in the examples. If you don't do this and use a custom string, the incoming call screen will never be shown on iOS.Contributing
Any pull request, issue report and suggestion are highly welcome!
License
This work is dual-licensed under ISC and MIT.
Previous work done by @ianlin on iOS is on ISC Licence.
We choose MIT for the rest of the project.
SPDX-License-Identifier: ISC OR MIT`