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

Incoming call expiration

Open aevaldas opened this issue 3 years ago • 9 comments

Hi, how do you handle incoming call expiration (hide the incoming call screen after a certain timeout)?

aevaldas avatar Jun 07 '21 14:06 aevaldas

@aevaldas You can put a timeout/interval to check if the call is expired, then use endCall(uuid) or endAllCalls() I suggest to use https://www.npmjs.com/package/react-native-background-timer for timeout/interval

namnm avatar Jun 24 '21 09:06 namnm

There's a solution, which is done on front end part. First of all, run

npm i react-native-background-timer

This will help you run scheduled tasks when the app is closed.

Then, you will need to add the listener:

RNCallKeep.addEventListener("didDisplayIncomingCall", onIncomingCallDisplayed);

Which is fired when call is displayed.

And then implement it like this:

  const onIncomingCallDisplayed = ({callUUID, handle, fromPushKit, payload,}) => {
        BackgroundTimer.setTimeout(() => {
            RNCallKeep.endAllCalls();
        }, 120000);
    };

Where 120000 is time in milliseconds when you want to end the call. You could also add a backend request to notify your server that the call is rejected.

nornewman avatar May 04 '22 10:05 nornewman

@nornewman this sounds like a good idea, but if the app is closed it won't work right?

Thank you for the code though

newme616 avatar Jul 18 '22 14:07 newme616

@newme616 hmm, that actually depends on what BackgroundTimer library offers, but another solution we've come up is that the timer is handled on backend side, and once time's up, the backend sends the firebase notification to frontend, which then handles the logic. Both should work, but the second one is more reliable, I think.

nornewman avatar Jul 18 '22 14:07 nornewman

@nornewman thanks for the quick reply. Did you also find a solution if the Caller ends call before Callee accepts/picks the call. We tried to send another push and listen for that, but the problem is, this only works if the app is loaded. I guess we have to do it from the app delegate side.

newme616 avatar Jul 18 '22 14:07 newme616

@newme616 Actually there is a solution, it works for both iOS and Android, while app is in background. Use this in index.js file image

You should duplicate the code for both messaging().setBackgroundMessageHandler and messaging().onMessage

nornewman avatar Jul 18 '22 14:07 nornewman

@nornewman thank you so much. I'll try that out.

newme616 avatar Jul 18 '22 14:07 newme616

@nornewman Does the messaging package from rn firebase also work if I use One Signal?

And I thought that messagin().setBackGroundMessageHandler only works for Android?

One Signal unfortunately only has a foreground handler, not a background handler for notifications?

thank you in advance!

newme616 avatar Jul 19 '22 10:07 newme616

And then implement it like this:

   const onIncomingCallDisplayed = ({callUUID, handle, fromPushKit, payload,}) => {
       BackgroundTimer.setTimeout(() => {
           RNCallKeep.endAllCalls();
       }, 120000);
   };

without forgetting to keep track of that timer to cancel it if the user picks up the call

frozencap avatar Sep 13 '22 15:09 frozencap