Last active
November 2, 2020 09:15
-
-
Save Mohammad-Faisal/1ba8eaf12e69bc259711b3227bb701e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
importScripts('https://www.gstatic.com/firebasejs/7.14.2/firebase-app.js') | |
importScripts('https://www.gstatic.com/firebasejs/7.14.2/firebase-messaging.js') | |
const config = { | |
apiKey: "API_KEY", | |
authDomain: "PROJECT_ID.firebaseapp.com", | |
databaseURL: "https://PROJECT_ID.firebaseio.com", | |
projectId: "PROJECT_ID", | |
storageBucket: "PROJECT_ID.appspot.com", | |
messagingSenderId: "SENDER_ID", | |
appId: "APP_ID", | |
measurementId: "G-MEASUREMENT_ID" | |
} | |
firebase.initializeApp(config) | |
const messaging = firebase.messaging() | |
// IF WE WANT TO HANDLE BACKGROUND NOTIFICATION WE HAVE TO ADD THE FOLLOWING BLOCK OF CODE AS WELL | |
messaging.setBackgroundMessageHandler(function (payload) { | |
console.log('[firebase-messaging-sw.js] Received background message ', payload) | |
const notificationTitle = payload.data.title | |
const notificationOptions = { | |
body: payload.data.body, | |
icon: '/firebase-logo.png' | |
} | |
return self.registration.showNotification(notificationTitle, notificationOptions) | |
}) | |
self.addEventListener('notificationclick', (event) => { | |
console.log(event) | |
return event | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment