File tree Expand file tree Collapse file tree 1 file changed +2
-21
lines changed Expand file tree Collapse file tree 1 file changed +2
-21
lines changed Original file line number Diff line number Diff line change @@ -60,32 +60,13 @@ webpush.sendNotification(pushSubscription, 'Your Push Payload Text');
60
60
61
61
## Using VAPID Key for applicationServerKey
62
62
63
- When using your VAPID key in your web app, you'll need to convert the
64
- URL safe base64 string to a Uint8Array to pass into the subscribe call,
63
+ When subscribing to push messages, you'll need to pass your VAPID key,
65
64
which you can do like so:
66
65
67
66
``` javascript
68
- function urlBase64ToUint8Array (base64String ) {
69
- const padding = ' =' .repeat ((4 - base64String .length % 4 ) % 4 );
70
- const base64 = (base64String + padding)
71
- .replace (/ -/ g , ' +' )
72
- .replace (/ _/ g , ' /' );
73
-
74
- const rawData = window .atob (base64);
75
- const outputArray = new Uint8Array (rawData .length );
76
-
77
- for (let i = 0 ; i < rawData .length ; ++ i) {
78
- outputArray[i] = rawData .charCodeAt (i);
79
- }
80
- return outputArray;
81
- }
82
-
83
- const vapidPublicKey = ' <Your Public Key from generateVAPIDKeys()>' ;
84
- const convertedVapidKey = urlBase64ToUint8Array (vapidPublicKey);
85
-
86
67
registration .pushManager .subscribe ({
87
68
userVisibleOnly: true ,
88
- applicationServerKey: convertedVapidKey
69
+ applicationServerKey: ' <Your Public Key from generateVAPIDKeys()> '
89
70
});
90
71
```
91
72
You can’t perform that action at this time.
0 commit comments