Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge upstream #12

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
aa79f76
adds mutableContent doku entry
Oct 20, 2018
2fd89a1
removes duplicate line
Oct 22, 2018
4b74526
Merge pull request #328 from tomsvogel/master
eladnava Oct 23, 2018
1816786
Update example to find "bad" tokens
sidhantpanda Jun 2, 2019
8bae681
Merge pull request #333 from sidhantpanda/patch-1
hypesystem Jul 18, 2019
8256971
Update broken links in README
eladnava Nov 12, 2019
05ebebd
Rename occurrences of GCM to FCM in README
eladnava Nov 12, 2019
adfd4b0
fix: Gcm InternalServerError should also be retied with exponential-b…
yog27ray Jan 14, 2020
4eeb2cc
added similar test cases.
yog27ray Jan 14, 2020
33683d9
Add fcm_options as allowed params to message object
SpellChucker May 26, 2020
859625a
Update README with usage
SpellChucker May 28, 2020
e435347
Fix syntax of link
SpellChucker May 28, 2020
db66259
Merge pull request #342 from SpellChucker/add-fcm-options-message
eladnava May 28, 2020
456b0de
README: Fix formatting of `fcm_options` param doc
eladnava May 28, 2020
2390554
Fix package.json: remove trailing comma in contributor list
Jul 6, 2020
6c77b95
Add unit tests for uri override
Jul 6, 2020
fcb8d8c
Move options.uri to overridable section
Jul 6, 2020
6d0bcc6
Merge pull request #345 from pertu/allow-uri-override
eladnava Jul 9, 2020
cbb1115
1.0.2
eladnava Jul 9, 2020
4bec224
1.0.3
eladnava Jul 9, 2020
2b82cac
use [email protected]
marneborn Jan 20, 2021
29bb027
upgrade lodash
marneborn Jan 20, 2021
dc80fc5
Merge pull request #337 from yog27ray/internalServer
ToothlessGear Feb 23, 2021
72a883f
Merge pull request #349 from marneborn/upgrade-request
ToothlessGear Feb 23, 2021
31e89bd
1.0.4
ToothlessGear Feb 23, 2021
69fe799
Merge remote-tracking branch 'upstream/master' into merge-upstream
mtrezza Aug 26, 2021
5352775
rebuilt package-lock
mtrezza Aug 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ $ npm install node-gcm --save

## Requirements

This library provides the server-side implementation of GCM.
You need to generate an [API Key](https://developers.google.com/cloud-messaging/gcm#apikey).
This library provides the server-side implementation of FCM.
You need to generate an [API Key](https://console.firebase.google.com/u/0/) (Click the gear next to FCM project name) > Project Settings > Cloud Messaging -> **Server Key**).

GCM notifications can be sent to both [Android](https://developers.google.com/cloud-messaging/android/start) and [iOS](https://developers.google.com/cloud-messaging/ios/start).
If you are new to GCM you should probably look into the [documentation](https://developers.google.com/cloud-messaging/gcm).
FCM notifications can be sent to both [Android](https://firebase.google.com/docs/cloud-messaging/android/client) and [iOS](https://firebase.google.com/docs/cloud-messaging/ios/client).
If you are new to FCM you should probably look into the [documentation](https://firebase.google.com/docs/cloud-messaging).

## Example application

Expand Down Expand Up @@ -128,14 +128,11 @@ sender.send(message, { registrationTokens: registrationTokens }, 10, function (e
else console.log(response);
});

// Q: I need to remove all "bad" token from my database, how do I do that?
// Q: I need to remove all "bad" token from my database, how do I do that?
// The results-array does not contain any tokens!
// A: The array of tokens used for sending will match the array of results, so you can cross-check them.
sender.send(message, { registrationTokens: registrationTokens }, function (err, response) {
var failed_tokens = response.results // Array with result for each token we messaged
.map((res, i) => res.error ? registrationTokens[i] : null) // If there's any kind of error,
// pick _the token_ from the _other_ array
.filter(token => token); // Remove all the null values
sender.send(message, { registrationTokens: registrationTokens }, function (err, response) {
var failed_tokens = registrationTokens.filter((token, i) => response[i].error != null);
console.log('These tokens are no longer ok:', failed_tokens);
});
```
Expand All @@ -146,7 +143,7 @@ You can send push notifications to various recipient types by providing one of t

|Key|Type|Description|
|---|---|---|
|to|String|A single [registration token](https://developers.google.com/cloud-messaging/android/client#sample-register), [notification key](https://developers.google.com/cloud-messaging/notifications), or [topic](https://developers.google.com/cloud-messaging/topic-messaging).
|to|String|A single [registration token](https://firebase.google.com/docs/cloud-messaging/android/client#sample-register), [notification key](https://firebase.google.com/docs/cloud-messaging/android/device-group), or [topic](https://firebase.google.com/docs/cloud-messaging/android/topic-messaging).
|topic|String|A single publish/subscribe topic.
|condition|String|Multiple topics using the [condition](https://firebase.google.com/docs/cloud-messaging/topic-messaging) parameter.
|notificationKey|String|Deprecated. A key that groups multiple registration tokens linked to the same user.
Expand All @@ -156,7 +153,7 @@ You can send push notifications to various recipient types by providing one of t
If you provide an incorrect recipient key or object type, an `Error` object will be returned to your callback.

Notice that [you can *at most* send notifications to 1000 registration tokens at a time](https://github.com/ToothlessGear/node-gcm/issues/42).
This is due to [a restriction](http://developer.android.com/training/cloudsync/gcm.html) on the side of the GCM API.
This is due to [a restriction](https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json) on the side of the FCM API.


### Additional message options
Expand All @@ -166,11 +163,13 @@ This is due to [a restriction](http://developer.android.com/training/cloudsync/g
|collapseKey|Optional, string|This parameter identifies a group of messages that can be collapsed, so that only the last message gets sent when delivery can be resumed.|
|priority|Optional, string|Sets the priority of the message. Valid values are "normal" and "high."|
|contentAvailable|Optional, JSON boolean|On iOS, when a notification or message is sent and this is set to true, an inactive client app is awoken.|
|timeToLive|Optional, JSON number|This parameter specifies how long (in seconds) the message should be kept in GCM storage if the device is offline. The maximum time to live supported is 4 weeks, and the default value is 4 weeks.|
|mutableContent|Optional, JSON boolean|On iOS, Currently for iOS 10+ devices only. On iOS, use this field to represent mutable-content in the APNs payload. When a notification is sent and this is set to true, the content of the notification can be modified before it is displayed, using a Notification Service app extension.|
|timeToLive|Optional, JSON number|This parameter specifies how long (in seconds) the message should be kept in FCM storage if the device is offline. The maximum time to live supported is 4 weeks, and the default value is 4 weeks.|
|restrictedPackageName|Optional, string|This parameter specifies the package name of the application where the registration tokens must match in order to receive the message.|
|dryRun|Optional, JSON boolean|This parameter, when set to true, allows developers to test a request without actually sending a message.|
|data|Optional, JSON object|This parameter specifies the custom key-value pairs of the message's payload.|
|notification|Optional, JSON object|This parameter specifies the predefined, user-visible key-value pairs of the notification payload. See "Notification payload option table" below for more details.|
|fcm_options|Optional, JSON object|This parameter is used to pass FCM specific options, as outlined [here](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#FcmOptions).

## Notification usage

Expand Down Expand Up @@ -211,11 +210,11 @@ message.addNotification({
|title_loc_args|iOS|Optional, JSON array as string|Indicates the string value to replace format specifiers in title string for localization. On iOS, this corresponds to "title-loc-args" in APNS payload.|
|title_loc_key|iOS|Optional, string|Indicates the key to the title string for localization. On iOS, this corresponds to "title-loc-key" in APNS payload.|

Notice notification payload defined in [GCM Connection Server Reference](https://developers.google.com/cloud-messaging/server-ref#table1)
Notice notification payload defined in [FCM Connection Server Reference](https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json)

## Custom HTTP request options

You can provide custom `request` options such as `proxy` and `timeout` for the HTTP request to the GCM API. For more information, refer to [the complete list of request options](https://github.com/request/request#requestoptions-callback). Note that the following options cannot be overriden: `method`, `uri`, `body`, as well as the following headers: `Authorization`, `Content-Type`, and `Content-Length`.
You can provide custom `request` options such as `proxy` and `timeout` for the HTTP request to the FCM API. For more information, refer to [the complete list of request options](https://github.com/request/request#requestoptions-callback). Note that the following options cannot be overriden: `method`, `uri`, `body`, as well as the following headers: `Authorization`, `Content-Type`, and `Content-Length`.

```js
// Set custom request options
Expand All @@ -236,9 +235,9 @@ sender.send(message, { registrationTokens: regTokens }, function (err, response)
});
```

## GCM client compatibility
## FCM client compatibility

As of January 9th, 2016, there are a few known compatibility issues with 3rd-party GCM client libraries:
As of January 9th, 2016, there are a few known compatibility issues with 3rd-party FCM client libraries:

### phonegap-plugin-push

Expand All @@ -250,7 +249,7 @@ These issues are out of this project's context and can only be fixed by the resp

## Debug

To enable debug mode (print requests and responses to and from GCM),
To enable debug mode (print requests and responses to and from FCM),
set the `DEBUG` environment flag when running your app (assuming you use `node app.js` to run your app):

```bash
Expand Down
9 changes: 6 additions & 3 deletions lib/message-options.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* This module defines all the arguments that may be passed to a message.
*
*
* Each argument may contain a field `__argName`, if the name of the field
* should be different when sent to the server.
*
*
* The argument may also contain a field `__argType`, if the given
* argument must be of that type. The types are the strings resulting from
* calling `typeof <arg>` where `<arg>` is the argument.
*
*
* Other than that, the arguments are expected to follow the indicated
* structure.
*/
Expand Down Expand Up @@ -51,5 +51,8 @@ module.exports = {
__argType: "object"
//TODO: There are a lot of very specific arguments that could
// be indicated here.
},
fcm_options: {
__argType: "object"
}
};
2 changes: 1 addition & 1 deletion lib/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ Sender.prototype.sendNoRetry = function(message, recipient, callback) {
headers: {
'Authorization': 'key=' + this.key
},
uri: Constants.GCM_SEND_URI,
json: body
}, this.options, {
uri: Constants.GCM_SEND_URI,
timeout: Constants.SOCKET_TIMEOUT
});

Expand Down
Loading