react-native-webrtc / react-native-callkeep

iOS CallKit framework and Android ConnectionService for React Native
ISC License
922 stars 444 forks source link

How to simulate missed call when caller cancels a call? #383

Open jatins52 opened 3 years ago

jatins52 commented 3 years ago

This is not a bug but I did not know where to post my question?

I have used agora.io for call and firebase for voip push notifications. react-native-callkeep : for showing incoming call when voip push notification is arrived. Web RTC : agora.io Firebase Firestore: for realtime database

my calls are successful when user accepts incoming call on IOS and android. But when a user calls other user and it shown incoming call on IOS or Android and then caller cancels the call, how do I disconnect ?

Approach I tried is to create Firebase collection listener inside "RNCallKeep.addEventListener('didDisplayIncomingCall', (data) => {}" (I am using firebase database), but the issue is that it works for first time then for next calls the old listener works and does not get destroyed.

Any ideas are welcome.

My code sample for firestore document subscription when incoming call is displayed:

// RNCallKeep.addEventListener('didDisplayIncomingCall', (data) => { // console.log('didDisplayIncomingCall', data); // #TODO: search for ways to handle this case for missed calls // callDataSubscription = currentCallRef.onSnapshot({ // error: (error => { // console.log(error); // }), // next: (snap) => { // const callData = snap.data(); // console.log('callData', callData) // if (callData.cancelled === true || callData.missed === true || callData.disconnected === true) { // RNCallKeep.endCall(data.callUUID); // return; // } // } // }); // setTimeout(() => { // if (typeof callDataSubscription === 'function') { // callDataSubscription() // callDataSubscription = null; // } // // currentCallRef = null; // }, 5000); // });

Commented code is where I am ending call depending on what data is gets. When caller cancels the call before callee accepts it the document will save "missed" and "disconnected" true.

Thank you in advance

Romick2005 commented 3 years ago

I've sold this problem by sending http end request directly from objective c app native part. Take a look at my fork here Code usage sample here

Romick2005 commented 3 years ago

Nope. I used this exactly to end a call on callee to to notify caller about call rejection.

jatins52 commented 3 years ago

@Romick2005 Thank you for answering. You did this action when user answers the call if I am getting it right. My concern is when the caller cancels the call I need to perform endCall at receiver end. For this I created a firestore listener when incoming call is displayed, when call canceled is set true (it will be written in firestore document when caller cancels the call) I need to perform endCall at receiver end also. This works for first time but the firebase listener is not destroyed and when the call is made again from any user it reads cancelled true and performs endCall for all further incoming calls.

jatins52 commented 3 years ago

Nope. I used this exactly to end a call on callee to to notify caller about call rejection.

Ohk If receiver rejects the call I can notify caller using real-time Firestone document value change. This works when caller calls and cancels but I am unable to destroy listener. callDataSubscription

thank you