HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /var/www/nclive/firebase-messaging-sw.js
importScripts("https://www.gstatic.com/firebasejs/11.0.1/firebase-app-compat.js");
importScripts("https://www.gstatic.com/firebasejs/11.0.1/firebase-messaging-compat.js");

firebase.initializeApp({
  apiKey: "AIzaSyB7mQGdLNFy2UTH93p3A7c5m-R244_4amg",
  projectId: "naukriconnectapp-45431",
  messagingSenderId: "138268116111",
  appId: "1:138268116111:web:419ac3a40392ff1c651cfa",
});

const messaging = firebase.messaging();

// Handle background messages
messaging.onBackgroundMessage(function (payload) {
  console.log("Background message received:", payload);

  if (payload?.notification) {
    const notificationTitle = payload.notification.title;
    const notificationOptions = {
      body: payload.notification.body,
      icon: "/images/nc-withbg.png"
    };

    // Only show when page is not focused
    self.registration.showNotification(notificationTitle, notificationOptions);
  }
});

self.addEventListener("message", (event) => {
  if (event.data && event.data.type === "SHOW_NOTIFICATION") {
    const payload = event.data.payload;

    const notificationTitle = payload.notification?.title || "Notification";
    const notificationOptions = {
      body: payload.notification?.body || "",
      icon: "/images/nc-withbg.png"
    };

    self.registration.showNotification(notificationTitle, notificationOptions);
  }
});


// Optional: Handle notification click
self.addEventListener("notificationclick", function(event) {
  event.notification.close();
  event.waitUntil(
    clients.openWindow("/") // redirect to home or custom URL
  );
});