mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
53 lines
1.9 KiB
JavaScript
53 lines
1.9 KiB
JavaScript
// eslint-disable-next-line no-undef
|
|
importScripts('https://www.gstatic.com/firebasejs/8.8.0/firebase-app.js');
|
|
// eslint-disable-next-line no-undef
|
|
importScripts('https://www.gstatic.com/firebasejs/8.8.0/firebase-messaging.js');
|
|
|
|
const firebaseConfig = {
|
|
apiKey: "AIzaSyAEkZCHhnyatsNiZ2dpjeaz6JqXYknKKHk",
|
|
authDomain: "hats-8319e.firebaseapp.com",
|
|
projectId: "hats-8319e",
|
|
storageBucket: "hats-8319e.appspot.com",
|
|
messagingSenderId: "422528660020",
|
|
appId: "1:422528660020:web:db16e1cba4d357e32f1061",
|
|
measurementId: "G-RN0NQKCM2F"
|
|
};
|
|
// eslint-disable-next-line no-undef
|
|
firebase.initializeApp(firebaseConfig);
|
|
// eslint-disable-next-line no-undef
|
|
const messaging = firebase.messaging();
|
|
|
|
messaging.onBackgroundMessage((payload) => {
|
|
// console.log('[firebase-messaging-sw.js] Received background message ', payload);
|
|
// const notificationTitle = payload.notification.title;
|
|
// const notificationOptions = {
|
|
// body: payload.notification.body,
|
|
// icon: './assets/hats-256x256.png',
|
|
// // tag: "notification-1"
|
|
// };
|
|
self.registration.hideNotification();
|
|
});
|
|
|
|
messaging.setBackgroundMessageHandler((payload) => {
|
|
self.registration.hideNotification();
|
|
});
|
|
|
|
self.addEventListener('push', event => {
|
|
let payload = event.data.json();
|
|
console.log('[firebase-messaging-sw.js] Received background message ', payload);
|
|
const notificationTitle = payload.notification.title;
|
|
const notificationOptions = {
|
|
body: payload.notification.body,
|
|
icon: './assets/hats-256x256.png',
|
|
// tag: "notification-1"
|
|
};
|
|
self.registration.showNotification(notificationTitle, notificationOptions);
|
|
});
|
|
|
|
self.addEventListener('notificationclick', event => {
|
|
// TODO
|
|
console.log("EVENT notificationclick :", event)
|
|
console.log(event.notification)
|
|
event.notification.close();
|
|
event.waitUntil(this.clients.openWindow('https://his.nutech-integrasi.com'));
|
|
}); |