Push v1
Wenn /dash aufgerufen wird, wird in der Konsole ein MSG TOKEN ausgegeben, dieser muss kopiert werden. Wenn localhost:7000/push/<MSGTOKEN> aufgerufen wird, bekommt der user dem der MSG TOKEN gehört eine push notification, sollange er den Browser offen hat
This commit is contained in:
25
express-server/public/firebase-messaging-sw.js
Normal file
25
express-server/public/firebase-messaging-sw.js
Normal file
@ -0,0 +1,25 @@
|
||||
// Give the service worker access to Firebase Messaging.
|
||||
// Note that you can only use Firebase Messaging here, other Firebase libraries
|
||||
// are not available in the service worker.
|
||||
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
|
||||
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');
|
||||
|
||||
// Initialize the Firebase app in the service worker by passing in the
|
||||
// messagingSenderId.
|
||||
firebase.initializeApp({
|
||||
'messagingSenderId': 'YOUR-SENDER-ID'
|
||||
});
|
||||
|
||||
// Retrieve an instance of Firebase Messaging so that it can handle background
|
||||
// messages.
|
||||
const messaging = firebase.messaging();
|
||||
|
||||
|
||||
|
||||
messaging.setBackgroundMessageHandler(payload => {
|
||||
const title = payload.data.title
|
||||
const options = {
|
||||
body: payload.data.text
|
||||
}
|
||||
return self.registration.showNotification(title, options)
|
||||
})
|
Reference in New Issue
Block a user