Beginning Progressive Web App Development by Dennis Sheppard

Beginning Progressive Web App Development by Dennis Sheppard

Author:Dennis Sheppard
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


Once you’re ready to send the notification, you can kill your timer. Then, whatever data you want to send with the push notification along with your subscription object you passed in to this function is included in a sendNotification method on the webPush object. That returns a promise you can use to do something after the notification was sent or to handle errors. In your case, if for some reason the notification didn’t send, the subscription is no good, so you want to remove that subscription object from your array of them.

At this point, your notification is sent! The cycle is complete.

You’re not quite done yet, though. What happens when or if the user feeds Peggy? You need to reset the timer and notify them again later. So you need something that the front end can use to update that timer. Again, this is an item that’s really specific to this particular app, but you’ll see later how you can use the following logic to enable users to interact directly with notifications:

app.post('/feed', (req, res) => {

timeLeft = 15;

if (!timer) {

setPushTimer();

}

res.sendStatus(200);

});



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.