Service Worker Push Notifications with Angular2

时间:2016-04-04 18:54:35

标签: node.js push-notification angular service-worker progressive-web-apps

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:

  • Client visits app
  • Service worker yields a push notification endpoint
  • Client sends the endpoint to the server
  • Server associates the endpoint with the current user that the endpoint was generated for
  • Every time something that your app would say is notification worthy happens, the server grabs the push notification endpoint(s) associated with the user, and hits it to send a push notification to any user devices (possibly with a data payload in Chrome 50+, etc)

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

1 个答案:

答案 0 :(得分:8)

你非常喜欢,有一些细节并不是很正确(但这主要是措辞,可能是为了个人品味)。

  • 客户访问应用
  • 注册要用于推送消息传递的服务工作者
  • 使用服务工作者注册来订阅用户推送消息,此时用户代理将配置端点+用于加密有效负载的其他值(如果用户代理支持它)。
  • 客户端将端点发送到服务器
  • 服务器存储端点和数据供以后使用(如果Web应用程序具有用户帐户,服务器可以将端点与当前用户关联)。
  • 当服务器希望向用户发送通知时,它会抓取相应的端点并调用它们,这将唤醒服务工作者,然后服务工作者可以显示通知。
来自Chrome 50+的有效负载支持在编写有效负载时支持Firefox,但在3个不同版本的Firefox中有3种不同版本的加密用于有效负载,因此我等待有效载荷支持故事在使用它/依赖它之前要稍微解决。