Open davidvavra opened 8 years ago
Hi @davidvavra, This is definitely made possible by node-gcm.
Check out this great example by @hypesystem.
Yes I know it's possible. But it's not easy - developer needs to understand the concepts from the official documentation and write some non-trivial logic to detect which registrationIds to replace and which to remove. The library could make developer's life easier and provide two clear callbacks.
Definitely not something we considered before, but interesting nonetheless.
@hypesystem what do you think about this?
I am implementing GCM now and this is something I was looking for in the documentation (similar to https://github.com/argon/node-apn).
A simple example on how you could collect the "bad tokens"
const userTokens = [ /* we're sending to these tokens */ ];
const results = response.results; // callback from .send()
const collectBadTokens = (userTokens, results) =>
results.filter(({ error }) => !!error)
.map((_, i) => userTokens[i]);
This issue needs to be documented, it's kind of silly that you have to dig through the issues to find it.
Thanks @johanforssell for the example code. I think you're right, we can easily add this to the main README. What do you think @hypesystem?
Here's a PR for a change of documentation: https://github.com/ToothlessGear/node-gcm/pull/323
Well my intention was that "get bad tokens" would be part of the library API and people won't have to implement it, since everybody who uses the library has to do it. But a documented way is definitely an improvement.
To be honest, a built-in way would be great :smile: if you feel like doing a PR on it, @davidvavra, we would definitely merge!
According to GCM documentation, implementations of GCM server should replace or remove some registrationTokens from database in some cases like when the app was uninstalled from user's phone. I looked in the code and the information is hidden in the response object. It would be great if the developer can get a simple callback "replace these regTokens with these" and "remove these regTokens"