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