ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 206 forks source link

Improved support for unicast messaging (sending to one device) #191

Closed eladnava closed 8 years ago

eladnava commented 8 years ago

As per @alemonmk's suggestion in #187, when supplying a single registration token inside an array, we should set the to property and not the registration_ids property, so that the push notification will be sent as a unicast message, which is encouraged by the GCM documentation.

To achieve this, I added a check for a single-element array inside sendNoRetry.

The response from the GCM server is identical for unicast and multicast messages.

Also, added the following tests to check for correct utilization of the to GCM request property:

@hypesystem Please confirm. =)

hypesystem commented 8 years ago

This looks great! :smile:

hypesystem commented 8 years ago

Good that you removed the "if-string-wrap-in-array" branch, makes the code easier to understand :smile:

appleboy commented 8 years ago

:+1:

eladnava commented 8 years ago

Thanks!