Last active
March 18, 2019 19:41
-
-
Save Serginho/50d1dd39f6c16be68901f422fc04adff to your computer and use it in GitHub Desktop.
request subscription browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
navigator.serviceWorker.ready.then(serviceWorkerRegistration => { | |
const options = {userVisibleOnly: true, applicationServerKey: applicationServerKey}; | |
serviceWorkerRegistration.pushManager.subscribe(options).then(pushSubscription => { | |
// Send subscription to service worker to save it. | |
navigator.serviceWorker.controller.postMessage({ | |
action: 'REQUEST_SUBSCRIPTION', | |
subscription: pushSubscription | |
}); | |
// Upload first subscription to server using userId or any identifier | |
// to match user. | |
uploadSubscriptionToTheServer(pushSubscription, userId); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment