Reputation: 403
Serverside code:
var message = new gcm.Message({
collapseKey: "demo",
delayWhileIdle: true,
timeToLive: 3,
data: {
test: 'value'
}
});
var sender = new gcm.Sender(config.gcmKey);
var tokens = [];
... (to add tokens) ...
sender.send(message, tokens, 3, function (err, res) { ... }
Clientside code (in a working serviceworker):
self.addEventListener('push', function(event) {
console.log('Push message', event);
var title = 'Push message';
event.waitUntil(
self.registration.showNotification(title, {
body: 'Test',
icon: 'img/icon.png',
}));
});
(Everything is copied from readmes, tutorials and demos)
When I send the notification serverside, it displays on my screen as expected and with no errors. However, the console.log('Push message', event);
outputs the event object with data: null
. How can I get the test: 'value'
key-value pair from the server? This is with the latest node-gcm and Chrome 52.
Upvotes: 0
Views: 276
Reputation: 10802
The payload for web push notifications doesn't work the same way as it works for Android. It needs to be encrypted and sent in a different way.
You can use the web-push library for Node.js. It supports GCM for older Chrome versions, Web Push for Firefox and newer Chrome versions.
Upvotes: 1