Skip to content

Commit 531e7bd

Browse files
committed
More read me content
1 parent 5994039 commit 531e7bd

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

PushMessageFromServer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ webpush.setVapidDetails(
1818
vapidKeys.privateKey
1919
);
2020

21-
// This is the same output of calling JSON.stringify on a PushSubscription
21+
// This is the sample output of calling JSON.stringify on a PushSubscription
2222

2323
// const pushSubscription =
2424
// endpoint: '.....',

README.md

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,57 @@
11
# web-push-api-example
22

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.
59

10+
```sh
11+
yarn create react-app web-push-api-example --template typescript
12+
```
613

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+
-

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function App() {
2929
return (
3030
<div>
3131
<button onClick={handleSubscribeWebPush}>
32-
Subscript web push
32+
Subscript Web Push
3333
</button>
3434
<div>
3535
<textarea rows={10} style={style} value={subscription} />

0 commit comments

Comments
 (0)