WIP FCM push messaging.
This commit is contained in:
44
client/public/firebase-messaging-sw.js
Normal file
44
client/public/firebase-messaging-sw.js
Normal file
@@ -0,0 +1,44 @@
|
||||
importScripts("https://www.gstatic.com/firebasejs/7.14.2/firebase-app.js");
|
||||
importScripts(
|
||||
"https://www.gstatic.com/firebasejs/7.14.2/firebase-messaging.js"
|
||||
);
|
||||
|
||||
firebase.initializeApp({
|
||||
apiKey: "AIzaSyDV9MsSHZmpLtjoaTK_ObvjFaJ-nMSd2KA",
|
||||
authDomain: "bodyshop-dev-b1cb6.firebaseapp.com",
|
||||
databaseURL: "https://bodyshop-dev-b1cb6.firebaseio.com",
|
||||
projectId: "bodyshop-dev-b1cb6",
|
||||
storageBucket: "bodyshop-dev-b1cb6.appspot.com",
|
||||
messagingSenderId: "922785209028",
|
||||
appId: "1:922785209028:web:96e9df15401eee5d784791",
|
||||
measurementId: "G-2D5378VCHE",
|
||||
});
|
||||
|
||||
const messaging = firebase.messaging();
|
||||
|
||||
//Handles Background Messages
|
||||
messaging.setBackgroundMessageHandler(function (payload) {
|
||||
console.log("backgroundMessageHandler", payload);
|
||||
const promiseChain = clients
|
||||
.matchAll({
|
||||
type: "window",
|
||||
includeUncontrolled: true,
|
||||
})
|
||||
.then((windowClients) => {
|
||||
for (let i = 0; i < windowClients.length; i++) {
|
||||
const windowClient = windowClients[i];
|
||||
windowClient.postMessage(payload);
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
return registration.showNotification(JSON.stringify(payload));
|
||||
});
|
||||
return promiseChain;
|
||||
});
|
||||
|
||||
//Handles the notification getting clicked.
|
||||
self.addEventListener("notificationclick", function (event) {
|
||||
// do what you want
|
||||
// ...
|
||||
console.log("SW notificationclick", event);
|
||||
});
|
||||
@@ -22,5 +22,6 @@
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#fff",
|
||||
"background_color": "#fff"
|
||||
"background_color": "#fff",
|
||||
"gcm_sender_id": "103953800507"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user