react-native-webrtc / react-native-callkeep

iOS CallKit framework and Android ConnectionService for React Native
ISC License
884 stars 431 forks source link

Incoming call expiration #433

Open aevaldas opened 3 years ago

aevaldas commented 3 years ago

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

namnm commented 3 years ago

@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

nornewman commented 2 years ago

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.

newme616 commented 1 year ago

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

Thank you for the code though

nornewman commented 1 year ago

@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.

newme616 commented 1 year ago

@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.

nornewman commented 1 year ago

@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

newme616 commented 1 year ago

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

newme616 commented 1 year ago

@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!

frozencap commented 1 year ago

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