react-native-webrtc / react-native-callkit

#deprecated iOS 10 new CallKit framework for React Native
ISC License
122 stars 67 forks source link

CallKit actions not always getting executed. #64

Open henrikbjorn opened 5 years ago

henrikbjorn commented 5 years ago

Hey, thanks for the package.

I am seeing a couple of different issues while using the library.

glocore commented 5 years ago

@henrikbjorn were you able to figure this out? Are you using the react-native-pjsip library? I'm working on a SIP calling app that uses that library.

henrikbjorn commented 5 years ago

Yeah we are using react-native-pjsip. We have cloned both packages and can be found at github.com/firmafon It contains some improvements that we found.

One of the things we found was that answering a call through CallKit needs to wait for didActivateAudioSession before actually answering the pjsip call. Otherwise it might fail to get control of the sound device.

henrikbjorn commented 5 years ago

We also found that this was important https://github.com/ianlin/react-native-callkit/pull/66

On the first run from xcode it would work correctly, but on every subsequent reload of the device (via the debug menu) Callkit would be confused. This fixes this problem

henrikbjorn commented 5 years ago

Also out react-native-pjsip fork uses promises instead of the callbacks. This makes it easier to handle for us. Since we use redux-saga and therefor want to wait on a promise until it is resolved.

glocore commented 5 years ago

@henrikbjorn thank you sir!

henrikbjorn commented 5 years ago

Another observation. When you are entering background you need to delete accounts which takes time. So you need to extend the background processing time by doing something like this:

- (void)applicationWillEnterForeground:(UIApplication *)application {
  [self endBackgroundTask];
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
  // Create a background task and deregister the pjsip registrations
  [self extendBackgroundRunningTime];
}

- (void)endBackgroundTask {
  if (self.backgroundUpdateTask != UIBackgroundTaskInvalid) {
    [[UIApplication sharedApplication] endBackgroundTask:self.backgroundUpdateTask];

    self.backgroundUpdateTask = UIBackgroundTaskInvalid;
  }
}

- (void)extendBackgroundRunningTime {
  if (self.backgroundUpdateTask != UIBackgroundTaskInvalid) {
    return;
  }

  self.backgroundUpdateTask = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"Unregistrations" expirationHandler:^{
    [self endBackgroundTask];
  }];

  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    [NSThread sleepForTimeInterval:5.0f];

    [[UIApplication sharedApplication] endBackgroundTask:self.backgroundUpdateTask];

    self.backgroundUpdateTask = UIBackgroundTaskInvalid;
  });
}
henrikbjorn commented 5 years ago

When you receive a push notification from push kit, the app will not change state from background. So you need to register/create an account when that happens, if the user tries to answer the call via callkit.

LFSCamargo commented 5 years ago

Here its not working also sometimes the endAllCalls function works but sometimes not

henrikbjorn commented 5 years ago

@LFSCamargo https://github.com/ianlin/react-native-callkit/pull/66 this one is important if you are reloading your app in development mode. Without this CallKit will be confused and nothing works correctly.