Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get registered into GCM topics from javascript (for 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).

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?

like image 327
Mehdi Avatar asked Oct 19 '22 16:10

Mehdi


1 Answers

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.

like image 169
Miguel Garcia Avatar answered Nov 01 '22 11:11

Miguel Garcia