2022-01-03 18:45:37 +01:00
|
|
|
// if ("serviceWorker" in navigator) {
|
|
|
|
|
// navigator.serviceWorker
|
|
|
|
|
// .register("./firebase-messaging-sw.js")
|
|
|
|
|
// .then(function(registration) {
|
|
|
|
|
// console.log("Registration successful, scope is:", registration.scope);
|
|
|
|
|
// messaging.getToken({vapidKey: 'BEuyzkUKcx4FSs-6GaIz_si2oV5Ut7e5ZEtcrVvr5L_tMVWZtS1NTqdtQkih5QCt2FZKuRUxZIaLm5GaxI6nJEw', serviceWorkerRegistration : registration })
|
|
|
|
|
// .then((currentToken) => {
|
|
|
|
|
// if (currentToken) {
|
|
|
|
|
// console.log('current token for client: ', currentToken);
|
2021-11-21 19:52:19 +01:00
|
|
|
|
2022-01-03 18:45:37 +01:00
|
|
|
// // Track the token -> client mapping, by sending to backend server
|
|
|
|
|
// // show on the UI that permission is secured
|
|
|
|
|
// } else {
|
|
|
|
|
// console.log('No registration token available. Request permission to generate one.');
|
2021-11-21 19:52:19 +01:00
|
|
|
|
2022-01-03 18:45:37 +01:00
|
|
|
// // shows on the UI that permission is required
|
|
|
|
|
// }
|
|
|
|
|
// }).catch((err) => {
|
|
|
|
|
// console.log('An error occurred while retrieving token. ', err);
|
|
|
|
|
// // catch error while creating client token
|
|
|
|
|
// });
|
|
|
|
|
// })
|
|
|
|
|
// .catch(function(err) {
|
|
|
|
|
// console.log("Service worker registration failed, error:" , err );
|
|
|
|
|
// });
|
|
|
|
|
// }
|
2021-11-05 15:59:12 +01:00
|
|
|
// Scripts for firebase and firebase messaging
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-app.js');
|
|
|
|
|
importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-messaging.js');
|
|
|
|
|
|
|
|
|
|
// Initialize the Firebase app in the service worker by passing the generated config
|
|
|
|
|
var firebaseConfig = {
|
|
|
|
|
apiKey: "AIzaSyAAdHmTFznCMerdT99nrewJgISRvtxPqoY",
|
|
|
|
|
authDomain: "gabinete-digital-2020.firebaseapp.com",
|
|
|
|
|
databaseURL: "https://gabinete-digital-2020.firebaseio.com",
|
|
|
|
|
projectId: "gabinete-digital-2020",
|
|
|
|
|
storageBucket: "gabinete-digital-2020.appspot.com",
|
|
|
|
|
messagingSenderId: "800733765231",
|
|
|
|
|
appId: "1:800733765231:web:28e7792ab150006513779a",
|
|
|
|
|
measurementId: "G-8QN4BLZ8XK"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
firebase.initializeApp(firebaseConfig);
|
|
|
|
|
|
|
|
|
|
// Retrieve firebase messaging
|
|
|
|
|
const messaging = firebase.messaging();
|
|
|
|
|
|
|
|
|
|
messaging.onBackgroundMessage(function(payload) {
|
|
|
|
|
console.log('Received background message ', payload);
|
|
|
|
|
|
|
|
|
|
const notificationTitle = payload.notification.title;
|
|
|
|
|
const notificationOptions = {
|
|
|
|
|
body: payload.notification.body,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.registration.showNotification(notificationTitle,
|
|
|
|
|
notificationOptions);
|
|
|
|
|
}); */
|