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

Commit ceb4ea5

Browse files
Merge pull request #447 from dbeulen/master
Added functionality: Receive Firebase Dynamic links
2 parents 68592fa + b1a0c45 commit ceb4ea5

File tree

5 files changed

+109
-32
lines changed

5 files changed

+109
-32
lines changed

firebase-common.js

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

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

firebase.android.js

Lines changed: 60 additions & 0 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) {
@@ -2118,4 +2123,59 @@ firebase.invites.getInvitation = function () {
21182123
});
21192124
};
21202125

2126+
2127+
firebase.addOnDynamicLinkReceivedCallback = function (callback) {
2128+
return new Promise(function (resolve, reject) {
2129+
try {
2130+
if (typeof(com.google.android.gms.appinvite) === "undefined") {
2131+
reject("Uncomment invites in the plugin's include.gradle first");
2132+
return;
2133+
}
2134+
2135+
firebase._DynamicLinkCallback = callback;
2136+
resolve();
2137+
} catch (ex) {
2138+
console.log("Error in firebase.addOnDynamicLinkReceivedCallback: " + ex);
2139+
reject(ex);
2140+
}
2141+
});
2142+
};
2143+
2144+
var dynamicLinksEnabled = new lazy(function () {
2145+
return typeof(com.google.android.gms.appinvite) !== "undefined"
2146+
});
2147+
2148+
(function() {
2149+
appModule.on("launch", function(args) {
2150+
if (!dynamicLinksEnabled()) {
2151+
return;
2152+
}
2153+
2154+
var intent = args.android;
2155+
2156+
var getDynamicLinksCallback = new com.google.android.gms.tasks.OnCompleteListener({
2157+
onComplete: function(task) {
2158+
2159+
if (task.isSuccessful() && task.getResult() != null) {
2160+
result = task.getResult().getLink();
2161+
result = firebase.toJsObject(result);
2162+
if(firebase._DynamicLinkCallback === null){
2163+
console.log("No callback is provided for a dynamic link");
2164+
}
2165+
else{
2166+
setTimeout(function() {
2167+
firebase._DynamicLinkCallback(result);
2168+
});
2169+
}
2170+
2171+
}
2172+
}
2173+
});
2174+
2175+
firebaseDynamicLinks = com.google.firebase.dynamiclinks.FirebaseDynamicLinks.getInstance();
2176+
DynamicLinks = firebaseDynamicLinks.getDynamicLink(intent).addOnCompleteListener(getDynamicLinksCallback);
2177+
2178+
});
2179+
})()
2180+
21212181
module.exports = firebase;

firebase.d.ts

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -74,37 +74,42 @@ export enum ServerValue {
7474
* The options object passed into the init function.
7575
*/
7676
export interface InitOptions {
77-
/**
78-
* Allow disk persistence. Default false.
79-
*/
80-
persist?: boolean;
81-
/**
82-
* Get notified when the user is logged in.
83-
*/
84-
onAuthStateChanged?: (data: AuthStateData) => void;
85-
/**
86-
* Attempt to sign out before initializing, useful in case previous
87-
* project token is cached which leads to following type of error:
88-
* "[FirebaseDatabase] Authentication failed: invalid_token ..."
89-
* Default false.
90-
*/
91-
iOSEmulatorFlush?: boolean;
92-
/**
93-
* For Firebase Storage you can pass in something like 'gs://n-plugin-test.appspot.com'
94-
* here so we can cache it. Otherwise pass in the 'bucket' param when using Storage features.
95-
* Can be found in the firebase console.
96-
*/
97-
storageBucket?: string;
77+
/**
78+
* Allow disk persistence. Default false.
79+
*/
80+
persist?: boolean;
81+
/**
82+
* Get notified when the user is logged in.
83+
*/
84+
onAuthStateChanged?: (data: AuthStateData) => void;
85+
/**
86+
* Attempt to sign out before initializing, useful in case previous
87+
* project token is cached which leads to following type of error:
88+
* "[FirebaseDatabase] Authentication failed: invalid_token ..."
89+
* Default false.
90+
*/
91+
iOSEmulatorFlush?: boolean;
92+
/**
93+
* For Firebase Storage you can pass in something like 'gs://n-plugin-test.appspot.com'
94+
* here so we can cache it. Otherwise pass in the 'bucket' param when using Storage features.
95+
* Can be found in the firebase console.
96+
*/
97+
storageBucket?: string;
9898

99-
/**
100-
* For FCM either pass in this callback function here, or use addOnMessageReceivedCallback
101-
*/
102-
onPushTokenReceivedCallback?: (data: string) => void;
99+
/**
100+
* For FCM either pass in this callback function here, or use addOnMessageReceivedCallback
101+
*/
102+
onPushTokenReceivedCallback?: (data: string) => void;
103103

104-
/**
105-
* For FCM either pass in this callback function here, or use addOnPushTokenReceivedCallback
106-
*/
107-
onMessageReceivedCallback?: (data: Message) => void;
104+
/**
105+
* For FCM either pass in this callback function here, or use addOnPushTokenReceivedCallback
106+
*/
107+
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 {
@@ -757,6 +762,17 @@ export module invites {
757762
function getInvitation(): Promise<GetInvitationResult>;
758763
}
759764

765+
// Dynamic Link
766+
767+
export interface DynamicLink {
768+
cachedFsi: number;
769+
cachedSsi: number;
770+
scheme: string;
771+
uriString: string;
772+
host: string;
773+
port: number;
774+
}
775+
760776

761777
// Auth
762778
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)