|
@@ -1,12 +1,13 @@
|
|
|
importScripts('https://www.gstatic.com/firebasejs/10.13.2/firebase-app-compat.js');
|
|
|
importScripts('https://www.gstatic.com/firebasejs/10.13.2/firebase-messaging-compat.js');
|
|
|
-// if ('serviceWorker' in navigator) {
|
|
|
-// navigator.serviceWorker.register('./firebase-messaging-sw.js').then(function (reg) {
|
|
|
-// console.log('reg: ', reg.scope);
|
|
|
-// }).catch(function (err) {
|
|
|
-// console.log('err: ', err);
|
|
|
-// })
|
|
|
-// }
|
|
|
+importScripts('swenv.js')
|
|
|
+if ('serviceWorker' in navigator) {
|
|
|
+ navigator.serviceWorker.register('./firebase-messaging-sw.js').then(function (reg) {
|
|
|
+ console.log('reg: ', reg.scope);
|
|
|
+ }).catch(function (err) {
|
|
|
+ console.log('err: ', err);
|
|
|
+ })
|
|
|
+}
|
|
|
class CustomPushEvent extends Event {
|
|
|
constructor(data) {
|
|
|
super('push')
|
|
@@ -16,7 +17,6 @@ class CustomPushEvent extends Event {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-console.log(`🚀🚀🚀🚀🚀-> in firebase-messaging-sw.js on 19`,process);
|
|
|
firebase.initializeApp({
|
|
|
apiKey: process.env.NEXT_PUBLIC_FIREBASE_APIKEY,
|
|
|
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTHDOMAIN,
|
|
@@ -31,6 +31,7 @@ firebase.initializeApp({
|
|
|
// messages.
|
|
|
self.addEventListener('push', (e) => {
|
|
|
// Skip if event is our own custom event
|
|
|
+ console.log(`🚀🚀🚀🚀🚀-> in firebase-messaging-sw.js on 41`, e);
|
|
|
if (e.custom) return;
|
|
|
|
|
|
// Kep old event data to override
|
|
@@ -68,8 +69,9 @@ messaging.onBackgroundMessage( (payload) => {
|
|
|
const notificationTitle = payload.data.title;
|
|
|
const notificationOptions = {
|
|
|
body: payload.data.body,
|
|
|
- icon: '/logo.png',
|
|
|
- data: payload.data
|
|
|
+ icon: payload.data.image,
|
|
|
+ data: payload.data,
|
|
|
+ ...payload.data
|
|
|
};
|
|
|
return self.registration.showNotification(notificationTitle,
|
|
|
notificationOptions);
|
|
@@ -78,7 +80,6 @@ messaging.onBackgroundMessage( (payload) => {
|
|
|
self.onnotificationclick = function (event) {
|
|
|
console.log(`🚀🚀🚀🚀🚀-> in firebase-messaging-sw.js on 91`,event);
|
|
|
//example
|
|
|
- const endpoint = event.notification.data.type;
|
|
|
- self.clients.openWindow('/' + endpoint || "")
|
|
|
+ self.clients.openWindow('/')
|
|
|
event.notification.close()
|
|
|
}
|