From bf69d0a0bec0ae1eed6be536ad70b9fb6b690b2b Mon Sep 17 00:00:00 2001 From: Neamar Date: Thu, 30 Nov 2017 20:18:41 +0100 Subject: [PATCH 1/2] Handle concurrency properly (fix #7) --- lib/gcm.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/gcm.js b/lib/gcm.js index b8cccea..dd77c4a 100644 --- a/lib/gcm.js +++ b/lib/gcm.js @@ -3,6 +3,7 @@ var https = require('https'); var querystring = require('querystring'); var emitter = require('events').EventEmitter; var retry = require('retry'); +var noop = function() {}; function GCM(apiKey) { if (apiKey) { @@ -25,7 +26,6 @@ exports.GCM = GCM; GCM.prototype.send = function(packet, cb) { var self = this; - if (cb) this.once('sent', cb); var operation = retry.operation(); @@ -58,6 +58,8 @@ GCM.prototype.send = function(packet, cb) { } } if (!operation.retry('TemporaryUnavailable')) { + cb(operation.mainError(), null); + cb = noop; self.emit('sent', operation.mainError(), null); } // Ignore all subsequent events for this request @@ -84,6 +86,8 @@ GCM.prototype.send = function(packet, cb) { } // Success, return message id (without id=) + cb(error, id); + cb = noop; self.emit('sent', error, id); } @@ -94,6 +98,8 @@ GCM.prototype.send = function(packet, cb) { res.on('close', respond); }); request.on('error', function(error) { + cb(error, null); + cb = noop; self.emit('sent', error, null); }); request.end(postData); From e43a3288c3b31afd7ab839d8d8cb25b2c0da3bab Mon Sep 17 00:00:00 2001 From: Neamar Date: Wed, 3 Apr 2019 22:33:27 +0100 Subject: [PATCH 2/2] Updated endpoints to use fcm --- lib/gcm.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gcm.js b/lib/gcm.js index dd77c4a..5b17c8d 100644 --- a/lib/gcm.js +++ b/lib/gcm.js @@ -12,9 +12,9 @@ function GCM(apiKey) { throw Error('No apiKey is given.'); } this.gcmOptions = { - host: 'android.googleapis.com', + host: 'fcm.googleapis.com', port: 443, - path: '/gcm/send', + path: '/fcm/send', method: 'POST', headers: {} };