Closed ravikiran-gunale closed 8 years ago
@ravikiran-gunale Can you please post code that reproduces this issue?
Code from app.js file: (here I am calling GCM api and sending data to api)
var message = new gcm.Message();
message.addData('key1', 'msg1');
message.addNotification('title', 'Alert!!!');
message.addNotification('body', 'Abnormal data access');
var sender = new gcm.Sender(website_key1);
var registrationTokens = [];
registrationTokens.push(registration_token);
sender.send(message, { registrationTokens: registrationTokens }, function(err, response) {
if(err) console.error(err);
else console.log(response);
});
code from service-worker.js:
self.addEventListener('push', function(event) {
var title = event.title;
var body = event.body;
var icon = '/images/image.png';
var tag = 'simple-push-demo-notification-tag';
event.waitUntil(function() {
self.registration.showNotification(title, {
body: body,
icon: icon,
tag: tag
})
});
})
Here, I am able to send data to GCM api using node-gcm but in service-worker.js. event object in service-worker.js does not have data, title, body. Hence, I am getting an error
@ravikiran-gunale You're describing a client-side bug.
node-gcm
only handles sending the push notifications from your backend to GCM. Receiving and handling the notification on the client-side is your responsibility.
While implementing push notifications using GCM, I sent message from server to GCM using node-gcm as per example in documentation of node-gcm. As per my understanding, 'event' parameter in addEventListener code (service-worker file), has above sent message data. But I am not seeing this message data in 'event' parameter. Is this a bug or error from my side?