Receive personalized messages from GCM using web push notifications

I use notifications on the web with Chrome and they work great. But now I want to deliver a custom message in my notifications. I can get my Worker to call my site to get content, as done at https://simple-push-demo.appspot.com/ - this is normal if I want each recipient to see the same message.

Is there a way to get either recipients registration_idor message_idthat GCM returns? If I could get any of them and include them in the service callback, I could customize the response.

Also, any information on when we could include a payload in a GCM call?

+4
source share
2 answers

Field registration_idand message_idare not displayed, but if the user has previously been authenticated in your application, any fetch()server on your employee's work will include the credentials (and session information), which you can use to identify them.

If this does not work for your case, you can store the user / session information in IndexedDB.

Helpful information coming soon - probably Chrome 50 or 51 - based on the Web Push protocol. This is a little extra overhead and works to set up (necessary) encryption.

+5
source

, , GCM, .

(, Mercurius) IndexedDB URL .

, registration_id:

self.registration.pushManager.getSubscription()
.then(function(subscription) {
  if (subscription) {
    var endpoint = subscription.endpoint;
    var endpointParts = endpoint.split('/');
    var gcmRegistrationID = endpointParts[endpointParts.length - 1];

    console.log(gcmRegistrationID);
  }
});

P.S.: , , , .

+1

Source: https://habr.com/ru/post/1625023/


All Articles