react-native-twilio-programmable-voice icon indicating copy to clipboard operation
react-native-twilio-programmable-voice copied to clipboard

Add support for specifying a delegate FirebaseMessagingService

Open vuletuanbt opened this issue 4 years ago • 11 comments

We're using multiple push providers and thus need to use a delegate service for handling our notifications.

This PR adds the ability to specify a delegate service during instantiation as this library will otherwise throw an NPE when attempting to invoke getReactNativeHost() when handling a remote message.

vuletuanbt avatar Mar 12 '21 06:03 vuletuanbt

@fabriziomoscon, please help us to review this PR

vuletuan avatar Mar 15 '21 10:03 vuletuan

Thank you for this PR @vuletuan I will also notify @fabriziomoscon about this one

jdegger avatar Mar 15 '21 10:03 jdegger

@vuletuan which FIrebase library version is your app using? This library use 17.6.+

When testing this I received a crash for an incoming call:

java.lang.RuntimeException: Unable to instantiate service com.hoxfon.react.RNTwilioVoice.fcm.VoiceFirebaseMessagingService: java.lang.InstantiationException: java.lang.Class<com.hoxfon.react.RNTwilioVoice.fcm.VoiceFirebaseMessagingService> has no zero argument constructor
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:4057)
        at android.app.ActivityThread.access$1800(ActivityThread.java:231)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1968)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

I guess that in this PR you should also update the build.gradle file and the README.md

https://firebase.google.com/support/release-notes/android#messaging_v21-0-1

fabriziomoscon avatar Mar 22 '21 08:03 fabriziomoscon

@vuletuan which FIrebase library version is your app using? This library use 17.6.+

When testing this I received a crash for an incoming call:

java.lang.RuntimeException: Unable to instantiate service com.hoxfon.react.RNTwilioVoice.fcm.VoiceFirebaseMessagingService: java.lang.InstantiationException: java.lang.Class<com.hoxfon.react.RNTwilioVoice.fcm.VoiceFirebaseMessagingService> has no zero argument constructor
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:4057)
        at android.app.ActivityThread.access$1800(ActivityThread.java:231)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1968)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

I guess that in this PR you should also update the build.gradle file and the README.md

https://firebase.google.com/support/release-notes/android#messaging_v21-0-1

I'm sorry for my missing. I will update build.gradle and README.md

vuletuan avatar Mar 22 '21 10:03 vuletuan

Thanks @vuletuanbt you need to change this line: https://github.com/hoxfon/react-native-twilio-programmable-voice/blob/master/android/build.gradle#L61

fabriziomoscon avatar Mar 22 '21 11:03 fabriziomoscon

@fabriziomoscon I'm using firebase-bom(26.4.0) to install firebase-messaging. I guess my firebase-messaging version could be 21.0.1

vuletuan avatar Mar 22 '21 11:03 vuletuan

Thanks @vuletuanbt you need to change this line: https://github.com/hoxfon/react-native-twilio-programmable-voice/blob/master/android/build.gradle#L61

I did it.

vuletuan avatar Mar 22 '21 11:03 vuletuan

@vuletuan I followed your instruction and update my app build.gradle with:

    implementation platform('com.google.firebase:firebase-bom:26.7.0')
    implementation 'com.google.firebase:firebase-messaging'

And upon receiving a call the app crashes with:

java.lang.RuntimeException: Unable to instantiate service com.hoxfon.react.RNTwilioVoice.fcm.VoiceFirebaseMessagingService: java.lang.InstantiationException: java.lang.Class<com.hoxfon.react.RNTwilioVoice.fcm.VoiceFirebaseMessagingService> has no zero argument constructor

By reading this https://firebase.google.com/docs/android/learn-more I can see that using the BoM is a major change in the way Firebase dependencies are handled. So I would ask you that you would submit a PR to migrate Firebase to the latest version (before this PR), so we can test that properly and see that calls in all scenarios can be received.

fabriziomoscon avatar Mar 22 '21 13:03 fabriziomoscon

@vuletuan I followed your instruction and update my app build.gradle with:


    implementation platform('com.google.firebase:firebase-bom:26.7.0')

    implementation 'com.google.firebase:firebase-messaging'

And upon receiving a call the app crashes with:


java.lang.RuntimeException: Unable to instantiate service com.hoxfon.react.RNTwilioVoice.fcm.VoiceFirebaseMessagingService: java.lang.InstantiationException: java.lang.Class<com.hoxfon.react.RNTwilioVoice.fcm.VoiceFirebaseMessagingService> has no zero argument constructor

By reading this https://firebase.google.com/docs/android/learn-more I can see that using the BoM is a major change in the way Firebase dependencies are handled. So I would ask you that you would submit a PR to migrate Firebase to the latest version (before this PR), so we can test that properly and see that calls in all scenarios can be received.

It' ok. I will to help you migrate firebase to lastest version. But first, could you try firebase-bom 26.4.0. Just make sure the problem is about firebase-bom version

vuletuan avatar Mar 22 '21 15:03 vuletuan

@vuletuan by reading the error message I attempted to add an empty () cosntructor:

    public VoiceFirebaseMessagingService() {}
    public VoiceFirebaseMessagingService(FirebaseMessagingService delegate) {
        super();
        this.mFirebaseServiceDelegate = delegate;
        callNotificationManager = new CallNotificationManager();
    }

and now I can receive calls with both firebase-bom: com.google.firebase:firebase-bom:26.7.0 and com.google.firebase:firebase-bom:26.4.0

fabriziomoscon avatar Mar 22 '21 17:03 fabriziomoscon

@fabriziomoscon I did not run into it. I will add it to my PR. What about the others?

vuletuan avatar Mar 25 '21 11:03 vuletuan