From 3f3b79fea31aefc0bc899b391b53fdff8100a542 Mon Sep 17 00:00:00 2001 From: Doyu-Lee Date: Thu, 11 Jan 2024 22:27:31 +0900 Subject: [PATCH] =?UTF-8?q?chore(develop):=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- firebase-messaging-sw.js | 56 --------------------------------- firebase/firebase.js | 5 ++- public/firebase-messaging-sw.js | 3 +- 3 files changed, 3 insertions(+), 61 deletions(-) delete mode 100644 firebase-messaging-sw.js diff --git a/firebase-messaging-sw.js b/firebase-messaging-sw.js deleted file mode 100644 index 3572c98..0000000 --- a/firebase-messaging-sw.js +++ /dev/null @@ -1,56 +0,0 @@ -importScripts( - "https://www.gstatic.com/firebasejs/9.0.0/firebase-app-compat.js", -); -importScripts( - "https://www.gstatic.com/firebasejs/9.0.0/firebase-messaging-compat.js", -); - -const firebaseConfig = { - apiKey: "AIzaSyAR7EVRk7tK2-ygKtecKt9iK6qaEVFSvLs", - authDomain: "looi-b28fe.firebaseapp.com", - projectId: "looi-b28fe", - storageBucket: "looi-b28fe.appspot.com", - messagingSenderId: "474327539636", - appId: "1:474327539636:web:0e12bc5c9db1539b9e5ce1", - measurementId: "G-MNM6B8Q54T", -}; - -const app = firebase.initializeApp(firebaseConfig); -const messaging = firebase.messaging(app); - -/** - * messaging.onBackgroundMessage - 앱 사용하지 않는 중 메시지 수신 (백그라운드) - */ -messaging.onBackgroundMessage(function (payload) { - console.log("[Background]", payload); - - self.addEventListener("notificationclick", (event) => { - const notificationTitle = payload.notification.title; - const notificationOptions = { - body: payload.notification.body, - icon: payload.notification.image, - badge: "https://docent.zip/icon.png", - }; - self.registration.showNotification( - notificationTitle, - notificationOptions, - ); - event.notification.close(); - - event.waitUntil( - clients - .matchAll({ - type: "window", - }) - .then((clientList) => { - for (const client of clientList) { - console.log(client); - if (client.url === "/" && "focus" in client) - return client.focus(); - } - if (clients.openWindow) - return clients.openWindow("https://docent.zip"); - }), - ); - }); -}); diff --git a/firebase/firebase.js b/firebase/firebase.js index fbd0edf..15b9d65 100644 --- a/firebase/firebase.js +++ b/firebase/firebase.js @@ -46,7 +46,7 @@ export async function getFCMToken() { */ export const onMessageListener = () => { if (process.client) { - console.log("Foreground Message Listener registered!"); + // console.log("Foreground Message Listener registered!"); const app = initializeApp(firebaseConfig); const messaging = getMessaging(app); @@ -68,7 +68,7 @@ export const onMessageListener = () => { notificationTitle, notificationOptions, ); - console.log(notif); + notif.onclick = (event) => { event.preventDefault(); const landing_url = payload.data.landing_url; @@ -77,7 +77,6 @@ export const onMessageListener = () => { notif.close(); }; } else if (!isIOSApp() && isMobile) { - console.log("Mobile:AOS"); navigator.serviceWorker.ready.then(function (registration) { registration.showNotification( notificationTitle, diff --git a/public/firebase-messaging-sw.js b/public/firebase-messaging-sw.js index 784b7b9..0342eb9 100644 --- a/public/firebase-messaging-sw.js +++ b/public/firebase-messaging-sw.js @@ -70,8 +70,7 @@ messaging.onBackgroundMessage(function (payload) { const notificationTitle = payload.data.title; const notificationOptions = { body: payload.data.body + "백", - icon: payload.data.image_url, - image: payload.data.landing_url, + image: payload.data.image_url, icon: "https://docent.zip/icon.png", }; self.registration.showNotification(notificationTitle, notificationOptions);