Skip to content
This repository was archived by the owner on May 26, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ Initialise RNCallKit with options
- generic
- number (default)
- email
- **hasVideo**: boolean (optional)
- false (default)
- **localizedCallerName**: string (optional)

Call when you receive incoming calls to display system UI
Expand Down Expand Up @@ -209,6 +211,12 @@ The `AudioSession` has been activated by **RNCallKit**, you might want to do fol

- Start playing ringback if it is an outgoing call

### - didDisplayIncomingCall

Callback for `RNCallKit.displayIncomingCall`

**error**: string (optional)

## Usage

```javascript
Expand Down Expand Up @@ -237,6 +245,7 @@ class RNCallKitExample extends React.Component {
RNCallKit.addEventListener('answerCall', this.onRNCallKitPerformAnswerCallAction);
RNCallKit.addEventListener('endCall', this.onRNCallKitPerformEndCallAction);
RNCallKit.addEventListener('didActivateAudioSession', this.onRNCallKitDidActivateAudioSession);
RNCallKit.addEventListener('didDisplayIncomingCall', this.onRNCallKitDidDisplayIncomingCall);
}

onRNCallKitDidReceiveStartCallAction(data) {
Expand Down Expand Up @@ -277,6 +286,12 @@ class RNCallKitExample extends React.Component {
*/
}

onRNCallKitDidDisplayIncomingCall(error) {
/* You will get this event after RNCallKit finishes showing incoming call UI
* You can check if there was an error while displaying
*/
}

// This is a fake function where you can receive incoming call notifications
onIncomingCall() {
// Store the generated uuid somewhere
Expand Down
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const RNCallKitDidReceiveStartCallAction = 'RNCallKitDidReceiveStartCallAction';
const RNCallKitPerformAnswerCallAction = 'RNCallKitPerformAnswerCallAction';
const RNCallKitPerformEndCallAction = 'RNCallKitPerformEndCallAction';
const RNCallKitDidActivateAudioSession = 'RNCallKitDidActivateAudioSession';
const RNCallKitDidDisplayIncomingCall = 'RNCallKitDidDisplayIncomingCall';

export default class RNCallKit {
static addEventListener(type, handler) {
Expand All @@ -41,7 +42,13 @@ export default class RNCallKit {
RNCallKitDidActivateAudioSession,
() => { handler(); }
);
} else if (type === 'didDisplayIncomingCall') {
listener = _RNCallKitEmitter.addListener(
RNCallKitDidDisplayIncomingCall,
(data) => { handler(data.error); }
);
}

_callkitEventHandlers.set(handler, listener);
}

Expand Down
23 changes: 13 additions & 10 deletions ios/RNCallKit/RNCallKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
static NSString *const RNCallKitPerformAnswerCallAction = @"RNCallKitPerformAnswerCallAction";
static NSString *const RNCallKitPerformEndCallAction = @"RNCallKitPerformEndCallAction";
static NSString *const RNCallKitDidActivateAudioSession = @"RNCallKitDidActivateAudioSession";
static NSString *const RNCallKitDidDisplayIncomingCall = @"RNCallKitDidDisplayIncomingCall";

@implementation RNCallKit
{
Expand Down Expand Up @@ -60,11 +61,12 @@ - (void)dealloc
- (NSArray<NSString *> *)supportedEvents
{
return @[
RNCallKitDidReceiveStartCallAction,
RNCallKitPerformAnswerCallAction,
RNCallKitPerformEndCallAction,
RNCallKitDidActivateAudioSession
];
RNCallKitDidReceiveStartCallAction,
RNCallKitPerformAnswerCallAction,
RNCallKitPerformEndCallAction,
RNCallKitDidActivateAudioSession,
RNCallKitDidDisplayIncomingCall
];
}

RCT_EXPORT_METHOD(setup:(NSDictionary *)options)
Expand Down Expand Up @@ -104,6 +106,7 @@ - (void)dealloc
callUpdate.localizedCallerName = localizedCallerName;

[self.callKitProvider reportNewIncomingCallWithUUID:uuid update:callUpdate completion:^(NSError * _Nullable error) {
[self sendEventWithName:RNCallKitDidDisplayIncomingCall body:@{ @"error": error ? error.localizedDescription : @"" }];
if (error == nil) {
// Workaround per https://forums.developer.apple.com/message/169511
if ([self lessThanIos10_2]) {
Expand Down Expand Up @@ -309,7 +312,7 @@ + (BOOL)application:(UIApplication *)application

+ (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler
restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler
{
#ifdef DEBUG
NSLog(@"[RNCallKit][application:continueUserActivity]");
Expand All @@ -319,25 +322,25 @@ + (BOOL)application:(UIApplication *)application
NSString *handle;
BOOL isAudioCall = [userActivity.activityType isEqualToString:INStartAudioCallIntentIdentifier];
BOOL isVideoCall = [userActivity.activityType isEqualToString:INStartVideoCallIntentIdentifier];

if (isAudioCall) {
INStartAudioCallIntent *startAudioCallIntent = (INStartAudioCallIntent *)interaction.intent;
contact = [startAudioCallIntent.contacts firstObject];
} else if (isVideoCall) {
INStartVideoCallIntent *startVideoCallIntent = (INStartVideoCallIntent *)interaction.intent;
contact = [startVideoCallIntent.contacts firstObject];
}

if (contact != nil) {
handle = contact.personHandle.value;
}

if (handle != nil && handle.length > 0 ){
NSDictionary *userInfo = @{
@"handle": handle,
@"video": @(isVideoCall)
};

[[NSNotificationCenter defaultCenter] postNotificationName:RNCallKitHandleStartCallNotification
object:self
userInfo:userInfo];
Expand Down