I am using https://github.com/react-native-webrtc/react-native-callkeep to implement a VOIP app in React Native.
It has a built in method for checking if a Call is going by passing the uuid to method isCallActive, it didn't work correctly for me so i have implement my own native module to check using the same code with promise:
RCT_EXPORT_METHOD(isCallActive:
(NSString *)uuidString
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
CXCallObserver *callObserver = [[CXCallObserver alloc] init];
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
BOOL _mybool = false;
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){
_mybool = true;
resolve(@"true");
}
}
if(!_mybool){
reject(false, false, false);
}
}
The code is working and I am able to access it like this:
NativeModules?.CallManager?.isCallActive(uuid)
.then((value) => {
console.log('isCallActive then', value);
})
.catch((error) => {
console.log('isCallActive catch', error);
});
Now the problem here is that, if I receive a call, it displays CallKit UI then in my console i see it resolves the promise quickly even though i haven't accepted call yet and its ringing in the phone. I am unable to understand why is this happening.
EDIT: How does hasConnected work? Even though i have accepted the call it always returns false? If I wait for my app to start completely behind callKit UI and then accept the call, it gives me true for hasConnected and I am assuming because the Twilio audio session is started at that point. But if i accept call early, i don't get true for hasConnected because audio session was not started. Is my understanding correct?