Open owencm opened 8 years ago
I.e. what keys should it have? How should they be encoded?
The question of how to get keys from a PushSubscription object on the client up to the server has turned out to be a big problem for me trying to get this to work and clarification would be great.
@owencm you can find some explanation here: https://developers.google.com/web/updates/2016/03/web-push-encryption?hl=en Not sure, but I think the subscription object is the same that you get in registration.
@owencm Looking more closely in the code I think the subscription object is somethin like this:
var subscription = {
endpoint: '',
keys: {
p256dh: '',
auth: ''
}
};
navigator.serviceWorker.ready.then(worker => {
console.log('Service Worker is Ready')
console.log(worker)
worker.pushManager.getSubscription()
.then(subscription => {
console.log('Subscription: ', subscription)
const sub = subscription || worker.pushManager.subscribe({userVisibleOnly: true})
return sub
}).then(sub => {
const deviceSubscription = JSON.stringify(sub)
// --> Send deviceSubscription to the Server
}).catch(error => {
console.error(error)
})
})
It's unclear today what the
subscription
object in readme is supposed to be.