mirror of
https://git.steelants.cz/SH/PHP_SMART_HOME_V3.git
synced 2026-10-11 09:45:33 +00:00
Push Messages #1
This commit is contained in:
1 parent
92f8486f91
commit
1f456aaaac
3 files changed
+106
-75
No files matched your search
+43
-42
@@ -1,3 +1,6 @@
|
||||
importScripts('https://www.gstatic.com/firebasejs/7.1.0/firebase-app.js');
|
||||
importScripts('https://www.gstatic.com/firebasejs/7.1.0/firebase-messaging.js');
|
||||
|
||||
/**
|
||||
* Cache version, change name to force reload
|
||||
*/
|
||||
@@ -22,57 +25,55 @@ var CACHE_FILES = [
|
||||
'assets/logo.svg'
|
||||
];
|
||||
|
||||
/**
|
||||
* Service worker 'install' event.
|
||||
* If all the files are successfully cached, then the service worker will be installed.
|
||||
* If any of the files fail to download, then the install step will fail.
|
||||
*/
|
||||
this.addEventListener('install', function(event) {
|
||||
console.log('Install');
|
||||
});
|
||||
|
||||
/**
|
||||
* After a service worker is installed and the user navigates to a different page or refreshes,
|
||||
* the service worker will begin to receive fetch events.
|
||||
*
|
||||
* Network-first approach: if online, request is fetched from network and not from cache
|
||||
*/
|
||||
|
||||
self.addEventListener('push', function(event) {
|
||||
console.log('Received a push message', event);
|
||||
if (!firebase.apps.length) {
|
||||
firebase.initializeApp({
|
||||
'messagingSenderId': '93473765978'
|
||||
});
|
||||
}
|
||||
|
||||
var title = 'Notification';
|
||||
var body = 'There is newly updated content available on the site. Click to see more.';
|
||||
var icon = 'https://raw.githubusercontent.com/deanhume/typography/gh-pages/icons/typography.png';
|
||||
var tag = 'simple-push-demo-notification-tag';
|
||||
const messaging = firebase.messaging();
|
||||
messaging.setBackgroundMessageHandler(function(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: '/itwonders-web-logo.png'
|
||||
};
|
||||
|
||||
return self.registration.showNotification(notificationTitle,
|
||||
notificationOptions);
|
||||
});
|
||||
});
|
||||
|
||||
event.waitUntil(
|
||||
self.registration.showNotification(title, {
|
||||
body: body,
|
||||
icon: icon,
|
||||
tag: tag
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('sync', function(event) {
|
||||
console.info('Event: Sync');
|
||||
self.addEventListener('sync', function(event) {
|
||||
console.info('Event: Sync');
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', function (event) {
|
||||
self.addEventListener('fetch', function (event) {
|
||||
|
||||
});
|
||||
|
||||
self.addEventListener("online", function (event) {
|
||||
|
||||
});
|
||||
|
||||
self.addEventListener("offline", function (event) {
|
||||
});
|
||||
|
||||
self.addEventListener('notificationclick', function(e) {
|
||||
|
||||
});
|
||||
|
||||
// Initialize the Firebase app in the service worker by passing in the
|
||||
// messagingSenderId.
|
||||
|
||||
});
|
||||
|
||||
self.addEventListener("online", function (event) {
|
||||
|
||||
});
|
||||
|
||||
self.addEventListener("offline", function (event) {
|
||||
});
|
||||
|
||||
self.addEventListener('notificationclick', function(e) {
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user