Comparing version 0.9.11 to 0.9.12
@@ -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; |
115
package.json
{ | ||
"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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
19079
274
205
0
2
+ Addeddebug@^0.8.1
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddebug@0.8.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.9.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
- Removedasn1@0.1.11(transitive)
- Removedassert-plus@0.1.5(transitive)
- Removedasync@0.9.2(transitive)
- Removedaws-sign@0.3.0(transitive)
- Removedboom@0.4.2(transitive)
- Removedcombined-stream@0.0.7(transitive)
- Removedcookie-jar@0.3.0(transitive)
- Removedcryptiles@0.2.2(transitive)
- Removedctype@0.5.3(transitive)
- Removeddelayed-stream@0.0.5(transitive)
- Removedforever-agent@0.5.2(transitive)
- Removedform-data@0.1.4(transitive)
- Removedhawk@1.0.0(transitive)
- Removedhoek@0.9.1(transitive)
- Removedhttp-signature@0.10.1(transitive)
- Removedmime@1.2.11(transitive)
- Removednode-uuid@1.4.8(transitive)
- Removedoauth-sign@0.3.0(transitive)
- Removedqs@0.6.6(transitive)
- Removedrequest@2.27.0(transitive)
- Removedsntp@0.2.4(transitive)
- Removedtunnel-agent@0.3.0(transitive)
Updatedrequest@^2.27.0