-
Notifications
You must be signed in to change notification settings - Fork 875
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* FCM Pre Modualization * Refactor FCM typing * Polish javascript doc * Update index.d.ts * Add Changeset * Fix changeset from major to minor * Add to changeset * Polished index.d.ts based on Arthur's feedback * Polish PR based on feedbacks * Update Changeset * Fix wording * Polishing
- Loading branch information
Showing
47 changed files
with
1,435 additions
and
688 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'firebase': minor | ||
'@firebase/messaging': minor, | ||
'@firebase/messaging-types': minor | ||
--- | ||
|
||
Add `getToken(options:{serviceWorkerRegistration, vapidKey})`,`onBackgroundMessage`. | ||
Deprecate `setBackgroundMessageHandler`, `onTokenRefresh`, `useVapidKey`, `useServiceWorker`, `getToken`. | ||
|
||
Add Typing `MessagePayload`, `NotificationPayload`, `FcmOptions`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @license | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
async function addPayloadToDb(payload) { | ||
const dbOpenReq = indexedDB.open(TEST_DB); | ||
|
||
dbOpenReq.onupgradeneeded = () => { | ||
const db = dbOpenReq.result; | ||
|
||
// store creation is a synchronized call | ||
console.log('creating object store...'); | ||
db.createObjectStore(BACKGROUND_MESSAGES_OBJECT_STORE, { | ||
keyPath: BACKGROUND_MESSAGES_OBJECT_STORE_PRIMARY_KEY | ||
}); | ||
}; | ||
|
||
dbOpenReq.onsuccess = () => { | ||
const db = dbOpenReq.result; | ||
|
||
addPayloadToDbInternal(db, { | ||
...payload, | ||
// ndx is required as the primary key of the store. It doesn't have any other testing purpose | ||
ndx: BACKGROUND_MESSAGES_OBJECT_STORE_DEFAULT_NDX | ||
}); | ||
}; | ||
} | ||
|
||
async function addPayloadToDbInternal(db, payload) { | ||
// onsuccess might race with onupgradeneeded. Consequently causing "object stores was not found" | ||
// error. Therefore, wait briefly for db.createObjectStore to complete | ||
const delay = ms => new Promise(res => setTimeout(res, ms)); | ||
await delay(/* milliseconds= */ 30000); | ||
|
||
tx = db.transaction(BACKGROUND_MESSAGES_OBJECT_STORE, 'readwrite'); | ||
|
||
console.log('adding message payload to db: ' + JSON.stringify(payload)); | ||
addReq = tx.objectStore(BACKGROUND_MESSAGES_OBJECT_STORE).add(payload); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
integration/messaging/test/static/valid-vapid-key-modern-sw/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<html> | ||
<head> | ||
<title>FCM Demo</title> | ||
<meta name="viewport" content="width=device-width,initial-scale=1" /> | ||
</head> | ||
<body> | ||
<h1>Valid <strong>WITH</strong> VAPID Key - Modern SW</h1> | ||
|
||
<script src="/firebase-app.js"></script> | ||
<script src="/firebase-messaging.js"></script> | ||
<script src="../app.js"></script> | ||
<script src="../constants.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/sinon.js/4.1.3/sinon.min.js"></script> | ||
<script> | ||
navigator.serviceWorker | ||
.register('./sw.js') | ||
.then(reg => { | ||
window.__test = new window.DemoApp(FIREBASE_CONFIG, { | ||
swReg: reg, | ||
vapidKey: PUBLIC_VAPID_KEY | ||
}); | ||
}) | ||
.catch(error => { | ||
console.log('Error registering FCM SW: ' + error); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.