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

'answerCall' Listener occasionally does not run, when answering call while app is terminated/background

Open stephanoparaskeva opened this issue 4 years ago • 7 comments

'runs pickup' is never logged to console. I suspect the 'answerCall' event occurs before listener is added in some cases. How do you check if app loaded with 'answerCall' event. As opposed to detecting an event in real time?

IE If 'answerCall' has already occured, then after you add the event listener: RNCallKeep.addEventListener('answerCall', pickupCall), the function will instantly run. Or a way to check if 'answerCall' has already occurred when app starts?

Current code:

  // Picks up and accepts incoming call.
  const pickupCall = async () => {
    console.warn('runs pickup'); // <--------- Sometimes Never Runs
    setOpenCall({ recipient: {}, inCall: true, isIncomingCall: true });
    const id = oneTimeId();
    // Tell callkeep that call has begun
    RNCallKeep.setCurrentCallActive(id);

    // Relay that phone has been picked up
    // Just incase this function runs before 'onCallListener'
    // If it runs before 'sess.current' will not be the real session
    // So methods below will not do anything.
    pickedUp.current = true;

    // onRemoteStreamListener event gets registered if both phones run this function
    const stream = await sess.current?.getUserMedia?.(MEDIA_OPTIONS);
    // The function to cause the call to be connected
    await sess.current?.accept?.({});
    // Setting of localStream video and preparing the remote stream object for incoming remote stream
    setLocalStreams([{ userId: 'localStream', stream }]);
    setRemoteStreams([{ userId: sess.current.initiatorID, stream: null }]);
  };

  const callkeepListenersInit = async () => {
    console.warn('runs callkeep');
    RNCallKeep.setAvailable(true);
    RNCallKeep.addEventListener('answerCall', pickupCall);
    RNCallKeep.addEventListener('endCall', rejectCall);
  };

  // Removes all listeners when component unmounts.
  const cleanup = () => {
    RNCallKeep.removeEventListener('answerCall');
    RNCallKeep.removeEventListener('endCall');
    hangup();
  };

  // First mount hooks up all listeners.
  useEffect(() => {
    cubeListenersInit();
    callkeepListenersInit();
    return cleanup;
  }, []);

stephanoparaskeva avatar Jan 01 '21 17:01 stephanoparaskeva

May be related to this: https://github.com/react-native-webrtc/react-native-callkeep#--didloadwithevents

namnm avatar Jan 13 '21 08:01 namnm

May be related to this: https://github.com/react-native-webrtc/react-native-callkeep#--didloadwithevents

This is exactly what I was looking for, great.

There's the residual problem that when using didLoadWithEvents, the call never gets put in 'connected' state and so the user cannot hear anything. Just the dial tone. How does one move the call into connected state when using didLoadWithEvents

stephanoparaskeva avatar Jan 13 '21 14:01 stephanoparaskeva

I dont know much about your detail situation so I can not help.

About me, I handled that didLoadWithEvents as following: https://github.com/brekekesoftware/brekekephone/blob/master/src/utils/callkeep.ts#L62

namnm avatar Jan 13 '21 18:01 namnm

Someone, please help! 🙏 answerCall event is not firing in Android only. When we call displayIncomingCall and the incoming call shows on Android, and when we press the call end button, the endCall event is firing, but when we press the call-accept button, it stays there on the call screen and nothing happens. And the answerCall event is not firing.

Please help, we've tried all the solutions, nothing is working.

classiebit avatar Jun 09 '21 07:06 classiebit

Have you fixed??. I am also facing the same issue

prasanthvenkatachalam avatar Jul 30 '21 07:07 prasanthvenkatachalam

No, it didn't work, and we just removed the rn-callkeep package from Android and we created a custom solution to receive calls on Android.

We created a solution to receive calls via silent push notification and created a custom page to show incoming calls on Android.

classiebit avatar Aug 03 '21 09:08 classiebit

hi, i got this problem on IOS, not android

fukemy avatar Sep 09 '22 10:09 fukemy