ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 208 forks source link

Getting success but not message #277

Closed MuyBien closed 7 years ago

MuyBien commented 7 years ago

Hi! Thanks for you work that, I'm sure, is making me life a lot easier trying to achieve that. But I cannot understand why I am not receiving any message.

In my server console I get:

I20161207-22:57:30.664(1)?   success: 1,
I20161207-22:57:30.664(1)?   failure: 0,
I20161207-22:57:30.664(1)?   canonical_ids: 0,
I20161207-22:57:30.664(1)?   results: [ { message_id: '0:1481147850607211%7c2d200ff9fd7ecd' } ] }

But I'm getting to:

TypeError: Cannot read property 'Context' of undefined

Here is "my" code (copy/paste from readme)

var gcm = require('node-gcm');
var sender = new gcm.Sender('AA******MS');
var message = new gcm.Message({
    data: { "title": "Portugal vs. Denmark", "body": "5 to 1" }
});
var regTokens = ['de******vj'];

sender.send(message, { registrationTokens: regTokens }, function (err, response) {
    if (err) console.error(err);
    else console.log(response);
});

And I have a code to handle a message (background or not)

fbInstance.messaging().onMessage(function(payload) {
  console.log("Message received. ", payload);
});
fbInstance.messaging().setBackgroundMessageHandler(function(payload) {
  console.log('[firebase-messaging-sw.js] Received background message ', payload);
});

What can be the problem? Thanks for your advice!

:)

hypesystem commented 7 years ago

Hmm, I'm not quite sure! Where does the TypeError happen?

I haven't done any implementation with firebase, so if something goes wrong on that end I'm afraid I can't help you :-(

MuyBien commented 7 years ago

Hi! I am using MeteorJS. The TypeError is happening in the navigator console.

Maybe I have to do the server implementation in NodeJS whithout any plugin :(

hypesystem commented 7 years ago

Aw. Yeah, usually a backend application would run the node-gcm code. I don't have any experience with MeteorJS, so I can't really help you :-( sorry!

Please let us know if you resolve the issue, though!

eladnava commented 7 years ago

Closing due to inactivity. Feel free to reopen if you still experience this issue.