Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-gcm

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-gcm - npm Package Compare versions

Comparing version 0.9.11 to 0.9.12

80

lib/sender.js

@@ -7,16 +7,12 @@ /*!

var Constants = require('./constants');
var Result = require('./result');
var req = require('request');
var debug = require('debug')('node-gcm');
var https = require('https');
var timer = require('timers');
var req = require('request')
function Sender(key , options) {
this.key = key;
this.options = options ;
this.options = options;
}
var sendNoRetryMethod = Sender.prototype.sendNoRetry = function (message, registrationIds, callback) {
Sender.prototype.sendNoRetry = function(message, registrationIds, callback) {
var body = {},
result = new Result(),
requestBody,

@@ -58,9 +54,13 @@ post_options,

if(this.options && this.options.proxy){
if (this.options && this.options.proxy) {
post_options.proxy = this.options.proxy;
}
if (this.options && this.options.maxSockets) {
post_options.maxSockets = this.options.maxSockets;
}
timeout = Constants.SOCKET_TIMEOUT;
if(this.options && this.options.timeout){
if (this.options && this.options.timeout) {
timeout = this.options.timeout;

@@ -73,16 +73,18 @@ }

if (err)
if (err) {
return callback(err, null);
if (!res)
}
if (!res) {
return callback('response is null', null);
}
if (res.statusCode >= 500) {
console.log('GCM service is unavailable');
debug('GCM service is unavailable');
return callback(res.statusCode, null);
} else if(res.statusCode == 401){
console.log('Unauthorized');
} else if (res.statusCode === 401) {
debug('Unauthorized');
return callback(res.statusCode, null);
} else if (res.statusCode !== 200) {
console.log('Invalid request: ' + res.statusCode);
debug('Invalid request: ' + res.statusCode);
return callback(res.statusCode, null);

@@ -93,6 +95,7 @@ }

// handling the response.
var data = null;
try {
var data = JSON.parse(resBody);
data = JSON.parse(resBody);
} catch (e) {
console.log("Error handling GCM response " + e);
debug("Error handling GCM response " + e);
return callback("error", null);

@@ -104,6 +107,7 @@ }

Sender.prototype.send = function (message, registrationId, retries, callback) {
Sender.prototype.send = function(message, registrationId, retries, callback) {
var attempt = 1,
backoff = Constants.BACKOFF_INITIAL_DELAY;
var attempt = 0,
backoff = Constants.BACKOFF_INITIAL_DELAY,
self = this;

@@ -115,16 +119,18 @@ if (registrationId.length === 1) {

if (!result) {
if (attempt < retries) {
var sleepTime = backoff * 2 * attempt;
if (attempt < retries - 1) {
var sleepTime = Math.pow (2, attempt) * backoff;
if (sleepTime > Constants.MAX_BACKOFF_DELAY) {
sleepTime = Constants.MAX_BACKOFF_DELAY;
}
timer.setTimeout(function () {
sendNoRetryMethod(message, registrationId, lambda);
setTimeout(function () {
self.sendNoRetry(message, registrationId, lambda);
}, sleepTime);
} else {
console.log('Could not send message after ' + retries + ' attempts');
debug('Could not send message after ' + retries + ' attempts');
callback(err, result);
}
attempt += 1;
} else callback(err, result);
} else {
callback(err, result);
}
});

@@ -134,4 +140,4 @@ } else if (registrationId.length > 1) {

if (attempt < retries) {
var sleepTime = backoff * 2 * attempt,
if (attempt < retries - 1) {
var sleepTime = Math.pow (2, attempt) * backoff,
unsentRegIds = [],

@@ -154,3 +160,3 @@ i;

if (err) {
unsentRegIds = registrationId
unsentRegIds = registrationId;
}

@@ -160,10 +166,12 @@

if (registrationId.length !== 0) {
timer.setTimeout(function () {
sendNoRetryMethod(message, registrationId, lambda);
setTimeout(function () {
self.sendNoRetry(message, registrationId, lambda);
}, sleepTime);
attempt += 1;
} else callback(err, result);
} else {
callback(err, result);
}
} else {
console.log('Could not send message to all devices after ' + retries + ' attempts');
debug('Could not send message to all devices after ' + retries + ' attempts');
callback(err, result);

@@ -173,3 +181,3 @@ }

} else {
console.log('No RegistrationIds given!');
debug('No RegistrationIds given!');
callback('No RegistrationIds given!', null);

@@ -179,2 +187,2 @@ }

module.exports = Sender;
module.exports = Sender;
{
"name": "node-gcm",
"description": "a Node.JS wrapper library-port for Google Cloud Messaging for Android",
"version": "0.9.11",
"version": "0.9.12",
"author": "Marcus Farkas <toothlessgear@finitebox.com>",
"contributors": [
{ "name": "Marcus Farkas", "email": "toothlessgear@finitebox.com" },
{ "name": "monkbroc", "email": "jvanier@gmail.com" },
{ "name": "zlyinfinite", "email": ""},
{ "name": "Yann Biancheri", "email": "yann.biancheri@gmail.com" },
{ "name": "Hamid Palo", "email": "hamid@fogcreek.com"},
{ "name": "Dotan J. Nahum", "email": "jondotan@gmail.com" },
{ "name": "Max Rabin", "email": "rabin.max@gmail.com" },
{ "name": "Olivier Poitrey", "email": "rs@dailymotion.com" },
{ "name": "George Miroshnykov", "email": "george.miroshnykov@gmail.com" },
{ "name": "Alejandro Garcia Gil", "email": "alejandro@ideaknow.com" },
{ "name": "Ismael Gorissen", "email": "ismael.gorissen@gmail.com" },
{ "name": "Joris Verbogt", "email": "joris@notifica.re" },
{ "name": "goelvivek", "email": "goelvivek2011@gmail.com" },
{ "name": "Lars Jacob", "email": "lars@jaclar.net" },
{ "name": "Roman Iakovlev", "email": "roman.iakovlev@here.com" },
{ "name": "Roman Skvazh", "email": "roman.skvazh@gmail.com" },
{ "name": "Jeremy Goldstein", "email": "jg-dev@live.com" },
{ "name": "Adam Patacchiola", "email": "adam@2fours.com" }
"contributors": [
{
"name": "Marcus Farkas",
"email": "toothlessgear@finitebox.com"
},
{
"name": "monkbroc",
"email": "jvanier@gmail.com"
},
{
"name": "zlyinfinite",
"email": ""
},
{
"name": "Yann Biancheri",
"email": "yann.biancheri@gmail.com"
},
{
"name": "Hamid Palo",
"email": "hamid@fogcreek.com"
},
{
"name": "Dotan J. Nahum",
"email": "jondotan@gmail.com"
},
{
"name": "Max Rabin",
"email": "rabin.max@gmail.com"
},
{
"name": "Olivier Poitrey",
"email": "rs@dailymotion.com"
},
{
"name": "George Miroshnykov",
"email": "george.miroshnykov@gmail.com"
},
{
"name": "Alejandro Garcia Gil",
"email": "alejandro@ideaknow.com"
},
{
"name": "Ismael Gorissen",
"email": "ismael.gorissen@gmail.com"
},
{
"name": "Joris Verbogt",
"email": "joris@notifica.re"
},
{
"name": "goelvivek",
"email": "goelvivek2011@gmail.com"
},
{
"name": "Lars Jacob",
"email": "lars@jaclar.net"
},
{
"name": "Roman Iakovlev",
"email": "roman.iakovlev@here.com"
},
{
"name": "Roman Skvazh",
"email": "roman.skvazh@gmail.com"
},
{
"name": "Jeremy Goldstein",
"email": "jg-dev@live.com"
},
{
"name": "Adam Patacchiola",
"email": "adam@2fours.com"
},
{
"name": "Ivan Longin",
"email": "ivan.longin@infobip.com"
},
{
"name": "Paul Bininda",
"email": "paul@bininda.com"
}
],

@@ -31,6 +93,15 @@ "repository": {

},
"keywords": ["google", "cloud", "push", "notifications", "android", "c2dm", "gcm"],
"keywords": [
"google",
"cloud",
"push",
"notifications",
"android",
"c2dm",
"gcm"
],
"main": "index",
"dependencies": {
"request": "2.27.x"
"request": "^2.27.0",
"debug": "^0.8.1"
},

@@ -37,0 +108,0 @@ "devDependencies": {},

@@ -75,2 +75,4 @@ # node-gcm

```
### Debug
For enabling debug mode set environment flag ```DEBUG=node-gcm```

@@ -107,2 +109,4 @@ ## Donate

* [Adam Patacchiola](https://github.com/surespot)
* [Ivan Longin](https://github.com/ilongin)
* [Paul Bininda](https://github.com/pbininda)

@@ -135,2 +139,13 @@ ## License

## Changelog
**0.9.12**
* added debug module and removed console-logs
* use exponential retry instead of linear
* update request module with most recent compatible one
* remove require on global timers
* various cleanups
* add maxSockets option
* keep 'this' on Sender object in retries
* updated README
* updated contributors
**0.9.11**

@@ -137,0 +152,0 @@ * check >= 500 error status

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc