Web Push System - how to subscribe the users?

时间:2018-02-03 09:01:06

标签: javascript plugins push-notification sdk web-push

I'm making a simple web push system.

Each user registers, gets a unique vapid key, puts it in his web, his web users subscribes to push notifications with the vapid key, then the user can send push notifications via push system web interface.

I need a solution to install the server key in users websites.

Should I make a some sort of a plugin/javascript sdk, for example, the user would add a script from an SDK, and then init the script with his unique vapid key from the system? Like so:

pushSystem.init({ id: vapid_key })

The script would then subscribe the user with the key and send the subscribtion to the server, where I would pull the subscribtions for this private key in the web interface and send push to all of them.

How should I go about this? I did a lot of research, didin't really find anything about this.

1 个答案:

答案 0 :(得分:1)

At Pushpad we do this:

  1. We provide a Javascript SDK that is included as a normal script in the website
  2. The website calls pushpad('init', PROJECT_ID)
  3. The VAPID public key is downloaded dynamically from the service using the PROJECT_ID and is stored in a variable
  4. The website calls pushpad('subscribe'), which calls pushManage.subscribe() using the VAPID public key