@@ -36,38 +36,48 @@ Use [composer](https://getcomposer.org/) to download and install the library and
36
36
use Minishlink\WebPush\WebPush;
37
37
use Minishlink\WebPush\Subscription;
38
38
39
+ // store the client-side `PushSubscription` object (calling `.toJSON` on it) as-is and then create a WebPush\Subscription from it
40
+ $subscription = Subscription::create(json_decode($clientSidePushSubscriptionJSON, true));
41
+
39
42
// array of notifications
40
43
$notifications = [
41
44
[
45
+ 'subscription' => $subscription,
46
+ 'payload' => '{"message":"Hello World!"}',
47
+ ], [
48
+ // current PushSubscription format (browsers might change this in the future)
49
+ 'subscription' => Subscription::create([
50
+ "endpoint" => "https://example.com/other/endpoint/of/another/vendor/abcdef...",
51
+ "keys" => [
52
+ 'p256dh' => '(stringOf88Chars)',
53
+ 'auth' => '(stringOf24Chars)'
54
+ ],
55
+ ]),
56
+ 'payload' => '{"message":"Hello World!"}',
57
+ ], [
58
+ // old Firefox PushSubscription format
42
59
'subscription' => Subscription::create([
43
60
'endpoint' => 'https://updates.push.services.mozilla.com/push/abc...', // Firefox 43+,
44
61
'publicKey' => 'BPcMbnWQL5GOYX/5LKZXT6sLmHiMsJSiEvIFvfcDvX7IZ9qqtq68onpTPEYmyxSQNiH7UD/98AUcQ12kBoxz/0s=', // base 64 encoded, should be 88 chars
45
62
'authToken' => 'CxVX6QsVToEGEcjfYPqXQw==', // base 64 encoded, should be 24 chars
46
63
]),
47
64
'payload' => 'hello !',
48
65
], [
66
+ // old Chrome PushSubscription format
49
67
'subscription' => Subscription::create([
50
- 'endpoint' => 'https://fcm.googleapis.com/fcm/send/abcdef...', // Chrome
68
+ 'endpoint' => 'https://fcm.googleapis.com/fcm/send/abcdef...',
51
69
]),
52
70
'payload' => null,
53
71
], [
72
+ // old PushSubscription format
54
73
'subscription' => Subscription::create([
55
74
'endpoint' => 'https://example.com/other/endpoint/of/another/vendor/abcdef...',
56
75
'publicKey' => '(stringOf88Chars)',
57
76
'authToken' => '(stringOf24Chars)',
58
77
'contentEncoding' => 'aesgcm', // one of PushManager.supportedContentEncodings
59
78
]),
60
- 'payload' => '{msg:"test"}',
61
- ], [
62
- 'subscription' => Subscription::create([ // this is the structure for the working draft from october 2018 (https://www.w3.org/TR/2018/WD-push-api-20181026/)
63
- "endpoint" => "https://example.com/other/endpoint/of/another/vendor/abcdef...",
64
- "keys" => [
65
- 'p256dh' => '(stringOf88Chars)',
66
- 'auth' => '(stringOf24Chars)'
67
- ],
68
- ]),
69
- 'payload' => '{"msg":"Hello World!"}',
70
- ],
79
+ 'payload' => '{"message":"test"}',
80
+ ]
71
81
];
72
82
73
83
$webPush = new WebPush();
0 commit comments