From the course: JavaScript: Progressive Web Applications
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Subscribing to push messaging - JavaScript Tutorial
From the course: JavaScript: Progressive Web Applications
Subscribing to push messaging
- [Instructor] Currently, our PWA asks users to allow notifications using the request permission method of the notification object. To subscribe to Push notifications, we need to call the subscribe method of the Push manager built into the browser. The service worker registration object provides an interface to the Push manager. Let's open main.js and then comment out the notification object detection conditional statement. So that was in the service worker registration. And here is the beginning of that conditional statement. So let's start a comment here. And then we'll need to end the comment beneath that curly bracket. Okay, so right now we're not going to be getting notifications. We've turned that off. Let's do this: just above that commented code, let's make a call to a function called subscribeToPush. And we'll write that in just a moment. All right, so now let's put in subcribeToPush. I'll put that down at the bottom of the page. And let me scroll up to give you guys a little…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Introduction to notifications2m 21s
-
(Locked)
Requesting permission to show notifications5m 26s
-
(Locked)
Displaying a notification4m 50s
-
(Locked)
Adding data to a notification4m 36s
-
(Locked)
Closing a notification3m 33s
-
(Locked)
Handling the notification click event11m 25s
-
(Locked)
Push messaging overview1m 24s
-
(Locked)
Adding Firebase Cloud Messaging to the project2m 15s
-
(Locked)
Subscribing to push messaging6m
-
(Locked)
Handling push notifications3m 14s
-
(Locked)
Sending a tickle using cURL4m 57s
-
(Locked)
Sending data in a push message2m 9s
-
(Locked)
Installing Mozilla's Web Push library2m 51s
-
(Locked)
Modifying the push event handler2m 52s
-
(Locked)
Modifying the notification click event3m 48s
-
(Locked)
Creating the web push script6m
-
(Locked)
Testing the hosted app5m 7s
-
(Locked)
-
-