Dominic Farolino
Dominic Farolino

Reputation: 1383

Service Worker Push Notifications with Angular2

I'm trying to piece together the general workflow of giving a user push notifications via the service worker.

I have followed this Google Developers service worker push notifications tutorial and am currently thinking about how I can implement this sort of thing in a small user based web app for experimentation.

In my mind, the general workflow of an web app supporting push notifications is as follows:

Basically I just want to confirm that my general implementation thoughts with this technology are accurate, else get feedback if I am missing something.

Upvotes: 6

Views: 3926

Answers (1)

Matt Gaunt
Matt Gaunt

Reputation: 9831

You are pretty much bang on, there are some specifics that aren't quite right (but this is largely phrasing and may be done to personally taste).

  • Client visits app
  • Register a Service Worker that you want to use for push messaging
  • Use the service worker registration to subscribe the user to push messaging, at which point the user agent will configure an endpoint + additional values for encrypting payloads (If the the user agent supports it).
  • Client sends the endpoint to the server
  • Server store the the endpoint and data for later use (The server can associate the endpoint with the current user if the server if the web app has user accounts).
  • When ever the server wishes to send a notification to a user(s), it grabs the appropriate endpoints and calls them that will wake up the service worker which can then display a notification.

Payload support in coming in Chrome 50+ and at the time of writing payload is support in Firefox, but there are 3 different versions of encryption used for the payloads in 3 different versions of Firefox, so I'd wait for the payload support story to be ironed out a little before using it / relying on it.

Upvotes: 8

Related Questions