Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for specifying a delegate FirebaseMessagingService #191

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ Setup FCM
You must download the file `google-services.json` from the Firebase console.
It contains keys and settings for all your applications under Firebase. This library obtains the resource `senderID` for registering for remote GCM from that file.

Then follow these step by step https://firebase.google.com/docs/android/setup

#### `android/build.gradle`

```groovy
Expand All @@ -152,6 +154,17 @@ buildscript {
apply plugin: 'com.google.gms.google-services'
```

#### `android/app/build.gradle`

```groovy
dependencies {
implementation platform('com.google.firebase:firebase-bom:26.4.0')
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-analytics'
}
```


#### `AndroidManifest.xml`

```xml
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ dependencies {
implementation 'com.twilio:voice-android:4.5.0'
implementation "com.android.support:appcompat-v7:$supportLibVersion"
implementation 'com.facebook.react:react-native:+'
implementation 'com.google.firebase:firebase-messaging:17.6.+'
implementation 'com.google.firebase:firebase-messaging:21.0.+'
testImplementation 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public class VoiceFirebaseMessagingService extends FirebaseMessagingService {

private CallNotificationManager callNotificationManager;

private FirebaseMessagingService mFirebaseServiceDelegate;

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

@Override
public void onCreate() {
super.onCreate();
Expand Down Expand Up @@ -66,7 +74,7 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Map<String, String> data = remoteMessage.getData();

final FirebaseMessagingService serviceRef = (this.mFirebaseServiceDelegate == null) ? this : this.mFirebaseServiceDelegate;
// If notification ID is not provided by the user for push notification, generate one at random
Random randomNumberGenerator = new Random(System.currentTimeMillis());
final int notificationId = randomNumberGenerator.nextInt();
Expand All @@ -82,7 +90,7 @@ public void onCallInvite(final CallInvite callInvite) {
handler.post(new Runnable() {
public void run() {
// Construct and load our normal React JS code bundle
ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
ReactInstanceManager mReactInstanceManager = ((ReactApplication)serviceRef.getApplication()).getReactNativeHost().getReactInstanceManager();
ReactContext context = mReactInstanceManager.getCurrentReactContext();
// If it's constructed, send a notification
if (context != null) {
Expand Down