This commit is contained in:
gofnnp 2022-09-17 19:46:36 +04:00
parent 9428c3638b
commit 8659ba1fc2
3 changed files with 21 additions and 20 deletions

View File

@ -64,6 +64,7 @@ export class MainComponent implements OnInit {
}
requestPermission() {
console.log('####: ')
this.messagingService.requestPermission()
this.messagingService.receiveMessage()
this.message = this.messagingService.currentMessage

View File

@ -52,19 +52,32 @@ export class MessagingService {
}
requestPermission() {
this.angularFireMessaging.requestToken.subscribe({
next: (token) => {
this.updateToken(token);
console.log(token);
},
error: (e) => console.error(e),
});
try {
console.log('1');
this.angularFireMessaging.getToken.subscribe({
next: (val) => {
console.log('VAL: ', val)
}
})
this.angularFireMessaging.requestToken.subscribe({
next: (token) => {
console.log('#: ')
this.updateToken(token);
console.log('####TOKEN: ', token);
},
error: (e) => console.error(e),
});
} catch (error) {
console.error(error)
}
}
/**
* hook method when new notification received in foreground
*/
receiveMessage() {
console.log('#REC')
this.angularFireMessaging.messages.subscribe((payload: any) => {
console.log('new message received. ', payload);
this.currentMessage.next(payload);

View File

@ -1,13 +0,0 @@
importScripts('https://www.gstatic.com/firebasejs/3.6.8/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.6.8/firebase-messaging.js');
firebase.initializeApp({
apiKey: "AIzaSyCujHg9GtN8Uxi-JcCN8zggvXlfNQRKc04",
authDomain: "push-notification-test2-56dac.firebaseapp.com",
projectId: "push-notification-test2-56dac",
storageBucket: "push-notification-test2-56dac.appspot.com",
messagingSenderId: "1004369687552",
appId: "1:1004369687552:web:a6cc20625e05520a37d4e5"
});
const messaging = firebase.messaging();