node-gcm icon indicating copy to clipboard operation
node-gcm copied to clipboard

Create new topic, add subscribers to a topic

Open chirag200666 opened this issue 9 years ago • 5 comments

This is a feature request. It will be very useful to have the functionalities in the node-gcm packages as many people would want to use them :

  • Creation of a new topic
  • Subscribe a user to a topic using his token
  • get list of subscribed topics of a user.

chirag200666 avatar Feb 02 '16 20:02 chirag200666

Hi @chirag200666, Great call. We definitely want to implement these calls -- do you have any free time to help with this?

eladnava avatar Feb 02 '16 22:02 eladnava

Hi @eladnava , I am interested, I anyway have to implement for the project I am working on. I've been playing around with sails js, but not so comfortable with node, so some guidance would be appreciated.

chirag200666 avatar Feb 03 '16 00:02 chirag200666

After reading more I found :

  • There is no topic create API, a topic is automatically created when a user token is subscribed to a topic
  • There is an API call for adding one user token to one topic to create the subscription.
  • There is a second API method which takes a list of tokens, a topic and creates the subscription. The unsubscribe from topic API also works the same way.

https://developers.google.com/instance-id/reference/server

My Approach : I have created a Subscription model (Subscription.js file) similar to that of Sender. Which has two functions, first one to create a subscription which takes a token or a list of tokens & a topic. The second function takes a list of tokens and a topic to be unsubscribed.

I had a question: Should I implement the retry strategy we have in the Sender.js to the Subscription.js or it is not required.

chirag200666 avatar Feb 03 '16 08:02 chirag200666

Nice! Could you make a PR with your suggested addition, so we can continue the discussion there? That will allow us to talk about concrete code, which is often much easier than talking about concepts :smile:

I am not sure about the name, Subscription. If this functionality is only used for topics, maybe it should be called something more explicit, like TopicSubscriber?

The retry strategy we currently have in the Sender should actually be fixed to respect the Retry-After header we might get from GCM (see #94).

I think it would be a good idea for the topic subscription functionality to have retrying (and backoff) logic, too, but maybe we could extract that particular logic and reuse it in both the Sender and your new abstraction.

hypesystem avatar Feb 03 '16 12:02 hypesystem

I did an amateurish PR, want your inputs. https://github.com/ToothlessGear/node-gcm/pull/211

chirag200666 avatar Feb 06 '16 03:02 chirag200666