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

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

问题描述

这里是关于如何实现的很好的文档Chrome 中的 Google 云消息传递 (GCM).但我在这里或任何地方都没有找到任何参考如何使用 javascript(用于 Chrome)订阅主题.

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).

在这里,我找到了如何为 Android 执行任务的参考:https://developers.google.com/cloud-messaging/topic-messaging#subscribe-to-a-topic

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

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

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);
    }
}

我不想要的东西

我不是在寻找 Chrome 应用程序/扩展程序的方法.

I am NOT looking ways for Chrome app/Extension.

我想要什么

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

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

  1. 向主题推送消息
  2. 或者我必须:您需要发送设备的 reg id 列表,并且此列表不应超过 1000,这是 GCM 的限制,如果您想向超过 1000 个设备发送消息,那么您需要中断以 1000 个为单位的列表."

我想避开第 2 点.

我的问题

所以,我的问题是有没有办法使用 Javascript for Chrome 浏览器(用于网页)订阅 GCM 的主题?如果有,那该怎么做呢?

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?

推荐答案

Web 推送不支持 GCM 主题.原因很可能与即将添加的 payloads 需要为每个用户使用不同的密钥进行加密.

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.

所以我担心你会被 2) 困住.这当然取决于您拥有多少用户,但请记住,如果您要使用主题,您可能会立即向数百万人发送消息.收到消息后,所有这些用户都会https-ing"返回您的站点以获取显示通知所需的信息,因此如果该主题要被很多人使用,您将冒着 DOSing 自己的风险.以 1000 个为一组进行批处理有助于限制传入流量.

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天全站免登陆