Skip to content

Commit

Permalink
Init firebase app in sw
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptex-github authored Dec 28, 2023
1 parent 59f8d27 commit 5c270a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
18 changes: 18 additions & 0 deletions public/firebase-messaging-sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
importScripts('https://www.gstatic.com/firebasejs/10.7.1/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/10.7.1/firebase-messaging-compat.js');

firebase.initializeApp({
apiKey: "AIzaSyAUwv7mr1FK5BEpzJzqH1Bkb9tSj3e0KXY",
authDomain: "adapt-chat.firebaseapp.com",
projectId: "adapt-chat",
storageBucket: "adapt-chat.appspot.com",
messagingSenderId: "464541692865",
appId: "1:464541692865:web:651cc571d8c787c0823540",
measurementId: "G-W32V7KR3TQ"
});

const messaging = firebase.messaging();

messaging.onBackgroundMessage((payload) => {
console.log('[firebase-messaging-sw] Received background message ', payload);
});
9 changes: 5 additions & 4 deletions src/api/PushNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export default class PushNotifications {

constructor(public api: Api) {
this.app = initializeApp(FIREBASE_CONFIG)
const messaging = getMessaging(this.app)

onMessage(messaging, (payload) => {
console.log('[FIREBASE] Message received. ', payload)
})
}

subscribe() {
Expand All @@ -33,9 +38,5 @@ export default class PushNotifications {
}).catch((err) => {
console.log('An error occurred while retrieving token. ', err)
})

onMessage(messaging, (payload) => {
console.log('[FIREBASE] Message received. ', payload)
})
}
}

0 comments on commit 5c270a7

Please sign in to comment.