diff --git a/angular/angular.json b/angular/angular.json index ea8448c..1b1a0ab 100644 --- a/angular/angular.json +++ b/angular/angular.json @@ -30,7 +30,8 @@ "src/favicon.ico", "src/assets", "src/manifest.webmanifest", - "src/firebase-messaging-sw.js" + "src/firebase-messaging-sw.js", + "src/sw-master.js" ], "styles": [ "node_modules/primeng/resources/themes/bootstrap4-light-blue/theme.css", diff --git a/angular/src/app/app.module.ts b/angular/src/app/app.module.ts index 716954a..f714d39 100644 --- a/angular/src/app/app.module.ts +++ b/angular/src/app/app.module.ts @@ -69,7 +69,7 @@ import { DownloadAppDirective } from './directives/download-app.directive'; HttpClientModule, BrowserAnimationsModule, BrowserModule, - ServiceWorkerModule.register('ngsw-worker.js', { + ServiceWorkerModule.register('/sw-master.js', { enabled: environment.production, // Register the ServiceWorker as soon as the application is stable // or after 30 seconds (whichever comes first). diff --git a/angular/src/app/services/messaging.service.ts b/angular/src/app/services/messaging.service.ts index 33db477..59bc0ed 100644 --- a/angular/src/app/services/messaging.service.ts +++ b/angular/src/app/services/messaging.service.ts @@ -89,9 +89,6 @@ export class MessagingService { data: payload.data, icon: payload.notification.icon } - navigator.serviceWorker.getRegistration('/firebase-cloud-messaging-push-scope').then((registration: any) => { - registration.showNotification(payload.notification.title, NotificationOptions); - }); this.currentMessage.next(payload); }); } diff --git a/angular/src/firebase-messaging-sw.js b/angular/src/firebase-messaging-sw.js index 329818c..3468516 100644 --- a/angular/src/firebase-messaging-sw.js +++ b/angular/src/firebase-messaging-sw.js @@ -1,5 +1,5 @@ -importScripts('https://www.gstatic.com/firebasejs/9.17.1/firebase-app.js'); -importScripts('https://www.gstatic.com/firebasejs/9.17.1/firebase-messaging.js'); +importScripts('https://www.gstatic.com/firebasejs/3.6.9/firebase-app.js'); +importScripts('https://www.gstatic.com/firebasejs/3.6.9/firebase-messaging.js'); firebase.initializeApp({ apiKey: "AIzaSyCnKvln5itnrBj62POCPHxshAN_Vmd0zds", @@ -11,9 +11,4 @@ firebase.initializeApp({ measurementId: "G-RQF97ZK7R1" }); -const messaging = firebase.messaging(); - -self.addEventListener('notificationclick', function(event) { - event.notification.close(); - event.waitUntil(self.clients.openWindow(event.notification.data.url)); -}); \ No newline at end of file +const messaging = firebase.messaging(); \ No newline at end of file diff --git a/angular/src/sw-custom.js b/angular/src/sw-custom.js new file mode 100644 index 0000000..3027cb0 --- /dev/null +++ b/angular/src/sw-custom.js @@ -0,0 +1,8 @@ +(function () { + "use strict"; + + self.addEventListener("notificationclick", (event) => { + event.notification.close(); + console.log("notification details: ", event.notification); + }); +})(); diff --git a/angular/src/sw-master.js b/angular/src/sw-master.js new file mode 100644 index 0000000..62dbad5 --- /dev/null +++ b/angular/src/sw-master.js @@ -0,0 +1,2 @@ +importScripts('./ngsw-worker.js'); +importScripts('./sw-custom.js'); \ No newline at end of file