Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native callback for call rejects #423

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ Self Managed calling apps are an advanced topic, and there are many steps involv

## Methods

### getInitialEvents
_This feature is available only on iOS._

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.
>>>>>>> getInitialEvents-docs
remigijusbalc marked this conversation as resolved.
Show resolved Hide resolved

```js
RNCallKeep.getInitialEvents();
```

### setAvailable
_This feature is available only on Android._

Expand Down
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