Skip to content
Closed
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
2 changes: 2 additions & 0 deletions ios/RNCallKeep/RNCallKeep.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ continueUserActivity:(NSUserActivity *)userActivity

+ (void)setup:(NSDictionary *)options;

+ (void)setup:(NSDictionary *)options callRejectHandler: (void (^) (NSString* uuid, void (^completion)(void))) onReject;

@end
30 changes: 28 additions & 2 deletions ios/RNCallKeep/RNCallKeep.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ @implementation RNCallKeep
bool _hasListeners;
NSMutableArray *_delayedEvents;
}

NSMutableDictionary *_answeredCalls;
void (^onRejectHandler) (NSString* uuid, void (^completion)(void));
static bool isSetupNatively;
static CXProvider* sharedProvider;

Expand Down Expand Up @@ -81,7 +82,9 @@ - (void)dealloc
if (self.callKeepProvider != nil) {
[self.callKeepProvider invalidate];
}
onRejectHandler = nil;
sharedProvider = nil;
_answeredCalls = nil;
}

// Override method of RCTEventEmitter
Expand Down Expand Up @@ -142,6 +145,19 @@ + (void)setup:(NSDictionary *)options {
isSetupNatively = YES;
}

+ (void)setup:(NSDictionary *)options callRejectHandler: (void (^) (NSString* uuid, void (^completion)(void))) onReject {
RNCallKeep *callKeep = [RNCallKeep allocWithZone: nil];
[callKeep setup:options];
isSetupNatively = YES;

if (onReject != nil) {
onRejectHandler = onReject;
}
if (_answeredCalls == nil) {
_answeredCalls = [[NSMutableDictionary alloc] init];
}
}

RCT_EXPORT_METHOD(setup:(NSDictionary *)options)
{
if (isSetupNatively) {
Expand Down Expand Up @@ -521,6 +537,8 @@ + (void)reportNewIncomingCall:(NSString *)uuidString
callUpdate.localizedCallerName = localizedCallerName;

[RNCallKeep initCallKitProvider];
[_answeredCalls setValue:NO forKey:uuidString];

[sharedProvider reportNewIncomingCallWithUUID:uuid update:callUpdate completion:^(NSError * _Nullable error) {
RNCallKeep *callKeep = [RNCallKeep allocWithZone: nil];
[callKeep sendEventWithNameWrapper:RNCallKeepDidDisplayIncomingCall body:@{
Expand Down Expand Up @@ -768,6 +786,7 @@ - (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAct
#ifdef DEBUG
NSLog(@"[RNCallKeep][CXProviderDelegate][provider:performAnswerCallAction]");
#endif
[_answeredCalls setValue:[NSNumber numberWithBool:YES] forKey:action.callUUID.UUIDString];
[self configureAudioSession];
[self sendEventWithNameWrapper:RNCallKeepPerformAnswerCallAction body:@{ @"callUUID": [action.callUUID.UUIDString lowercaseString] }];
[action fulfill];
Expand All @@ -780,7 +799,14 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)
NSLog(@"[RNCallKeep][CXProviderDelegate][provider:performEndCallAction]");
#endif
[self sendEventWithNameWrapper:RNCallKeepPerformEndCallAction body:@{ @"callUUID": [action.callUUID.UUIDString lowercaseString] }];
[action fulfill];

if (onRejectHandler != nil && _answeredCalls[action.callUUID.UUIDString] == NO) {
onRejectHandler(action.callUUID.UUIDString, ^() {
[action fulfill];
});
} else {
[action fulfill];
}
}

-(void)provider:(CXProvider *)provider performSetHeldCallAction:(CXSetHeldCallAction *)action
Expand Down