if (firebaseConfig != null) {
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);

  const messaging = firebase.messaging();
  navigator.serviceWorker.register('/silverpeas/spmobile/app-sw.js')
      .then((registration) => {
       navigator.serviceWorker.ready.then(function(reg) {
           messaging.useServiceWorker(registration);

            // Request permission and get token.....
            Notification.requestPermission().then(function(permission) {
              if (permission === "granted") {
                messaging.getToken().then(token => {
                  console.log("Token Is : " + token);
                  storeToken(token);
                });
              } else {
                console.log("No permission to send push");
              }
            });
        });
      });

  messaging.onMessage(payload => {
    const notificationOptions = {
      body : payload.data["body"], icon : '/silverpeas/util/icons/desktop-user-notification.png',
      data : payload.data
    };

    navigator.serviceWorker.getRegistration('/silverpeas/spmobile/').then(registration => {
            registration.showNotification(payload.data["subject"], notificationOptions)
    });
  });
} else {
  navigator.serviceWorker.register('/silverpeas/spmobile/app-sw.js')
      .then((registration) => {
        // Request permission and get token.....
        Notification.requestPermission().then(function(permission) {
        });
  });
}

