Skip to content

Commit 53f05d3

Browse files
committed
Upgrade web-push-php to 4.0.0
1 parent 0694415 commit 53f05d3

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
}
1111
],
1212
"require": {
13-
"minishlink/web-push": "^3.0"
13+
"minishlink/web-push": "^4.0"
1414
}
1515
}

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,15 @@ document.addEventListener("DOMContentLoaded", () => {
175175
function push_sendSubscriptionToServer(subscription, method) {
176176
const key = subscription.getKey('p256dh');
177177
const token = subscription.getKey('auth');
178+
const contentEncoding = (PushManager.supportedContentEncodings || ['aesgcm'])[0];
178179

179180
return fetch('push_subscription.php', {
180181
method,
181182
body: JSON.stringify({
182183
endpoint: subscription.endpoint,
183-
key: key ? btoa(String.fromCharCode.apply(null, new Uint8Array(key))) : null,
184-
token: token ? btoa(String.fromCharCode.apply(null, new Uint8Array(token))) : null
184+
publicKey: key ? btoa(String.fromCharCode.apply(null, new Uint8Array(key))) : null,
185+
authToken: token ? btoa(String.fromCharCode.apply(null, new Uint8Array(token))) : null,
186+
contentEncoding,
185187
}),
186188
}).then(() => subscription);
187189
}
@@ -208,13 +210,15 @@ document.addEventListener("DOMContentLoaded", () => {
208210

209211
const key = subscription.getKey('p256dh');
210212
const token = subscription.getKey('auth');
213+
const contentEncoding = (PushManager.supportedContentEncodings || ['aesgcm'])[0];
211214

212215
fetch('send_push_notification.php', {
213216
method: 'POST',
214217
body: JSON.stringify({
215218
endpoint: subscription.endpoint,
216-
key: key ? btoa(String.fromCharCode.apply(null, new Uint8Array(subscription.getKey('p256dh')))) : null,
217-
token: token ? btoa(String.fromCharCode.apply(null, new Uint8Array(subscription.getKey('auth')))) : null
219+
publicKey: key ? btoa(String.fromCharCode.apply(null, new Uint8Array(subscription.getKey('p256dh')))) : null,
220+
authToken: token ? btoa(String.fromCharCode.apply(null, new Uint8Array(subscription.getKey('auth')))) : null,
221+
contentEncoding,
218222
})
219223
})
220224
})

src/send_push_notification.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22
require __DIR__ . '/../vendor/autoload.php';
33
use Minishlink\WebPush\WebPush;
4+
use Minishlink\WebPush\Subscription;
45

56
// here I'll get the subscription endpoint in the POST parameters
67
// but in reality, you'll get this information in your database
78
// because you already stored it (cf. push_subscription.php)
8-
$subscription = json_decode(file_get_contents('php://input'), true);
9+
$subscription = Subscription::create(json_decode(file_get_contents('php://input'), true));
910

1011
$auth = array(
1112
'VAPID' => array(
@@ -18,10 +19,8 @@
1819
$webPush = new WebPush($auth);
1920

2021
$res = $webPush->sendNotification(
21-
$subscription['endpoint'],
22+
$subscription,
2223
"Hello!",
23-
$subscription['key'],
24-
$subscription['token'],
2524
true
2625
);
2726

0 commit comments

Comments
 (0)