Comments (9)
If anyone else needs to support more than 1,000 devices, you can easily split the tokens up into batches like this:
// Max devices per request
var batchLimit = 1000;
// Batches will be added to this array
var tokenBatches = [];
// Traverse tokens and split them up into batches of 1,000 devices each
for (var start = 0; start < tokens.length; start += batchLimit) {
// Get next 1,000 tokens
var slicedTokens = tokens.slice(start, start + batchLimit);
// Add to batches array
tokenBatches.push(slicedTokens);
}
// You can now send a push to each batch of devices, in parallel, using the caolan/async library
async.each(batches, function (batch, callback) {
// Assuming you already set up the sender and message
sender.send(message, { registrationIds: batch }, function (err, result) {
// Push failed?
if (err) {
// Stop executing other batches
return callback(err);
}
// Done with batch
callback();
});
},
function (err) {
// Log the error to console
if (err) {
console.log(err);
}
});
from node-gcm.
You'll have to split your ID's beforehand, as node-gcm doesn't do that for you automatically yet.
from node-gcm.
Perfect. Thanks!
On 30 Jan 2014, at 16:26, Marcus Farkas [email protected] wrote:
You'll have to split your ID's beforehand, as node-gcm doesn't do that for you automatically yet.
—
Reply to this email directly or view it on GitHub.
from node-gcm.
I wrote parallel-batch which does pretty much that: https://www.npmjs.com/package/parallel-batch
from node-gcm.
Nice package! Would greatly simplify the code I wrote.
from node-gcm.
@hypesystem maybe it would be a good idea to integrate your parallel-batch library into node-gcm, so that batching will be performed automagically?
from node-gcm.
I agree, that was the original intention with parallel-batch. As it turns out, though, it's easier said than done.
Specifically we want to return errors correctly (as if no batching happened; so if only some of the batches fail, some of the messages will still (possibly) be sent); and we want to handle retries the way the user expects (which is also hard).
from node-gcm.
I think it's doable -- in case one of the batches failed, we'll retry it until we run out of tries
. We just have to make sure that GCM doesn't deliver the push notification to some devices in the batch while erroring out -- that would cause some serious spamming. But in any case, it could be happening today with < 1,000 devices in sender.send
.
from node-gcm.
I would love to see you give it a try. First of all, though, I think we need a new issue to discuss this -- feel free to create it.
I will try to gather my thoughts on what behaviour I think we would want, and why, exactly, it is tricky :-)
from node-gcm.
Related Issues (20)
- Address deprecation of request package HOT 2
- How to add analytics label to message? HOT 5
- Unable to send push to browser(firefox, chrome) always getting InvalidRegistration HOT 4
- Make send URI configurable HOT 1
- fcm_options and analytics_label fields are not sent to FCM servers? HOT 2
- TypeError: Cannot read property 'error' of undefined failed_tokens example HOT 1
- Not receiving notifications - ios HOT 2
- Add snyk to fix vulnerabilities faster HOT 15
- Add missing GitHub releases and version tags
- Add CI to require passing tests before release HOT 2
- didReceiveRemoteNotification:fetchCompletionHandler not called. HOT 6
- readme error in failedTokens snippets HOT 1
- Removing no longer valid FCM tokens HOT 1
- Add release automation HOT 2
- Support for Google Service Accounts authorization HOT 2
- Firebase Legacy HTTP API discontinued by June 20, 2024 HOT 12
- request package security issue. HOT 3
- Handle non-HTTP errors HOT 1
- Handle all HTTP errors
- Migration from legacy FCM to HTTP v1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-gcm.