@ukpc-lib/react 0.10.10 → 0.10.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ /* eslint-disable no-undef */
2
+ // This a service worker file for receiving push notifitications.
3
+ // See `Access registration token section` @ https://firebase.google.com/docs/cloud-messaging/js/client#retrieve-the-current-registration-token
4
+
5
+ // Scripts for firebase and firebase messaging
6
+ // eslint-disable-next-line no-undef
7
+ importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-app.js');
8
+ importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-messaging.js');
9
+
10
+
11
+ // Initialize the Firebase app in the service worker by passing the generated config
12
+ // TODO: research for initializing config using .env in each repo instead of hardcode
13
+ const firebaseConfig = {
14
+ apiKey: "AIzaSyBURVBSZYwY5qqVJClcp8_3uCi9X88CXX0",
15
+ authDomain: "sb-brand3.firebaseapp.com",
16
+ projectId: "sb-brand3",
17
+ storageBucket: "sb-brand3.appspot.com",
18
+ messagingSenderId: "219299800311",
19
+ appId: "1:219299800311:web:128cdb8de3650de3021ff2",
20
+ measurementId: "G-MLZSEVW7YD"
21
+ };
22
+
23
+
24
+ firebase.initializeApp(firebaseConfig);
25
+
26
+ // Retrieve firebase messaging
27
+ const messaging = firebase.messaging();
28
+
29
+ //Handle incoming messages while the app is not in focus (i.e in the background, hidden behind other tabs, or completely closed).
30
+ const channel = new BroadcastChannel('my-channel');
31
+ messaging.onBackgroundMessage(function(payload) {
32
+ console.log('Received background message ', payload);
33
+
34
+ const notificationTitle = payload.data.actorName;
35
+ const notificationOptions = {
36
+ body: `${payload.data.message} ${payload.data.context}`,
37
+ icon: 'https://ukpcsaprod.blob.core.windows.net/saas/notification-icon.svg',
38
+ };
39
+
40
+ self.registration.showNotification(notificationTitle,
41
+ notificationOptions);
42
+ channel.postMessage({notificationTitle, notificationOptions});
43
+ });