Firebase cloud messaging - subcribing to topic from a JavaScript client [duplicate]

限于喜欢 提交于 2021-02-17 05:54:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!