// Method to generate manager with Q promises
function getFcmManager () {
var serverKey = API_KEY;
var fcm = new FCM(serverKey);
// Manager
var fcmManager = {
// Send to device holding token
send: function (token) {
return Q.Promise(function (resolve, reject) {
// Message payload
var message = {
"notification":{
"title": "Notification title", //Any value
"body": "Notification body", //Any value
"sound": "default", //If you want notification sound
"click_action": "FCM_PLUGIN_ACTIVITY", //Must be present for Android
"icon": "fcm_push_icon" //White icon Android resource
},
"data":{
"param1": "value1", //Any data to be retrieved in the notification callback
"param2": "value2"
},
"to": token, //Topic or single device
"priority": "high", //If not set, notification won't be delivered on completely closed iOS app
"restricted_package_name": "" //Optional. Set for application filtering
};
// Push
fcm.send(message, function(err, response){
if (err) {
console.log("FCM: Something has gone wrong!", err);
reject();
} else {
console.log("FCM: Successfully sent with response: ", response);
resolve();
}
});
});
}
}
// Return
return fcmManager;
}