-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase.js
43 lines (39 loc) · 1.38 KB
/
firebase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Check if the environment supports Firebase Messaging
if (
navigator &&
window &&
"serviceWorker" in navigator &&
"PushManager" in window
) {
// Create firebase fcm service worker
importScripts("https://www.gstatic.com/firebasejs/8.2.1/firebase-app.js");
importScripts(
"https://www.gstatic.com/firebasejs/8.2.1/firebase-messaging.js"
);
// Initialize the Firebase app in the service worker by passing the generated config
var firebaseConfig = {
apiKey: "AIzaSyBaqs5rPeY_5Mol9nq8MOzLhZ5QsdEwL2E",
authDomain: "great-exchange.firebaseapp.com",
projectId: "great-exchange",
storageBucket: "great-exchange.appspot.com",
messagingSenderId: "443106951382",
appId: "1:443106951382:web:4cb7f93ab5c93d09dd8977",
};
firebase.initializeApp(firebaseConfig);
// Retrieve an instance of Firebase Messaging so that it can handle background messages.
const messaging = firebase.messaging();
// Handle background messages
messaging.onBackgroundMessage((payload) => {
console.log(
"[firebase-messaging-sw.js] Received background message ",
payload
);
// Customize notification here
const notificationTitle = "Background Message Title";
const notificationOptions = {
body: "Background Message body.",
icon: "/greatexc.svg",
};
self.registration.showNotification(notificationTitle, notificationOptions);
});
}