Skip to content

Instantly share code, notes, and snippets.

@yutin1987
Last active August 29, 2015 14:21
Show Gist options
  • Save yutin1987/974645fa8854092bd280 to your computer and use it in GitHub Desktop.
Save yutin1987/974645fa8854092bd280 to your computer and use it in GitHub Desktop.
GCM send
'use strict';
var gcm = require('node-gcm');
var promise = require('bluebird');
var senderId = ''; // setting sender Id
var sendGCM = function(registrationIds, alert) {
return new promise(function(resolve, reject) {
var message = new gcm.Message({
collapseKey: Date.now() + '',
data: {
alert: alert
}
});
var rIds;
if (Array.isArray(rIds)) {
rIds = registrationIds;
} else {
rIds = [registrationIds];
}
var sender = new gcm.Sender(senderId);
return sender.send(message, rIds, 4, function(err, result) {
if (err) {
return reject(err);
} else {
return resolve(result);
}
});
});
};
sendGCM(
'APA91bG3ErE3IcNXkPy86MQo_tKjvHbwv0j2KTKX2Ox7fj5f9vggI0lUtyfUS4qJeL-BSwgxd3V39Od3j6_daPQdWmOjVzeaAFJzygjD6F26smAWq9oWV8N2bhxjCFuFAOsaXJwb8SycbPfJGm7hJqxaBqY1uVLyog',
'Hello World 123'
).catch(function(error) {
console.log(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment