问题
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?
回答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.
来源:https://stackoverflow.com/questions/60675926/firebase-cloud-messaging-subcribing-to-topic-from-a-javascript-client