/*

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: "AIzaSyAt4R2JrInZjv-251kNOY6JSX5SPQUwCAw",
  authDomain: "puntodeventaweb-83f02.firebaseapp.com",
  databaseURL: "https://puntodeventaweb-83f02.firebaseio.com",
  projectId: "puntodeventaweb-83f02",
  storageBucket: "puntodeventaweb-83f02.appspot.com",
  messagingSenderId: "1025209701023",
  appId: "1:1025209701023:web:bf81b381cf6e2ef97288aa",
  measurementId: "G-EGSWTJB7W1"


    });

  

/*

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";
  var vibration = data.data.vibrate;
  
  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
    });
});
 