diff --git a/README.md b/README.md index 8b5e8a2f..f2305377 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,21 @@ Be sure to set this only after your call is ready for two way audio; used both i RNCallKeep.setCurrentCallActive(uuid); ``` +- `uuid`: string + - The `uuid` used for `startCall` or `displayIncomingCall` + +### isCallActive +_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` diff --git a/index.d.ts b/index.d.ts index 2f86c02a..449db32d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -114,7 +114,9 @@ export default class RNCallKeep { static setReachable() { } + static isCallActive(uuid: string): Promise { + } /** * @description supportConnectionService method is available only on Android. */ diff --git a/index.js b/index.js index 38b61301..b09c0477 100644 --- a/index.js +++ b/index.js @@ -108,6 +108,8 @@ class RNCallKeep { } }; + isCallActive = async(uuid) => await RNCallKeepModule.isCallActive(uuid); + endCall = (uuid) => RNCallKeepModule.endCall(uuid); endAllCalls = () => RNCallKeepModule.endAllCalls(); diff --git a/ios/RNCallKeep/RNCallKeep.h b/ios/RNCallKeep/RNCallKeep.h index 9c0d8c6c..a91dfacd 100644 --- a/ios/RNCallKeep/RNCallKeep.h +++ b/ios/RNCallKeep/RNCallKeep.h @@ -46,4 +46,7 @@ continueUserActivity:(NSUserActivity *)userActivity + (void)endCallWithUUID:(NSString *)uuidString reason:(int)reason; + ++ (BOOL)isCallActive:(NSString *)uuidString; + @end \ No newline at end of file diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index 251e852c..67499f40 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -273,6 +273,14 @@ + (void)initCallKitProvider { [self requestTransaction:transaction]; } +RCT_EXPORT_METHOD(isCallActive:(NSString *)uuidString) +{ +#ifdef DEBUG + NSLog(@"[RNCallKeep][isCallActive] uuid = %@", uuidString); +#endif + [RNCallKeep isCallActive: uuidString]; +} + - (void)requestTransaction:(CXTransaction *)transaction { #ifdef DEBUG @@ -304,6 +312,20 @@ - (void)requestTransaction:(CXTransaction *)transaction }]; } ++ (BOOL)isCallActive:(NSString *)uuidString +{ + CXCallObserver *callObserver = [[CXCallObserver alloc] init]; + NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString]; + + for(CXCall *call in callObserver.calls){ + NSLog(@"[RNCallKeep] isCallActive %@ %d ?", call.UUID, [call.UUID isEqual:uuid]); + if([call.UUID isEqual:[[NSUUID alloc] initWithUUIDString:uuidString]] && !call.hasConnected){ + return true; + } + } + return false; +} + + (void)endCallWithUUID:(NSString *)uuidString reason:(int)reason {