How to use the node-gcm.Sender function in node-gcm

To help you get started, we’ve selected a few node-gcm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gokulkrishh / demo-progressive-web-app / server.js View on Github external
app.post('/send_notification', function (req, res) {
  if (!req.body) {
    res.status(400);
  }

  var message = new gcm.Message();
  var temp = req.body.endpoint.split('/');
  var regTokens = [temp[temp.length - 1]];

  var sender = new gcm.Sender('AIzaSyCjrU5SqotSg2ybDLK_7rMMt9Rv0dMusvY'); //Replace with your GCM API key

  // Now the sender can be used to send messages
  sender.send(message, { registrationTokens: regTokens }, function (error, response) {
  	if (error) {
      console.error(error);
      res.status(400);
    }
  	else {
     	console.log(response);
      res.status(200);
    }
  });
});
github hemanth / generator-pwa / generators / app / templates / server.js View on Github external
app.post('/send_notification', function (req, res) {
  if (!req.body) {
    res.status(400);
  }

  var message = new gcm.Message();
  var temp = req.body.endpoint.split('/'); //End point send from client
  var regTokens = [temp[temp.length - 1]];

  var sender = new gcm.Sender("<%= apiKey %>"); //API key

  // Now the sender can be used to send messages
  sender.send(message, { registrationTokens: regTokens }, function (error, response) {
  	if (error) {
      console.error(error);
      res.status(400);
    }
  	else {
     	console.log(response);
      res.status(200);
    }
  });
});
github unicodeveloper / pwa-api / server / controllers / notification.server.controller.js View on Github external
notifyUsers: function(req, res){

    var sender = new gcm.Sender(secrets.fcm);

    // Prepare a message to be sent
    var message = new gcm.Message({
        notification: {
          title: "Hello, World",
          icon: "ic_launcher",
          body: "Click to see the latest commit"
        }
    });

    User.find({}, function(err, users) {

      // user subscription ids to deliver message to
      var user_ids = _.map(users, 'user_id');

      console.log("User Ids", user_ids);
github kaplanmaxe / push-notification-test-tool / dist / push / android.js View on Github external
return new Promise(function (resolve, reject) {
        var registrationTokens = (typeof tokens === 'undefined' ? 'undefined' : _typeof(tokens)) === 'object' ? tokens : [tokens];
        var sender = new _nodeGcm.Sender(config.androidSenderAPIKey);
        var notification = Android.genMessage(body.title, body.message, body.payload, config.bundle);
        sender.send(notification, { registrationTokens: registrationTokens }, function (err) {
          if (err) reject(err);else resolve();
        });
      });
    }
github kaplanmaxe / push-notification-test-tool / src / push / android.js View on Github external
return new Promise((resolve, reject) => {
      const registrationTokens = typeof tokens === 'object' ? tokens : [tokens];
      const sender = new Sender(config.androidSenderAPIKey);
      const notification = Android.genMessage(
        body.title,
        body.message,
        body.payload,
        config.bundle
      );
      sender.send(notification, { registrationTokens }, err => {
        if (err) reject(err);
        else resolve();
      });
    });
  }
github rohansapre / cleanhood / Web / server / services / event.service.server.js View on Github external
function sendNotifications(registrationTokens) {
        var message = new gcm.Message();
        message.addData({
            key1: 'Welcome to push notification',
            key2: 'How do you feel now?'
        });

        var sender = new gcm.Sender(process.env.GOOGLE_API_KEY);

        sender.send(message, { registrationTokens: registrationTokens }, function (err, response) {
            if(err)
                console.log(err);
            else
                console.log(response);
        });
    }
github NextCenturyCorporation / EVEREST / gcm / gcm.js View on Github external
this.sendEvent = function(title, id, gid){
	console.log("Sending GCM message about "+title);
    var message = new gcm.Message();
    var sender = new gcm.Sender(config.gcmApiKey);
    var ids = [];
    
    //Add the title and ID data
    message.addData('title', title);
    message.addData('id', id);
    //This allows the GCM servers to deliver only 1 message per key if a device is offline or something
    message.collapseKey = 'gid'+gid;
    //Not sure what unit this is, but 2 sounds like a good choice
    message.timeToLive = 2;
    
    //Need to get all the IDs now, up to 1000 at a time
    if(config.noDB){
        for(var i = 0; i < registeredIds.length && i < 1000; i++){
            ids.push(registeredIds[i].registrationId);
        }
        sender.send(message, ids, 5, function(result){
github fredericbarrau / pushserver / app / lib / gcm-push.js View on Github external
GcmPushManager.prototype.connect = function() {
    debug('GCM : connecting to GCM platform using ', this.application);
    if (this.application === null) {
      throw "GcmPushManager : an application object must be provided.";
    }
    this.service = new gcm.Sender(this.application.key);
    debug('GCM : connection established using ', this.service);
  };
  /**
github xpush / node-xpush / lib / mobile / gcm.js View on Github external
var Gcm = exports.Gcm = function (api_key) {
  this.sender = new nodegcm.Sender(api_key); 
};

node-gcm

Easy interface for Google's Cloud Messaging service (now Firebase Cloud Messaging)

MIT
Latest version published 3 months ago

Package Health Score

74 / 100
Full package analysis

Popular node-gcm functions