react-native-callkeep
react-native-callkeep copied to clipboard
Incoming call expiration
Hi, how do you handle incoming call expiration (hide the incoming call screen after a certain timeout)?
@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
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 this sounds like a good idea, but if the app is closed it won't work right?
Thank you for the code though
@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 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
Actually there is a solution, it works for both iOS and Android, while app is in background.
Use this in index.js file
You should duplicate the code for both messaging().setBackgroundMessageHandler and messaging().onMessage
@nornewman thank you so much. I'll try that out.
@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!
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