twilio/twilio-voice-react-native

Incoming CallInvite is not working in Android

Opened this issue · 15 comments

Issue

Pre-submission Checklist

  • I have verified that the issue occurs with the latest release and is not marked as a known issue in the CHANGELOG.md.
  • I reviewed the Common Issues and open GitHub issues and verified that this report represents a potentially new issue.
  • I am not sharing any Personally Identifiable Information (PII)
    or sensitive account information (API keys, credentials, etc.) when reporting this issue.

Description

Currently using 'twilio-voice-react-native' SDK version '1.0.0-beta.4'. Previously, I could receive the CallInvite for incoming calls on an Android 10 device (also on Android12) with this SDK version. But now, the CallInvite emitter is no longer triggered without any code changes. However, the app is still able to receive the push notification payload for incoming calls.

Successfully able to register the access token on voice.
voice.register(accessToken)

voice.on(Voice.Event.Registered, () => {
console.log('Device registered successfully for incoming calls.')
});

LOG Device registered successfully for incoming calls.

Reproduction Steps

Expected Behavior

When receive incoming call, the callInvite emitter should be triggered automatically to accept/reject the calls.

Actual Behavior

Currently device is able to receive the push data payload but notification doesn't shows and callInvite not triggred.
When check the call logs on Twilio console it shows following errors:
Error
52103GCM/FCM client uninstalled or turned off notifications

52116Legacy FCM server key used to send notifications

52116Legacy FCM server key used to send notifications

Reproduction Frequency

Is the reproducibility of the issue deterministic? If not, what percentage of the time does the issue occur? In how many attempts was the issue observed?

Screenshots

Software and Device Information

Please complete the following information.
Device: Samsung SM-M115F
Android 10.

Additional Context

Add any other context about the problem here.

@manpreetaj we highly recommend you upgrade to use FCM v1 tokens as by June 2024, Google will be disabling FCM legacy support.

Also, what do you mean by "the callInvite emitter should be triggered automatically to accept/reject the calls"? are you receiving a firebase notification (you can test by putting a breakpoint here).

@afalls-twilio Thank you, I will attempt to upgrade to FCM v1 tokens.

Q: Also, what do you mean by "the callInvite emitter should be triggered automatically to accept/reject the calls"? are you receiving a firebase notification.

Ans: This implies that upon receiving an incoming call, the voice.on('callInvite', (callInvite) => {callInvite.accept()}) listener must be invoked, as it was previously. This allows for the action of accepting or rejecting the incoming call to be performed. Currently, the app is capable of receiving the 'remoteMessage' payload for incoming calls within the following 'react-native-firebase' class.

 import messaging from '@react-native-firebase/messaging';

 messaging().onMessage(async remoteMessage => {
    console.log('Message received!', remoteMessage);
  });

However, the class VoiceFirebaseMessagingService.java is unable to retrieve the remoteMessage.

 @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
    logger.debug("onMessageReceived remoteMessage: " + remoteMessage.toString());
   }

@manpreetaj I'm guessing you are running two firebase services, one via the @react-native-firebase/messaging module and one internal to our SDK?

Ahh, so you are not receiving a message in VoiceFirebaseMessagingService.java? can you make sure that both Firebase services (NodeJS and VoiceFirebaseMessagingService.java) are receiving the same firebase token?

Also, what happens when you delete your app entirely, then re-install it to force it to create a new FCM token for both sercices?

I have also got the same issue @afalls-twilio. Can you suggest what solution worked for you @manpreetaj ?

@manish-shrivastava The following solutions have worked for me:

  1. Upgrade to use FCM v1 tokens as by June 2024, Google will be disabling FCM legacy support. Click here for more information.

  2. Specify the service and receiver in the app's manifest file.

<service
           android:name="com.twiliovoicereactnative.VoiceFirebaseMessagingService"
           android:stopWithTask="false"
           android:exported="true">
           <intent-filter>
               <action android:name="com.google.firebase.MESSAGING_EVENT" />
           </intent-filter>
       </service>

       <receiver
           android:name="com.twiliovoicereactnative.VoiceNotificationReceiver"
           android:exported="false">
           <intent-filter>
               <action android:name="ACTION_INCOMING_CALL" />
               <action android:name="ACTION_ACCEPT_CALL" />
               <action android:name="ACTION_REJECT_CALL" />
               <action android:name="ACTION_CANCEL_CALL" />
               <action android:name="ACTION_CALL_DISCONNECT" />
               <action android:name="ACTION_RAISE_OUTGOING_CALL_NOTIFICATION" />
               <action android:name="ACTION_CANCEL_NOTIFICATION" />
               <action android:name="ACTION_FOREGROUND_AND_DEPRIORITIZE_INCOMING_CALL_NOTIFICATION" />
               <action android:name="ACTION_FOREGROUND_APPLICATION" />
           </intent-filter>
   </receiver>

Hi all, thanks for the vibrant community discussion and problem solving. We're currently working on improving our docs and will be including this feedback in our revisions. Please stay tuned for that! I'll keep this issue pinned and open for now, and close it out when we release those documentation changes.

@manpreetaj what version are you using?

The reason I ask is because..

  1. We no longer have a receiver, it has been migrated to a separate service
  2. The manifest merging stage of your build should merge the correct manifest settings from the .aar package for our sdk (it has a manifest inside of it).

@afalls-twilio
Currently, I'm using @twilio/voice-react-native-sdk": "^1.0.0" and I noticed it has a separate service.

Thanks for the update.

Hi @manpreetaj are you still having issues regarding Android integration? Just to confirm, you were able to use the SDK-provided proxy classes in your MainApplication and MainService files?

culov commented

Hi @mhuynh5757, I'm currently experiencing this same issue, where I receive the FCM notification, but I never receive the callInvite event. After the notification is received, I even check to see for active call invites every few seconds, and there are never any call invites:

  checkForActiveCall = async () => {
      const voice = VoiceManager.getInstance();
      const callInvites = await voice.getCallInvites();
      if (callInvites && callInvites.size > 0) {
        let mostRecentInvite = Array.from(callInvites.values()).pop();;
          if (mostRecentInvite) {
              mostRecentInvite.accept()
              .then(incomingCall => {
....

Incoming calls are already working correctly using essentially the same code, on iOS.

I'm just fetching the token, and doing

        this.voice.register(token)
          .then(() => {
            console.log('Twilio Voice registered successfully');
            self.initTwilioVoice();  // Initialize Twilio Voice
          })
          .catch(error => {
            console.error("Error registering Twilio Voice: ", error);
          });

         this.voice.on(Voice.Event.CallInvite, this.handleCallInvite.bind(this));

And handleCallInvite is never called on android.

Here's what the FCM notification I am correctly receiving when an incoming call invite should be coming in:


'Notification received:', { foreground: true,
08-29 22:31:11.465 11170 11352 I ReactNativeJS:   finish: [Function: finish],
08-29 22:31:11.465 11170 11352 I ReactNativeJS:   userInteraction: false,
08-29 22:31:11.465 11170 11352 I ReactNativeJS:   id: 'CCCCCCCCC',
08-29 22:31:11.465 11170 11352 I ReactNativeJS:   data: 
08-29 22:31:11.465 11170 11352 I ReactNativeJS:    { twi_account_sid: 'ACCCCCCCC',
08-29 22:31:11.465 11170 11352 I ReactNativeJS:      twi_params: 'parentCallSid=XXXXXXz',
08-29 22:31:11.465 11170 11352 I ReactNativeJS:      twi_to: 'client:XXXXXX:3',
08-29 22:31:11.465 11170 11352 I ReactNativeJS:      twi_answer_timeout: '600',
08-29 22:31:11.465 11170 11352 I ReactNativeJS:      twi_bridge_token: 'XXXXX',
08-29 22:31:11.465 11170 11352 I ReactNativeJS:      twi_message_type: 'twilio.voice.call',
08-29 22:31:11.465 11170 11352 I ReactNativeJS:      twi_call_sid: 'CAXXXXXX,
08-29 22:31:11.465 11170 11352 I ReactNativeJS:      twi_message_id: 'RUXXXXXX',
08-29 22:31:11.465 11170 11352 I ReactNativeJS:      twi_from: '+CCCCCCCC',
08-29 22:31:11.465 11170 11352 I ReactNativeJS:      twi_stir_status: 'TN-Validation-Passed-C' } }
08-29 22:31:13.486 11170 11352 I ReactNativeJS: Checking for active call
08-29 22:31:13.506 11170 11352 I ReactNativeJS: 'Call invites:', {}

Any idea what's going on? I'm on the latest release, 1.1.1

Hi @culov are you using @react-native-firebase/messaging in your application, or some other package that also declares a Firebase listener?

culov commented

@mhuynh5757 I'm using @react-native-firebase/app, but not @react-native-firebase/messaging. I had push notifications working already from other parts of my app. I've been trying to follow the sample project closely, and noticed it isn't using @react-native-firebase/messaging either.

Should I add that package and try again? Or is there other work I should be doing with firebase that I'm perhaps missing?

culov commented

Hi @mhuynh5757 , just checking to see if there's any update on this. I'm at a loss of what else to try, I simply never receive the CallInvite on Android despite everything working on iOS, and having closely followed the Android instructions and sample project structure.

Hi @culov, apologies for the delays. We had some urgent items we needed to prioritize. The issue is rather complicated, we're trying to investigate a solution. See this thread for more details: #370

culov commented

Hi @mhuynh5757 , thanks for the link to that issue.

It does seem complicated. Just so I'm clear - as of now with this package on android, you can EITHER accept incoming calls OR receive remote push notifications - but you can't do both?

I haven't been able to get either of the proposed solution here #370 (comment) to work. Is there any workaround, like downgrading the package to a specific version?