parent
5152d9ad30
commit
699db43b39
@ -84,11 +84,15 @@ export class MessagingService {
|
|||||||
receiveMessage() {
|
receiveMessage() {
|
||||||
this.angularFireMessaging.messages.subscribe((payload: any) => {
|
this.angularFireMessaging.messages.subscribe((payload: any) => {
|
||||||
console.log('new message received. ', payload);
|
console.log('new message received. ', payload);
|
||||||
|
const NotificationOptions = {
|
||||||
|
body: payload.notification.body,
|
||||||
|
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);
|
this.currentMessage.next(payload);
|
||||||
});
|
});
|
||||||
this.angularFireMessaging.onMessage((res) => {
|
|
||||||
console.log('@@@@: ', res);
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
7
angular/src/firebase-messaging-sw.js
vendored
7
angular/src/firebase-messaging-sw.js
vendored
@ -11,4 +11,9 @@ firebase.initializeApp({
|
|||||||
measurementId: "G-RQF97ZK7R1"
|
measurementId: "G-RQF97ZK7R1"
|
||||||
});
|
});
|
||||||
|
|
||||||
const messaging = firebase.messaging();
|
const messaging = firebase.messaging();
|
||||||
|
|
||||||
|
self.addEventListener('notificationclick', function(event) {
|
||||||
|
event.notification.close();
|
||||||
|
event.waitUntil(self.clients.openWindow(event.notification.data.url));
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user