forked from gdg-x/hoverboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase-messaging-sw.js
31 lines (28 loc) · 1.07 KB
/
firebase-messaging-sw.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
importScripts('./node_assets/firebase/firebase-app.js');
importScripts('./node_assets/firebase/firebase-messaging.js');
firebase.initializeApp({
apiKey: '{$ firebase.apiKey $}',
appId: '{$ firebase.appId $}',
authDomain: '{$ firebase.authDomain $}',
databaseURL: '{$ firebase.databaseURL $}',
messagingSenderId: '{$ firebase.messagingSenderId $}',
projectId: '{$ firebase.projectId $}',
storageBucket: '{$ firebase.storageBucket $}',
});
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(({ data }) => {
const notification = Object.assign({}, data, {
data: {
click_action: data.click_action,
},
});
return self.registration.showNotification(notification.title, notification);
});
self.addEventListener('notificationclick', (event) => {
const isPath =
event.notification.data.click_action && event.notification.data.click_action.startsWith('/');
const url = isPath
? `${self.origin}${event.notification.data.click_action}`
: event.notification.data.click_action;
event.waitUntil(clients.openWindow(url));
});