/*

Give the service worker access to Firebase Messaging.

Note that you can only use Firebase Messaging here, other Firebase libraries are not available in the service worker.

*/

importScripts('https://www.gstatic.com/firebasejs/8.4.1/firebase-app.js');

importScripts('https://www.gstatic.com/firebasejs/8.4.1/firebase-messaging.js');

   

/*

Initialize the Firebase app in the service worker by passing in the messagingSenderId.

* New configuration for app@pulseservice.com

*/

firebase.initializeApp({

  apiKey: "AIzaSyBSbik7z_-Z_1SIXvSA3ZcGMqWU8uUuJwY",
  authDomain: "marisquerialaisla-b349a.firebaseapp.com",
  projectId: "marisquerialaisla-b349a",
  storageBucket: "marisquerialaisla-b349a.appspot.com",
  messagingSenderId: "180671319698",
  appId: "1:180671319698:web:9121ee0d96146e918ea04b"

});

  

/*

Retrieve an instance of Firebase Messaging so that it can handle background messages.

*/

const messaging = firebase.messaging();

// When a notification is received, the push event is called.
self.addEventListener('push', function (event) {

var data = {};
  if (event.data) {
    data = event.data.json();
  }
  var title = data.data.title || "Something Has Happened";
  var message = data.data.body || "Here's something you might want to check out.";
  var icone = "logo.png";

  const notificationPromise = self.registration.showNotification(
    title,
    {
      body: message,
      icon: icone,
      vibrate: [500]
    });

  event.waitUntil(notificationPromise);

}, false)

// If the web application is in the background, setBackGroundMessageHandler is called.
messaging.setBackgroundMessageHandler(function (payload) {

  console.log("backgroundMessage")

  let messageTitle = "MESSAGETITLE"
  let messageBody = "MESSAGEBODY"

  return self.registration.showNotification(
    messageTitle,
    {
      body: messageBody,
      tag: messageTag
    });
});