Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit ec6a7e7

Browse files
author
Denny Beulen
committed
finished receiving dynamiclinks on android
1 parent 18507de commit ec6a7e7

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

firebase-common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ firebase.storage = null;
7272
firebase.firebaseRemoteConfig = null;
7373
firebase.authStateListeners = [];
7474
firebase._receivedNotificationCallback = null;
75+
firebase._DynamicLinkCallback = null;
7576

7677
firebase.addAuthStateListener = function(listener) {
7778
if (firebase.authStateListeners.indexOf(listener) === -1) {

firebase.android.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ firebase.init = function (arg) {
237237
firebase.addOnPushTokenReceivedCallback(arg.onPushTokenReceivedCallback);
238238
}
239239
}
240+
241+
// Firebase DynamicLink
242+
if (arg.onDynamicLinkCallback !== undefined){
243+
firebase.addOnDynamicLinkReceivedCallback(arg.onDynamicLinkCallback);
244+
}
240245

241246
// Firebase storage
242247
if (arg.storageBucket) {
@@ -2098,7 +2103,25 @@ firebase.invites.getInvitation = function () {
20982103
});
20992104
};
21002105

2101-
//Dynamic links make sure invitations are enabled in the gradle file (it uses the same api)
2106+
2107+
firebase.addOnDynamicLinkReceivedCallback = function (callback) {
2108+
return new Promise(function (resolve, reject) {
2109+
try {
2110+
if (typeof(com.google.android.gms.appinvite) === "undefined") {
2111+
reject("Uncomment invites in the plugin's include.gradle first");
2112+
return;
2113+
}
2114+
2115+
firebase._DynamicLinkCallback = callback;
2116+
resolve();
2117+
} catch (ex) {
2118+
console.log("Error in firebase.addOnDynamicLinkReceivedCallback: " + ex);
2119+
reject(ex);
2120+
}
2121+
});
2122+
};
2123+
2124+
21022125
(function() {
21032126
appModule.on("launch", function(args) {
21042127
var intent = args.android;
@@ -2107,10 +2130,17 @@ firebase.invites.getInvitation = function () {
21072130
onComplete: function(task) {
21082131

21092132
if (task.isSuccessful() && task.getResult() != null) {
2110-
result = firebase.toJsObject(task.getResult());
2111-
console.log("launched by dynamic link:"+ result);
2112-
} else {
2113-
console.log("Not launched by dynamic link");
2133+
result = task.getResult().getLink();
2134+
result = firebase.toJsObject(result);
2135+
if(firebase._DynamicLinkCallback === null){
2136+
console.log("No callback is provided for a dynamic link");
2137+
}
2138+
else{
2139+
setTimeout(function() {
2140+
firebase._DynamicLinkCallback(result);
2141+
});
2142+
}
2143+
21142144
}
21152145
}
21162146
});
@@ -2121,5 +2151,4 @@ firebase.invites.getInvitation = function () {
21212151
});
21222152
})()
21232153

2124-
21252154
module.exports = firebase;

firebase.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ export interface InitOptions {
105105
* For FCM either pass in this callback function here, or use addOnPushTokenReceivedCallback
106106
*/
107107
onMessageReceivedCallback?: (data: Message) => void;
108+
109+
/**
110+
* Get notified when the dynamic link is changed.
111+
*/
112+
onDynamicLinkCallback?: (data: DynamicLink) => void;
108113
}
109114

110115
export interface QueryRangeOption {
@@ -743,6 +748,17 @@ export module invites {
743748
function getInvitation(): Promise<GetInvitationResult>;
744749
}
745750

751+
// Dynamic Link
752+
753+
export interface DynamicLink {
754+
cachedFsi: number;
755+
cachedSsi: number;
756+
scheme: string;
757+
uriString: string;
758+
host: string;
759+
port: number;
760+
}
761+
746762

747763
// Auth
748764
export function login(options: LoginOptions): Promise<User>;

platforms/android/include.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dependencies {
4646
// Uncomment if you need Google Sign-In Authentication
4747
// compile "com.google.android.gms:play-services-auth:$googlePlayServicesVersion"
4848

49-
// Uncomment if you want to use 'Invites'
49+
// Uncomment if you want to use 'Invites or Dynamic Links'
5050
// compile 'com.google.firebase:firebase-invites:10.2.+'
5151

5252
}

scripts/installer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function promptQuestions() {
157157
default: 'n'
158158
}, {
159159
name: 'invites',
160-
description: 'Are you using Firebase Invites (y/n)',
160+
description: 'Are you using Firebase Invites or Firebase Dynamic Links (y/n)',
161161
default: 'n'
162162
}], function (err, result) {
163163
if (err) {
@@ -234,7 +234,7 @@ pod 'Firebase/Auth'
234234
# Uncomment if you want to enable AdMob
235235
` + (isSelected(result.admob) ? `` : `#`) + `pod 'Firebase/AdMob'
236236
237-
# Uncomment if you want to enable Invites
237+
# Uncomment if you want to enable Invites or Dynamic Links
238238
` + (isSelected(result.invites) ? `` : `#`) + `pod 'Firebase/Invites'
239239
240240
# Uncomment if you want to enable Facebook Authentication

0 commit comments

Comments
 (0)