From 22e0002f03ce9000bfc0f719fb564b8f5489b498 Mon Sep 17 00:00:00 2001 From: Paul Ailincai Date: Sun, 8 Aug 2021 19:10:04 +0000 Subject: [PATCH] Update for new firebase library #26 --- lib/client/web.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/client/web.js b/lib/client/web.js index f1ae442..3e14491 100644 --- a/lib/client/web.js +++ b/lib/client/web.js @@ -51,6 +51,7 @@ class WebPushHandle extends EventState { return (ua.indexOf('FBAN') > -1) || (ua.indexOf('FBAV') > -1) } + // If no Firebase configuration, register sw.js // Otherwise register '/firebase-messaging-sw.js' which includes the sw.js @@ -81,12 +82,11 @@ class WebPushHandle extends EventState { doTabsRefresh() return false } - if (!noConfiguration && pushSupported) { const webApp = firebase.initializeApp(configuration.firebase) deviceStorage.setItem('pushSupport', true) this.messaging = webApp.messaging() - this.messaging.usePublicVapidKey(configuration.publicVapidKey) + // this.messaging.usePublicVapidKey(configuration.publicVapidKey) window.addEventListener('load', async () => { const registration = await navigator.serviceWorker.register('/firebase-messaging-sw.js', { @@ -102,7 +102,6 @@ class WebPushHandle extends EventState { */ this.messaging.onMessage(payload => { - this.log('My Foreground Message payload here: ', payload) const title = payload.notification.title const options = { body: payload.notification.body, @@ -119,7 +118,7 @@ class WebPushHandle extends EventState { this.messaging.onTokenRefresh(() => { // Delete the old Push from MongoDB and from the localStore this.unsubscribe() - this.messaging.getToken().then(token => { + this.messaging.getToken({ vapidKey: configuration.publicVapidKey }).then(token => { WebPushEventState.emit('token', token) }).catch(err => { deviceStorage.setItem('lastSubscriptionMessage', interpretError(err)) @@ -141,7 +140,7 @@ class WebPushHandle extends EventState { deviceStorage.setItem('lastSubscriptionMessage', 'The permission request was dismissed.') return } - this.messaging.getToken().then(token => { + this.messaging.getToken({ vapidKey: configuration.publicVapidKey }).then(token => { this.log('Calling subscribe') if (token) { WebPushEventState.emit('token', token) @@ -224,10 +223,6 @@ class WebPushHandle extends EventState { const WebPush = new WebPushHandle() export default WebPush -const webPushConfigure = () => { - // return WebPush.Configure() -} - function webPushSubscribe () { return pushSupported && !noConfiguration ? WebPush.subscribe() : () => {} } @@ -236,4 +231,4 @@ const webPushUnsubscribe = () => { return pushSupported && !noConfiguration ? WebPush.unsubscribe() : () => {} } -export { webPushSubscribe, webPushUnsubscribe, webPushConfigure } +export { webPushSubscribe, webPushUnsubscribe }