Skip to content

Commit

Permalink
Merge pull request #172 from ajnozari/master
Browse files Browse the repository at this point in the history
New Method Check if Active Call with UUID
  • Loading branch information
manuquentin authored May 15, 2020
2 parents 5b37f2d + 095a34c commit 3e912d4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export default class RNCallKeep {
static setReachable() {

}
static isCallActive(uuid: string): Promise<boolean> {

}
/**
* @description supportConnectionService method is available only on Android.
*/
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class RNCallKeep {
}
};

isCallActive = async(uuid) => await RNCallKeepModule.isCallActive(uuid);

endCall = (uuid) => RNCallKeepModule.endCall(uuid);

endAllCalls = () => RNCallKeepModule.endAllCalls();
Expand Down
3 changes: 3 additions & 0 deletions ios/RNCallKeep/RNCallKeep.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ continueUserActivity:(NSUserActivity *)userActivity

+ (void)endCallWithUUID:(NSString *)uuidString
reason:(int)reason;

+ (BOOL)isCallActive:(NSString *)uuidString;

@end
22 changes: 22 additions & 0 deletions ios/RNCallKeep/RNCallKeep.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 3e912d4

Please sign in to comment.