Skip to content

Commit

Permalink
Update for new firebase library #26
Browse files Browse the repository at this point in the history
  • Loading branch information
paulincai authored Aug 8, 2021
1 parent 4d31b6c commit 22e0002
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions lib/client/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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', {
Expand All @@ -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,
Expand All @@ -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))
Expand All @@ -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)
Expand Down Expand Up @@ -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() : () => {}
}
Expand All @@ -236,4 +231,4 @@ const webPushUnsubscribe = () => {
return pushSupported && !noConfiguration ? WebPush.unsubscribe() : () => {}
}

export { webPushSubscribe, webPushUnsubscribe, webPushConfigure }
export { webPushSubscribe, webPushUnsubscribe }

0 comments on commit 22e0002

Please sign in to comment.