36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
|
|
if ('function' === typeof importScripts) {
|
||
|
|
// eslint-disable-next-line no-undef
|
||
|
|
importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-app.js');
|
||
|
|
// eslint-disable-next-line no-undef
|
||
|
|
importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-messaging.js');
|
||
|
|
// eslint-disable-next-line no-undef
|
||
|
|
|
||
|
|
const firebaseConfig = {
|
||
|
|
apiKey: '<FCM_apiKey>',
|
||
|
|
authDomain: '<FCM_authDomain>',
|
||
|
|
databaseURL: '<FCM_databaseURL>',
|
||
|
|
projectId: '<FCM_projectId>',
|
||
|
|
storageBucket: '<FCM_storageBucket>',
|
||
|
|
messagingSenderId: '<FCM_messagingSenderId>',
|
||
|
|
appId: '<FCM_appId>',
|
||
|
|
measurementId: '<FCM_measurementId>'
|
||
|
|
};
|
||
|
|
|
||
|
|
// eslint-disable-next-line no-undef
|
||
|
|
firebase.initializeApp(firebaseConfig);
|
||
|
|
|
||
|
|
const COLLECTIONS_PORTAL_BROADCAST_CHANNEL = 'COLLECTIONS_PORTAL_BROADCAST_CHANNEL';
|
||
|
|
const bc = new BroadcastChannel(COLLECTIONS_PORTAL_BROADCAST_CHANNEL);
|
||
|
|
|
||
|
|
// Retrieve firebase messaging
|
||
|
|
// eslint-disable-next-line no-undef
|
||
|
|
const messaging = firebase.messaging();
|
||
|
|
|
||
|
|
messaging.onBackgroundMessage(function (response) {
|
||
|
|
if (response?.data?.payload) {
|
||
|
|
bc.postMessage(response.data.payload);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
// Initialize the Firebase app in the service worker by passing the generated config
|