Closed imvishalsingh closed 8 years ago
Hi @vishaloban,
You have a lot of code and it is written quite messily, making it hard to give feedback. I would recommend that you try to live up to the DRY programming principle: Don't Repeat Yourself. You have the same code a lot of places, making it hard to maintain, let alone understand.
It looks like you have copied, ad verbatim, the overview of usage for node-gcm, without modifying the code for your purposes. Most interestingly, you have left in the field restrictedPackageName: "somePackageName"
, which means that only apps with the package name "restrictedPackageName"
can receive the notification.
Basically: you should modify the example code before using it. Remember to use the correct API key and actual registration Ids.
I am closing this issue as there are many other issues with the code than just those regarding to node-gcm, and it will likely lead to more confusion than help for others.
my server.js file code following
23 line set include gcm and set the api key 233 line start my send message function in 264 line number set the message body and perform the send function
var loopback = require('loopback'); var boot = require('loopback-boot');
var app = module.exports = loopback();
// Sub-apps like REST API are mounted via boot scripts. boot(app, __dirname);
app.start = function() { // start the web server return app.listen(function() { app.emit('started'); console.log('Web server listening at: %s', app.get('url')); }); };
var gcm = require('node-gcm');
var message = new gcm.Message();
// Set up the sender with you API key var sender = new gcm.Sender('MY Api key here');
var users = {}; var company = {}; var agent = {}; var msg = {}; var agentobj = {}; var lastagentid; var staticnew; var agentblock; // Bootstrap the application, configure models, datasources and middleware. // Sub-apps like REST API are mounted via boot scripts. // start the server if
$ node server.js
if (require.main === module) { //app.start(); app.io = require('socket.io')(app.start());});
}
var loopback = require('loopback'); var boot = require('loopback-boot');
var app = module.exports = loopback();
// Sub-apps like REST API are mounted via boot scripts. boot(app, __dirname);
app.start = function() { // start the web server return app.listen(function() { app.emit('started'); console.log('Web server listening at: %s', app.get('url')); }); };
var gcm = require('node-gcm');
var message = new gcm.Message();
// Set up the sender with you API key var sender = new gcm.Sender('AIzaSyD91AnA5zYRc-t621tkAAK8Gl2OSfOQwmo');
var users = {}; var company = {}; var agent = {}; var msg = {}; var agentobj = {}; var lastagentid; var staticnew; var agentblock; // Bootstrap the application, configure models, datasources and middleware. // Sub-apps like REST API are mounted via boot scripts. // start the server if
$ node server.js
if (require.main === module) { //app.start(); app.io = require('socket.io')(app.start());});
}