Created
May 1, 2020 07:59
-
-
Save rodydavis/d8259d5d0eb5c528c2c5cee755ca01a4 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.5.0/firebase-app.js"); | |
importScripts("https://www.gstatic.com/firebasejs/7.5.0/firebase-messaging.js"); | |
firebase.initializeApp({ | |
apiKey: "API_KEY", | |
authDomain: "AUTH_DOMAIN", | |
databaseURL: "DATABASE_URL", | |
projectId: "PROJECT_ID", | |
storageBucket: "STORAGE_BUCKET", | |
messagingSenderId: "MESSAGING_SENDER_ID", | |
appId: "APP_ID", | |
measurementId: "MEASUREMENT_ID" | |
}); | |
const messaging = firebase.messaging(); | |
messaging.setBackgroundMessageHandler(function (payload) { | |
const promiseChain = clients | |
.matchAll({ | |
type: "window", | |
includeUncontrolled: true | |
}) | |
.then(windowClients => { | |
for (let i = 0; i < windowClients.length; i++) { | |
const windowClient = windowClients[i]; | |
windowClient.postMessage(payload); | |
} | |
}) | |
.then(() => { | |
return registration.showNotification("New Message"); | |
}); | |
return promiseChain; | |
}); | |
self.addEventListener('notificationclick', function (event) { | |
console.log('notification received: ', event) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment