web-push


Getting customized message from GCM using Web push notifications


I'm using Web push notifications with Chrome, and they work great. But now I want to deliver a custom message in my notifications. I can have my Service Worker call out to my site to get content, as is done at https://simple-push-demo.appspot.com/—which is fine if I want every recipient to see the same message.
Is there any way to get either the recipient’s registration_id or the message_id that GCM returns? If I could get either of these and include them in the callback to the service, I could customize the response.
Also, any info on when we might be able to include a payload in the call to GCM?
The registration_id and message_id fields aren't exposed, but if the user is previously authenticated to your app, any fetch() to the server from your Service Worker will include credentials (and session information) which you can use to identify them.
If that doesn't work for your case, you can store user/session information in IndexedDB.
Payloads are coming soon—likely Chrome 50 or 51—based on the Web Push protocol. It's a bit of extra overhead and work to configure the (required) encryption.
It's possible, but I wouldn't do it since it's specific to GCM, while other browsers use other services.
You can either create a unique ID for each user (like we're doing in Mercurius) and store it in IndexedDB, or you can use the entire endpoint URL as an ID.
Here's the snippet to get the 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.: It returns a promise, so make sure your service worker waits for the promise to be resolved.

Related Links

My Pushpad Sender does not send any more notifications
Pushpad or Web push notification how to custom dialog message
What is VAPID and why is it useful?
How can I test pushsubscriptionchange event-handling code?
How should I handle the pushsubscriptionchange event?
How can I hide notifications my site is displaying if it is focused and brought to the foreground?
Do I need to show a notification in response to a push notification if my site is foreground and focused?
Getting customized message from GCM using Web push notifications
Firefox Push API - AbortError: Error retrieving push subscription

Categories

HOME
apple-push-notifications
kendo-dropdown
devexpress
tcsh
code-formatting
twitter-fabric
hyperledger
ipv6
cdi
selection
gtk
solution
nsstring
fullcalendar-scheduler
multi-step
powermock
ex
xbox360
gravity
word2vec
significance
multiple-tables
adobe-illustrator
pe
fido-u2f
pymongo
raima
cellular-network
python-appium
android-service
echosign
monitor
credit-card
source-insight
toad
netbios
nsmutablearray
listjs
devtools
runtimeexception
jade4j
gitolite
oauth2-playground
deployd
amazon-elastic-beanstalk
iptv
palindrome
asp.net-web-api-routing
ltrace
gapi
haraka
scheduledexecutorservice
system.web.optimization
timestamping
django-redis
mercurial-extension
ioctl
ibm-was
hmisc
explain
innerhtml
incron
rebar
cout
windows-rt
mobile-country-code
accountmanager
principalcontext
armv6
frontbase
iirf
stty
django-facebook
hints
gprof
idispatch
onconfigurationchanged
story
struts2-s2hibernate
monocross
fitch-proofs
exponent
acpi
type-safety
expression-web
motodev-studio
space-partitioning
ognl
dip
active-record-query
mygeneration
resharper-5.0
spring-modules
projectpier
xap
activex-exe
remote-working

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App