This commit is contained in:
Peter Maquiran
2023-02-03 19:37:47 +01:00
parent 065fc517ae
commit 6ff883c982
17 changed files with 871 additions and 169 deletions
+30 -9
View File
@@ -1,11 +1,3 @@
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./firebase-messaging-sw.js')
.then(function(registration) {
}).catch(function(err) {
});
}
// 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');
@@ -36,4 +28,33 @@ messaging.onBackgroundMessage(function(payload) {
self.registration.showNotification(notificationTitle,
notificationOptions);
});
});
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;
});