|
1 | 1 | # web-push-api-example |
2 | 2 |
|
3 | | -yarn create react-app web-push-api-example --template typescript |
4 | | -required Node.js version >= 14 |
| 3 | +## How to run the project locally |
| 4 | +- Open a new terminal session. |
| 5 | +- CD to the root folder of the project and run `yarn` to install all Node packages. |
| 6 | +- Then run `yarn start` to start a project and automatically launch a browser. |
| 7 | +- Click `Subscribe Web Push` and copy a subscription object in text box. |
| 8 | +- Use subscription object in a server side to send push notification. |
5 | 9 |
|
| 10 | +```sh |
| 11 | + yarn create react-app web-push-api-example --template typescript |
| 12 | +``` |
6 | 13 |
|
7 | | -# Notification does not always show as banner. |
8 | | -Turn of focus assist |
| 14 | +- Required Node.js version >= 14 |
| 15 | + |
| 16 | +# Get subscription object |
| 17 | +- For the main project in .NET Thailand repository, it can be accessed as http://www.dotnetthailand.com/web-push-api-example/. |
| 18 | + |
| 19 | + |
| 20 | +# Send push notification from a server |
| 21 | +- Set a push subscrition object in `PushMessageFromServer` that we get after a user's subscribed web push. |
| 22 | +- Execute the following command: |
| 23 | + ```sh |
| 24 | + node PushMessageFromServer.js |
| 25 | + ``` |
| 26 | + |
| 27 | +## Notification does not always show as banner. |
| 28 | +Turn of focus assist |
| 29 | + |
| 30 | +server |
| 31 | +private/public key |
| 32 | + |
| 33 | +client |
| 34 | +public key |
| 35 | + |
| 36 | +load register service background |
| 37 | + |
| 38 | +subscribe to server with public key |
| 39 | +send subscription object to store on server as identity |
| 40 | + |
| 41 | +import web-push |
| 42 | + |
| 43 | +const vapIdKey = push.generateVAPIDKeys(); to get public and private keys |
| 44 | +setVapidDetails() |
| 45 | +sendNotification |
| 46 | + |
| 47 | +serviceWorker to handle receive notification |
| 48 | + |
| 49 | +skip waiting in application tab |
| 50 | + |
| 51 | +Useful articles for .NET Web Push |
| 52 | +- https://www.pluralsight.com/guides/html5-desktop-notifications-with-react?fbclid=IwAR1NzrQNDYSZJxKLMxWVVWes_eulWauBqa63F6Z47dDznNBL9ARiCQ26wOs |
| 53 | +- https://blog.elmah.io/how-to-send-push-notifications-to-a-browser-in-asp-net-core/ |
| 54 | +- https://www.bartvanuden.com/2018/01/23/push-notifications-to-your-pwa-with-asp-net-core-2-0-and-aurelia/ |
| 55 | +- https://www.tpeczek.com/2017/12/push-notifications-and-aspnet-core-part.html |
| 56 | +- https://stackoverflow.com/a/47617427/1872200 |
| 57 | +- |
0 commit comments