如何从javascript注册GCM主题(适用于Chrome) [英] How to get registered into GCM topics from javascript (for Chrome)

查看:197
本文介绍了如何从javascript注册GCM主题(适用于Chrome)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是一个很好的文档,介绍如何实施Chrome中的Google云消息传递(GCM)。但我没有在这里或任何地方找到任何有关如何使用JavaScript(用于Chrome)订阅主题的参考。



在这里,我找到了一个参考如何完成任务Android:
https://developers.google .com / cloud-messaging / topic-messaging#订阅主题

订阅GCM主题的Java代码(Android)

  private void subscribeTopics(String token)throws IOException {
GcmPubSub pubSub = GcmPubSub.getInstance(this);
for(String topic:TOPICS){
pubSub.subscribe(token,/ topics /+ topic,null);


我不期待 strong>



我不想为Chrome应用/扩展程序寻找方法。

我需要什么



我想向所有用户发送推送通知。 到目前为止,我知道这可以可以通过两种方式实现:


  1. 将消息推送到某个主题

  2. 或者我必须:您需要发送设备的注册ID列表,并且此列表不应超过1000.如果您想要将消息发送到1000多个设备,则这是GCM的限制,那么您需要将该列表以1000个块为单位打破。

我想避免使用第二点。

MY QUESTION所以,我的问题是有什么方法可以订阅使用JavaScript的Chrome浏览器(用于网页)的GCM主题吗?如果有,那么该怎么做? 解决方案

网络推送不支持GCM主题。原因可能与即将增加有效载荷需要使用不同的密钥加密每个用户。



所以我恐怕你被困在2)。这当然取决于您有多少用户,但请记住,如果您要使用主题,则可以立即向数百万人发送消息,从而确保当前状态。在收到消息后,所有这些用户都将回复回您的站点以获取显示通知所需的信息,这样如果话题被很多人使用,您可能冒着DOS的风险。以1000个组为单位进行分组有助于限制传入流量。

Here is a nice documentation on how to implement Google Cloud Messaging (GCM) in Chrome. But I do not found any reference here or anywhere how to subscribe to a topic using javascript (for Chrome).

Here I have found a reference how to do the task for Android: https://developers.google.com/cloud-messaging/topic-messaging#subscribe-to-a-topic

Java code(Android) for subscribe to a topic in GCM:

private void subscribeTopics(String token) throws IOException {
    GcmPubSub pubSub = GcmPubSub.getInstance(this);
    for (String topic : TOPICS) {
        pubSub.subscribe(token, "/topics/" + topic, null);
    }
}

WHAT I AM NOT LOOKING FOR

I am NOT looking ways for Chrome app/Extension.

WHAT DO I WANT

I want to send push notification to all my users. So far I know this can be achievable in two ways:

  1. Push message to a topic
  2. Or I have to: "You need to send the list of reg id of devices and also this list should not exceed 1000 this is a limitation of GCM if you want to send message to more than 1000 devices then you need to break the list in chunks of 1000."

I want to avoid point number 2.

MY QUESTION

So, My question is is there any way to subscribe to a topic for GCM using Javascript for Chrome browser (for web pages)? If there, then how to do that?

解决方案

GCM topics are not supported by web push. The reason is likely to be related to the upcoming addition of payloads which are required to be encrypted with a different key per user.

So I'm afraid you are stuck with 2). This of course depends on how many users you have but keep in mind that with the current state of affairs you could be instantly sending a message to millions of people if you were to be using topics. Upon receiving the message all those users would be "https-ing" back to your site to fetch the information needed to display the notification so you run the risk of DOSing yourself if the topic were to be used by lot's of people. Batching in groups of 1000 helps throttling the incoming traffic.

这篇关于如何从javascript注册GCM主题(适用于Chrome)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆