Skip to content

Commit 1757e11

Browse files
arcturusFrancisco Jordano
authored andcommitted
Making the vapi and userauth parameters optional
1 parent f179587 commit 1757e11

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

bin/web-push.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ webPush.setGCMAPIKey(process.env.GCM_API_KEY);
44

55
const argv = require('minimist')(process.argv.slice(2));
66

7-
const usage = 'Use: web-push --endpoint=<url> --key=<browser key> [--auth=<auth secret>] [--ttl=<seconds>] [--payload=<message>]';
7+
const usage = 'Use: web-push --endpoint=<url> --key=<browser key> [--auth=<auth secret>] [--ttl=<seconds>] [--payload=<message>] [--vapid]';
88

99
if (!argv['endpoint'] || !argv['key']) {
1010
console.log(usage);
@@ -16,31 +16,30 @@ const key = argv['key'];
1616
const ttl = argv['ttl'] || 0;
1717
const payload = argv['payload'] || '';
1818
const auth = argv['auth'] || null;
19+
const useVAPID = argv['vapid'] || false;
1920

20-
// Uses old sendMessage API
21-
var pushResult = null;
22-
if (!auth) {
23-
pushResult = webPush.sendNotification(endpoint, ttl, key, payload)
24-
} else {
21+
var params = {
22+
TTL: ttl,
23+
payload,
24+
userPublicKey: key
25+
};
26+
if (useVAPID) {
2527
const vapidKeys = webPush.generateVAPIDKeys();
2628
const vapid = {
2729
audience: 'https://www.mozilla.org/',
2830
subject: 'mailto:[email protected]',
2931
privateKey: vapidKeys.privateKey,
3032
publicKey: vapidKeys.publicKey,
3133
};
32-
pushResult = webPush.sendNotification(endpoint, {
33-
TTL: ttl,
34-
payload,
35-
userPublicKey: key,
36-
userAuth: auth,
37-
vapid
38-
});
34+
params['vapid'] = vapid;
3935
}
40-
pushResult.then(() => {
36+
if (auth) {
37+
params['userAuth'] = auth;
38+
}
39+
webPush.sendNotification(endpoint, params).then(() => {
4140
console.log('Push message sent.');
4241
}, (err) => {
4342
console.log('Error sending push message: ', err);
4443
}).then(() => {
4544
process.exit(0);
46-
})
45+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "web-push",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
4+
"version": "1.0.3",
45
"description": "Web Push library for Node.js",
56
"main": "index.js",
67
"scripts": {

0 commit comments

Comments
 (0)