From f0a3f2db63164d549021db7e37961c6d75c8a670 Mon Sep 17 00:00:00 2001 From: remigijus Date: Mon, 17 May 2021 14:42:27 +0300 Subject: [PATCH 1/5] reject call listener --- ios/RNCallKeep/RNCallKeep.h | 2 +- ios/RNCallKeep/RNCallKeep.m | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ios/RNCallKeep/RNCallKeep.h b/ios/RNCallKeep/RNCallKeep.h index c8e7bbdf..39d698e2 100644 --- a/ios/RNCallKeep/RNCallKeep.h +++ b/ios/RNCallKeep/RNCallKeep.h @@ -45,6 +45,6 @@ continueUserActivity:(NSUserActivity *)userActivity + (BOOL)isCallActive:(NSString *)uuidString; -+ (void)setup:(NSDictionary *)options; ++ (void)setup:(NSDictionary *)options withEventHandler: (void (^) (NSString * eventName, id data)) onEvent; @end diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index 4864d258..e985ccd3 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -44,6 +44,7 @@ @implementation RNCallKeep NSMutableArray *_delayedEvents; } +void (^onEventHandler) (NSString * callUUID, id data); static bool isSetupNatively; static CXProvider* sharedProvider; @@ -81,6 +82,7 @@ - (void)dealloc if (self.callKeepProvider != nil) { [self.callKeepProvider invalidate]; } + onEventHandler = nil; sharedProvider = nil; } @@ -136,10 +138,14 @@ + (void)initCallKitProvider { } } -+ (void)setup:(NSDictionary *)options { ++ (void)setup:(NSDictionary *)options withEventHandler: (void (^) (NSString * eventName, id data)) onEvent { RNCallKeep *callKeep = [RNCallKeep allocWithZone: nil]; [callKeep setup:options]; isSetupNatively = YES; + + if (onEvent != nil) { + onEventHandler = onEvent; + } } RCT_EXPORT_METHOD(setup:(NSDictionary *)options) @@ -780,7 +786,12 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *) NSLog(@"[RNCallKeep][CXProviderDelegate][provider:performEndCallAction]"); #endif [self sendEventWithNameWrapper:RNCallKeepPerformEndCallAction body:@{ @"callUUID": [action.callUUID.UUIDString lowercaseString] }]; - [action fulfill]; + + if (onEventHandler != nil) { + onEventHandler(action.callUUID.UUIDString, action); + } else { + [action fulfill]; + } } -(void)provider:(CXProvider *)provider performSetHeldCallAction:(CXSetHeldCallAction *)action From cedcfc2a633136a2a2697dae735ccbb4f9c44a7b Mon Sep 17 00:00:00 2001 From: remigijus Date: Wed, 19 May 2021 09:37:44 +0300 Subject: [PATCH 2/5] documentation for getInitialEvents added --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 65e9fee0..70d21c64 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,16 @@ Self Managed calling apps are an advanced topic, and there are many steps involv ## Methods +### getInitialEvents + +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" handler. + +iOS only. + +```js +RNCallKeep.getInitialEvents(); +``` + ### setAvailable _This feature is available only on Android._ From 5fdf6cce3e3bb4c07e7df050bf6e45875123d9f2 Mon Sep 17 00:00:00 2001 From: remigijus Date: Wed, 19 May 2021 09:52:16 +0300 Subject: [PATCH 3/5] documentation for getInitialEvents added --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 65e9fee0..2a45a226 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,15 @@ 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. + +```js +RNCallKeep.getInitialEvents(); +``` + ### setAvailable _This feature is available only on Android._ From 13a132bd1cc152beaeaefd09517a0a9c8acb6a71 Mon Sep 17 00:00:00 2001 From: remigijus Date: Wed, 19 May 2021 14:52:21 +0300 Subject: [PATCH 4/5] implementation of call rejection handler, which fires only when call is rejected --- ios/RNCallKeep/RNCallKeep.h | 4 +++- ios/RNCallKeep/RNCallKeep.m | 31 +++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/ios/RNCallKeep/RNCallKeep.h b/ios/RNCallKeep/RNCallKeep.h index 39d698e2..1eec7908 100644 --- a/ios/RNCallKeep/RNCallKeep.h +++ b/ios/RNCallKeep/RNCallKeep.h @@ -45,6 +45,8 @@ continueUserActivity:(NSUserActivity *)userActivity + (BOOL)isCallActive:(NSString *)uuidString; -+ (void)setup:(NSDictionary *)options withEventHandler: (void (^) (NSString * eventName, id data)) onEvent; ++ (void)setup:(NSDictionary *)options; + ++ (void)setup:(NSDictionary *)options callRejectHandler: (void (^) (NSString* uuid, void (^completion)(void))) onReject; @end diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index e985ccd3..46afd0a6 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -43,8 +43,8 @@ @implementation RNCallKeep bool _hasListeners; NSMutableArray *_delayedEvents; } - -void (^onEventHandler) (NSString * callUUID, id data); +NSMutableDictionary *_answeredCalls; +void (^onRejectHandler) (NSString* uuid, void (^completion)(void)); static bool isSetupNatively; static CXProvider* sharedProvider; @@ -82,8 +82,9 @@ - (void)dealloc if (self.callKeepProvider != nil) { [self.callKeepProvider invalidate]; } - onEventHandler = nil; + onRejectHandler = nil; sharedProvider = nil; + _answeredCalls = nil; } // Override method of RCTEventEmitter @@ -138,13 +139,22 @@ + (void)initCallKitProvider { } } -+ (void)setup:(NSDictionary *)options withEventHandler: (void (^) (NSString * eventName, id data)) onEvent { ++ (void)setup:(NSDictionary *)options { + RNCallKeep *callKeep = [RNCallKeep allocWithZone: nil]; + [callKeep setup: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 (onEvent != nil) { - onEventHandler = onEvent; + if (onReject != nil) { + onRejectHandler = onReject; + } + if (_answeredCalls == nil) { + _answeredCalls = [[NSMutableDictionary alloc] init]; } } @@ -527,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:@{ @@ -774,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]; @@ -787,8 +800,10 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *) #endif [self sendEventWithNameWrapper:RNCallKeepPerformEndCallAction body:@{ @"callUUID": [action.callUUID.UUIDString lowercaseString] }]; - if (onEventHandler != nil) { - onEventHandler(action.callUUID.UUIDString, action); + if (onRejectHandler != nil && _answeredCalls[action.callUUID.UUIDString] == NO) { + onRejectHandler(action.callUUID.UUIDString, ^() { + [action fulfill]; + }); } else { [action fulfill]; } From a0b8fa52a8334189d95ced768fea00011cd00474 Mon Sep 17 00:00:00 2001 From: remigijus Date: Wed, 19 May 2021 15:15:17 +0300 Subject: [PATCH 5/5] revert other pr changes --- README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/README.md b/README.md index 21fbf201..65e9fee0 100644 --- a/README.md +++ b/README.md @@ -166,16 +166,6 @@ 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 - -```js -RNCallKeep.getInitialEvents(); -``` - ### setAvailable _This feature is available only on Android._