Nickersoft / push-fcm-plugin

Official Firebase Cloud Messaging plugin for Push.js v1.0 :fire:
https://pushjs.org
42 stars 13 forks source link

Push.FCM() returns a pending Promise #4

Open weiljx opened 6 years ago

weiljx commented 6 years ago

First Thanks for all of your effort on this. We have push.js working and are working to get this working with the browser closed through push messaging. Currently when we call

Push.FCM() the promise never returns. It shows the PromiseStatus as "pending". Would be interested if you have any thoughts.

Thanks

Nickersoft commented 6 years ago

Could you post your code? Are you getting any console errors?

johnjjung commented 6 years ago

I'm getting the same error, the promise stays pending and doesn't seem to return anything

johnjjung commented 6 years ago

@Nickersoft Not hitting debugger or any console logs below the console.log(config)

// const config = process.env.FIREBASE_CONFIG
    const config = {
      apiKey: process.env.FIREBASE_API_KEY,
      authDomain: process.env.FIREBASE_AUTH_DOMAIN,
      databaseURL: process.env.FIREBASE_DATABASE_URL,
      projectId: process.env.FIREBASE_PROJECT_ID,
      storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
      messagingSenderId: process.env.FIREBASE_MESSAGE_SENDER_ID,
      serviceWorkerLocation: '/static',
      onTokenFetched: (token) => console.log(token)
    }
    console.log(config)
    Push.extend(PushFCM)
    Push.config({
      FCM: config
    })
    Push.FCM().then((fcm) => {
      console.log(fcm)
      debugger
      fcm.getToken().then((token, error) => {
        console.log(token)
        console.log(error)
      }, (error) => { console.log(error) })
      .catch((tokenError) => {
        throw tokenError
      })
    }).catch((initError) => {
      console.log(initError)
      throw initError
    })
otbe commented 6 years ago

Same here. No console log or errors. Testing in latest chrome

otbe commented 6 years ago

Got it working. 😄 I used the firebase version of the serviceworker ("firebase-messaging-sw.js") instead of the packaged version from push-fcm-plugin.

johnjjung commented 6 years ago

@otbe can you specify?

So I did the same thing, I copy pasta'd the https://github.com/Nickersoft/push-fcm-plugin/blob/master/firebase-messaging-sw.js into a public directory to get it running, but it still wouldn't work.

Did you change the firebase versioning or something?