Closed periabyte closed 6 months ago
@periabyte 2 things..
1) the error you are having is because your build is not associating com.twilio.voice as a dependency to your custom firebase module. com.twilio.voice.MessageListener
is part of the Twilio Voice SDK that the RN sdk has as a dependency.
2) We internally ran some tests and discovered that you don't need to extend our VoiceFirebaseMessagingService, infact, you can have two FirebaseMessaging services, the SDK internal one (VoiceFirebaseMessagingService) and your custom one and if they use the same token, they will BOTH receive the same push messages.
This helped me
the error you are having is because your build is not associating com.twilio.voice as a dependency to your custom firebase module. com.twilio.voice.MessageListener is part of the Twilio Voice SDK that the RN sdk has as a dependency.
I manually added the Twilio Voice SDK in my android/app/build.gradle
file
dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
implementation("com.twilio:voice-android:6.3.3")
and then updated the final
package com.rnexpotwilio.app;
import com.google.firebase.messaging.FirebaseMessagingService;
import expo.modules.notifications.service.ExpoFirebaseMessagingService;
import expo.modules.notifications.service.interfaces.FirebaseMessagingDelegate;
import com.twiliovoicereactnative.VoiceFirebaseMessagingService;
// import com.rnexpotwilio.app.TwilioConstants;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.PowerManager;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.google.firebase.messaging.RemoteMessage;
// import java.util.ArrayList;
// import java.util.List;
// import System
import android.util.Log;
import java.util.*;
import com.google.firebase.messaging.RemoteMessage;
public class RnExpoTwilioNotificationService extends VoiceFirebaseMessagingService {
private FirebaseMessagingService expoFirebaseService = new ExpoFirebaseMessagingService();
protected open val firebaseMessagingDelegate: FirebaseMessagingDelegate by lazy {
expo.modules.notifications.service.delegates.FirebaseMessagingDelegate(this)
}
public static final String TAG = "RETNotificationService";
public RnExpoTwilioNotificationService() {
super();
}
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "onCreate");
}
@Override
public void onNewToken(String token) {
Log.d(TAG, "Refreshed FCM token: " + token);
}
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (!remoteMessage.getData().containsKey("twi_message_type")) {
Log.d(TAG, "Expo Sending Message");
firebaseMessagingDelegate.onMessageReceived(remoteMessage);
Log.d(TAG, "Expo Sent Message");
return;
}
Log.d(TAG, "onMessageReceived");
Log.d(TAG, remoteMessage.getData().toString());
Log.d(TAG, "contains twilio data:");
super.onMessageReceived(remoteMessage);
}
}
We internally ran some tests and discovered that you don't need to extend our VoiceFirebaseMessagingService, infact, you can have two FirebaseMessaging services, the SDK internal one (VoiceFirebaseMessagingService) and your custom one and if they use the same token, they will BOTH receive the same push messages.
Yes, they will both receive the same push message internally, but somehow when adding the VoiceFirebaseMessagingService
it somehow blocks the other service (in this case the ExpoFirebaseMessagingService
) from handling the push message. That's why I needed to create a custom service to send the push message to the proper service to handle that push message. I'm sure there's a better way to implement what I currently have, but for now it works.
Issue
Pre-submission Checklist
Description
My current setup was working with
.beta-2
. I created a Notification Service to handle expo notifications and Twilio notifications as I did in #160I disabled the Custom Notification Service.
I made the changes that were stated in the
.beta-4
migration guide. Mixed it with the default Expo Kotlin files.Incoming calls are working properly with this setup.
But other notifications are not coming through
I re-enabled the Custom Notification Service. The app won't compile now.
Here are the files that I modified for Expo and Twilio React Native
Expected Behavior
The app should compile properly
Actual Behavior
Reproduction Frequency
100%