react-native-callkeep icon indicating copy to clipboard operation
react-native-callkeep copied to clipboard

[iOS 13] callKit displayed from AppDelegate.m before incoming call listeners

Open ahmadworks opened this issue 7 years ago • 22 comments

After updating to 3.0.3 and updating my code to meet iOS 13 requirements so CallKit is reported from AppDelegate. But the problem is that when app is closed or in background, the callKit displays very fast before my call class get loaded. So the callKit is shown on screen before listeners are ready and if I accept or reject the call immediately nothing happened. I need to wait for 3 seconds until call listeners are ready then I can accept or reject.

How can I delay the callKit in AppDelegate until my call class is fully loaded?

ahmadworks avatar Sep 26 '19 03:09 ahmadworks

Hi @ahmadworks. It's the normal behaviour since in ios 13 we should report all calls coming from a VoIP push. Please refer to the doc about it and the corresponding PR.

manuquentin avatar Sep 26 '19 12:09 manuquentin

I don't think this should be the normal behaviour even after iOS 13, I can report to call but the call should appear on screen only after the app knows how to deal with the call. in current case what should happen if user quickly tapped answer before the app knows how it should handle the answer and reject.

ahmadworks avatar Sep 26 '19 12:09 ahmadworks

@ahmadworks this is needed for ios13 so we need to think collectively about how to work around that issue. I think from my perspective we need the native side to know that the JS bridge isn't up yet and so wait until it is and then emit the event of "yes someone accepted the call"

danjenkins avatar Sep 30 '19 19:09 danjenkins

@danjenkins also to emit UUID data of active CallKit call (for example, to update the incoming call display). Because RN doesn't know the current UUID call after the bridge is up. didDisplayIncomingCall not called (error "Sending 'RNCallKeepDidDisplayIncomingCall' with no listeners registered.)

Prussich avatar Oct 01 '19 21:10 Prussich

@Prussich you have to listen to the events at the very beginning of the loading of your app (eg. in the index.ios.js). You'll next have to wait for you WebRTC call to be set up before really answer it.

manuquentin avatar Oct 01 '19 23:10 manuquentin

Is it possible to implement dnd mode with RNCallKeep in AppDelegate.m? how can I use rejectCall if receive voip push?

bmp123 avatar Oct 02 '19 09:10 bmp123

@bmp123 please create a new issue for that :)

danjenkins avatar Oct 02 '19 10:10 danjenkins

@manuquentin As I see it:

  1. App wake up after receive VoIP-Push.
  2. App calling reportNewIncomingCall from VoIP-push delegate (as quickly, as Apple asks)
...
NSString *uuid = [[[NSUUID UUID] UUIDString] lowercaseString];
...
[RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:false localizedCallerName:callerName fromPushKit: YES];

RN bridge still not live. And there are no CallKeep listeners yet. 3) RN bridge is started. The RN part with CallKeep listeners starts up.

But, RNCallKeepDidDisplayIncomingCall was not called and RNCallKeep doesn't know which uuid was used in reportNewIncomingCall:uuid in native part.

Please correct me if everything is wrong and you can know in the RN part which UUID of the incoming call was used before in the native part of the application.

Prussich avatar Oct 02 '19 13:10 Prussich

@manuquentin I also try to listen to the events at the very beginning of the loading of my app:

At the top of index.ios.js:

const onAnswerCallAction = ({callUUID}) => {
    RNFS.writeFile(path, '\n[' + moment().locale('en').format('YYYY-MM-DD HH:mm:ss') + ']: ' + '[index]: onAnswerCallAction from App start\n', 'utf8');
};

const onIncomingCallDisplayed = ({error, callUUID, handle, localizedCallerName, fromPushKit}) => {
    RNFS.writeFile(path, '\n[' + moment().locale('en').format('YYYY-MM-DD HH:mm:ss') + ']: ' + '[index]: onIncomingCallDisplayed from App start:' + callUUID + '\n', 'utf8');
};

RNCallKeep.setup(options);
RNCallKeep.addEventListener('answerCall', onAnswerCallAction);
RNCallKeep.addEventListener('didDisplayIncomingCall', onIncomingCallDisplayed);

and I don't see any event records in log file about "onIncomingCallDisplayed". In the native part, sending the onIncomingCallDisplayed event fires earlier than there is a subscription to the event in JS. Any ideas how to fix this?

Prussich avatar Oct 04 '19 13:10 Prussich

@Prussich there is a timeout to work around this issue here. The app will wait 5s in release and 10s in debug before sending the event.

Here the event triggered too soon event with this workaround ?

manuquentin avatar Oct 04 '19 13:10 manuquentin

Good idea! But it work around for the outgoing call (RNCallKeepDidReceiveStartCallAction event). I 'll try to make the same implementation with the timeout for incoming calls for the RNCallKeepDidDisplayIncomingCall event in RNCallKeep.m.

Prussich avatar Oct 04 '19 14:10 Prussich

Hello, please do share if anyone got a solution for this. Thanks!

pravinjohn avatar Oct 24 '19 23:10 pravinjohn

Would it not be possible create a method AnswerCall(UUID) which calls [action fulfill]; currently called within performAnswerCallAction, this way the app should show connecting until your app has managed to reconnect and retrieve the call and actually answer the call. I am not that familiar with native iOS code otherwise I would attempt to see if the concept is possible.

danwhite-ipc avatar Dec 11 '19 15:12 danwhite-ipc

For anyone interested - please check my proof of concept to solve this issue https://github.com/softwarehutpl/react-native-callkeep/commit/b7df3b4863f1bcefd8fd89fcdaf7bcd10dff207e

The idea is to gather events which should be sent through JS bridge if it isn't ready. Once JS part is ready then send didLoadWithEvents with all gathered events. Next, on JS part, events needs to be handled depending of the project needs. For example, you may be interested in checking of only last "end call" action but it's worth having "did display call" action as well in order to get all push/call-related data.

Disclaimer:

  1. It wasn't fully tested yet.
  2. It may not be necessary to wrap all events.
  3. It may require some examples in README of how to use didLoadWithEvents event.

konradkierus avatar Feb 04 '20 10:02 konradkierus

Thanks @konradkierus, Can you make a PR with these changes ? I'll be happy to test the,.

manuquentin avatar Mar 10 '20 18:03 manuquentin

@manuquentin sure, please check #169

konradkierus avatar Mar 12 '20 20:03 konradkierus

I see sometimes the JS Bridge doesn't start after receive a VoIP PN. It receives the VoIP PN, I report the new incoming call but the app never starts. It seems the JS Bridge thread is paused until you take some action on the CallKit screen.

Even if I wait for a long time, I don't see the app starting.

CallKeep: 3.0.9 RN: 0.59.10 iOS: 13.3.1

Does anyone have this issue too?

mariouzae avatar Mar 27 '20 15:03 mariouzae

@mariouzae

You can try NOT calling completion() first. If you marked completion() and you've see your js bridge worked, then you might encounter the similar issue.

https://github.com/react-native-webrtc/react-native-voip-push-notification/pull/52

This PR is a try which aims to solve calling completion() too early to stop JS initialization issue

zxcpoiu avatar Mar 28 '20 08:03 zxcpoiu

Should be fixed in #205

manuquentin avatar Jun 04 '20 15:06 manuquentin

A lot of work has gone into this now.... closing and if people still have large issues... then they should re-open a new issue

danjenkins avatar Jun 09 '20 08:06 danjenkins