22 lines
846 B
JavaScript
22 lines
846 B
JavaScript
|
|
/* FCM 백그라운드 메시지 수신 서비스워커 (vite-plugin-pwa SW 와 별개).
|
||
|
|
* Firebase 웹 config 는 정적 파일에 박지 않고, initPush 등록 시 쿼리스트링으로 전달받는다. */
|
||
|
|
importScripts('https://www.gstatic.com/firebasejs/12.14.0/firebase-app-compat.js');
|
||
|
|
importScripts('https://www.gstatic.com/firebasejs/12.14.0/firebase-messaging-compat.js');
|
||
|
|
|
||
|
|
const p = new URL(self.location).searchParams;
|
||
|
|
firebase.initializeApp({
|
||
|
|
apiKey: p.get('apiKey'),
|
||
|
|
projectId: p.get('projectId'),
|
||
|
|
appId: p.get('appId'),
|
||
|
|
messagingSenderId: p.get('messagingSenderId'),
|
||
|
|
});
|
||
|
|
|
||
|
|
firebase.messaging().onBackgroundMessage((payload) => {
|
||
|
|
const n = payload.notification || {};
|
||
|
|
self.registration.showNotification(n.title || '알림', {
|
||
|
|
body: n.body || '',
|
||
|
|
icon: '/pwa-192x192.png',
|
||
|
|
data: payload.data || {},
|
||
|
|
});
|
||
|
|
});
|