importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-messaging.js');
firebase.initializeApp({
  messagingSenderId: '628214501041'
});
const messaging = firebase.messaging();


messaging.setBackgroundMessageHandler(function (payload) {
  console.log('[firebase-messaging-sw.js] Received background message ', payload);
  var notificationTitle = 'Background Message Title';
  var notificationOptions = {
    body: 'Background Message body.',
  };
  return self.registration.showNotification(notificationTitle,
    notificationOptions);
});
self.addEventListener('push', function (event) {
  var pushData = event.data.json();
  const promiseChain = clients.matchAll({
    type: 'window',
    includeUncontrolled: true
  })
    .then((windowClients) => {
      for (let i = 0; i < windowClients.length; i++) {
        const windowClient = windowClients[i];
        windowClient.postMessage(pushData);
      }
    })
    .then(() => {
      // return registration.showNotification('my notification title');
    });
  return promiseChain;
  try {
  } catch (err) {
  }
});


