0

After a lot of pain I got Firebase cloud messaging to work for my JavaScript PWA and push notifications are sent and received properly. However I did create quite a few Cloud Functions to manage topic registration (from the server then). Now I would like to minimize my use of Cloud Functions, and do as much as possible from the client.

I see at here that the Android client SDK allows managing registration to topics, but I cannot find any such documentation for the JavaScript SDK - is it possible?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
l1b3rty
  • 3,333
  • 14
  • 32

1 Answers1

1

The JavaScript SDK for Firebase Cloud Messaging does not support subscribing to a topic.

To subscribe a web app to a topic you will have to the REST API. Since this requires that you specify the FCM Server Key, you'll have to do this from a trusted environment, such as your development machine, a server you control, or Cloud Functions.

Once you've subscribed a web client to a topic it can receive the message similar to how iOS and Android do.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Good that it is secured via the FCM Server Key. But I read here https://firebase.google.com/docs/cloud-messaging/android/topic-messaging that on Android it is possible. Am I missing something? – l1b3rty Jul 05 '20 at 19:54
  • An Android app (or iOS app) can **subscribe** to a topic, and it will in that case associate the FCM token for that app instance with the topic in that project. There is no such API in the JavaScript SDK through, which means you'll have to do it through the server-side REST API by specifying both the FCM token *and* the FCM server key. – Frank van Puffelen Jul 05 '20 at 21:37