2023-02-03 14:37:29 +01:00
|
|
|
importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-app.js');
|
2021-11-05 15:59:12 +01:00
|
|
|
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) {
|
2023-08-08 15:40:10 +01:00
|
|
|
console.log('Received background message 22 ', payload);
|
2021-11-05 15:59:12 +01:00
|
|
|
|
|
|
|
|
const notificationTitle = payload.notification.title;
|
|
|
|
|
const notificationOptions = {
|
|
|
|
|
body: payload.notification.body,
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-11 16:14:25 +01:00
|
|
|
/* self.registration.showNotification(notificationTitle,
|
|
|
|
|
notificationOptions); */
|
2023-02-03 19:37:47 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.addEventListener('install', function(event) {
|
|
|
|
|
self.skipWaiting();
|
|
|
|
|
console.log('Installed', event);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.addEventListener('activate', function(event) {
|
|
|
|
|
console.log('Activated', event);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.addEventListener('push', function(event) {
|
|
|
|
|
|
|
|
|
|
var uid = "EXISTS_IN_CORE.JS";
|
|
|
|
|
var token = "ALSO_EXISTS_IN_CORE.JS";
|
|
|
|
|
|
|
|
|
|
console.log("Push recieved - we need to know the uid and token here, from core.js");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.addEventListener('message', function(event){
|
|
|
|
|
var data = JSON.parse(event.data);
|
|
|
|
|
|
|
|
|
|
console.log("SW Received Message:");
|
|
|
|
|
console.log(data);
|
|
|
|
|
|
|
|
|
|
self.userID = data.uid;
|
|
|
|
|
self.userToken = data.token;
|
|
|
|
|
|
2023-08-08 15:40:10 +01:00
|
|
|
});
|
|
|
|
|
|
2023-09-14 11:58:24 +01:00
|
|
|
/* self.addEventListener('notificationclick', function(event) {
|
2023-08-08 15:40:10 +01:00
|
|
|
console.log("Push Clicked ", event);
|
|
|
|
|
// Enviar uma mensagem para o cliente (componente)
|
|
|
|
|
self.clients.matchAll().then((clients) => {
|
2023-08-11 16:14:25 +01:00
|
|
|
console.log("Push Clicked 2", clients);
|
2023-08-08 15:40:10 +01:00
|
|
|
if (clients && clients.length) {
|
|
|
|
|
clients.forEach((client) => {
|
|
|
|
|
client.postMessage({ notificationClicked: true });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-09-14 11:58:24 +01:00
|
|
|
}); */
|