-
Notifications
You must be signed in to change notification settings - Fork 1
/
PushMessageFromServer.js
37 lines (31 loc) · 1.11 KB
/
PushMessageFromServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// https://developers.google.com/web/updates/2015/05/notifying-you-of-changes-to-notifications
// https://felixgerschau.com/web-push-notifications-tutorial/
// https://developers.google.com/web/fundamentals/codelabs/push-notifications
const webPush = require('web-push');
// VAPID keys should be generated only once with:
// const vapidKeys = webPush.generateVAPIDKeys();
// console.log(vapidKeys);
const vapidKeys = {
publicKey: 'BHG9NdYdfiCIx7xUS8u2CMhtDD-GWHb6QYuSZ908NZYZHhJEjGjcX0yTjHrWx7gDICmCEUORrLmw3uwOGBqzm2s',
privateKey: 'wDf6oqOkg0SQ3FD8NU9ZNrwVZWIGBfm1gPgp6QNXWjk'
};
webPush.setVapidDetails(
'mailto:example@yourdomain.org',
vapidKeys.publicKey,
vapidKeys.privateKey
);
// This is an sample subscription object that we get after subscript on browser
const pushSubscription =
{
"endpoint": "",
"expirationTime": null,
"keys": {
"p256dh": "",
"auth": ""
}
}
const payload = {
title: `Hello at ${(new Date()).toISOString()}`,
url: 'https://www.dotnetthailand.com/web-frameworks/orchard-core-cms/why-orchard-core-cms'
};
webPush.sendNotification(pushSubscription, JSON.stringify(payload));