-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfirebase-messaging-sw.js
31 lines (23 loc) · 1.09 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('https://www.gstatic.com/firebasejs/6.3.4/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/6.3.4/firebase-messaging.js');
const firebaseConfig = {}; // Put Your Firebase Config Here
let baseSampleURL = 'http://localhost:8080'; // Your sample running base url
firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(event => {
console.log('[firebase-messaging-sw.js] Received background message ', event);
var payload = JSON.parse(event.data.payload);
return self.registration.showNotification('Incoming call', {
body: 'You have a call from ' + payload.call.caller.fullname,
icon: payload.call.caller.avatarURL,
requireInteraction: true,
data: payload
});
});
self.addEventListener('notificationclick', (event) => {
event.notification.close();
console.log("Notification clicked", event);
if (clients.openWindow) {
return clients.openWindow(`${baseSampleURL}#/call/${event.notification.data.callId}/${event.notification.data.accessToken}`);
}
});