How to use node-gcm - 10 common examples

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 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 HabitRPG / habitrpg-email-server / libs / pushNotifications.js View on Github external
pushDevices.forEach(pushDevice => {
    switch (pushDevice.type) {
      case 'android':
        // Required for fcm to be received in background
        payload.title = details.title;
        payload.body = details.message;

        if (fcmSender) {
          var message = new gcmLib.Message({
            data: payload,
          });

          fcmSender.send(message, {
            registrationTokens: [pushDevice.regId],
          }, 10, (err) => {
            if (err) console.log('FCM Error', err);
          });
        }
        break;

      case 'ios':
        if (apn) {
          apn.send({
            token: pushDevice.regId,
            alert: details.message,
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 codeforseoul / FdAS / server / push-provider.js View on Github external
// 	cert: '',
// 	key: ''
// });

// var iosDevice = new apn.Device('token');
// var note = new apn.Notification();
// note.badge = 3;
// note.sound = "ping.aiff";
// note.alert = send_txt;
// note.payload = {'messageFrom': 'FdAS'};


/* android */
var registrationIds = [];
var sender = new gcm.Sender('AIzaSyACRdFNYuZauygD-hhJG3rFiavqjz4ilPs'); // server key
var message = new gcm.Message({
    collapseKey: 'demo',
    delayWhileIdle: true,
    timeToLive: 3,
    data: {
        key1: send_txt
    }
});


// get push list
// TODO, model 인식 안됨
var userModel = app.models.pushkey || loopback.getModelByType(app.models.pushkey);

userModel.find({}, function(err, lists){
	var len = lists.length;
github appfeel / node-pushnotifications / src / sendGCM.js View on Github external
} else {
    custom = {
      data: data.custom,
    };
  }

  custom.title = custom.title || data.title;
  custom.message = custom.message || data.body;
  custom.sound = custom.sound || data.sound;
  custom.icon = custom.icon || data.icon;
  custom.msgcnt = custom.msgcnt || data.badge;
  if (opts.phonegap === true && data.contentAvailable) {
    custom['content-available'] = 1;
  }

  const message = new gcm.Message({
    // See https://developers.google.com/cloud-messaging/http-server-ref#table5
    collapseKey: data.collapseKey,
    priority: data.priority === 'normal' ? data.priority : 'high',
    contentAvailable: data.contentAvailable || false,
    delayWhileIdle: data.delayWhileIdle || false,
    timeToLive: extractTimeToLive(data),
    restrictedPackageName: data.restrictedPackageName,
    dryRun: data.dryRun || false,
    data: opts.phonegap === true ? Object.assign(custom, notification) : custom, // See https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#android-behaviour
    notification: opts.phonegap === true ? undefined : notification,
  });
  let chunk = 0;

  // Split in 1.000 chunks, see https://developers.google.com/cloud-messaging/http-server-ref#table1
  do {
    const tokens = regIds.slice(chunk * 1000, (chunk + 1) * 1000);
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 nahuelcandia / mobile-app-maker / plugins / push-notif / index.js View on Github external
shovelMessenger.prototype.sendMessage = function(msgOptions) {
  var _this = this;

  //gcm
  //preparo el mensaje
  var message = new gcm.Message({
    collapseKey: __('New Notifications'),
    delayWhileIdle: true,
    timeToLive: 3,
    data: {
      message: msgOptions.message,
      title: msgOptions.title,
      timeStamp: new Date().toISOString(),
      sound: msgOptions.sound
    }
  });

  _this.gcmSender.send(message, _this.regIdsGcm, 4, function(err, result) {
    console.log(err);
    console.log(result);
  });

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