@@ -36,38 +36,48 @@ Use [composer](https://getcomposer.org/) to download and install the library and
3636use Minishlink\WebPush\WebPush;
3737use Minishlink\WebPush\Subscription;
3838
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+
3942// array of notifications
4043$notifications = [
4144 [
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
4259 'subscription' => Subscription::create([
4360 'endpoint' => 'https://updates.push.services.mozilla.com/push/abc...', // Firefox 43+,
4461 'publicKey' => 'BPcMbnWQL5GOYX/5LKZXT6sLmHiMsJSiEvIFvfcDvX7IZ9qqtq68onpTPEYmyxSQNiH7UD/98AUcQ12kBoxz/0s=', // base 64 encoded, should be 88 chars
4562 'authToken' => 'CxVX6QsVToEGEcjfYPqXQw==', // base 64 encoded, should be 24 chars
4663 ]),
4764 'payload' => 'hello !',
4865 ], [
66+ // old Chrome PushSubscription format
4967 'subscription' => Subscription::create([
50- 'endpoint' => 'https://fcm.googleapis.com/fcm/send/abcdef...', // Chrome
68+ 'endpoint' => 'https://fcm.googleapis.com/fcm/send/abcdef...',
5169 ]),
5270 'payload' => null,
5371 ], [
72+ // old PushSubscription format
5473 'subscription' => Subscription::create([
5574 'endpoint' => 'https://example.com/other/endpoint/of/another/vendor/abcdef...',
5675 'publicKey' => '(stringOf88Chars)',
5776 'authToken' => '(stringOf24Chars)',
5877 'contentEncoding' => 'aesgcm', // one of PushManager.supportedContentEncodings
5978 ]),
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+ ]
7181];
7282
7383$webPush = new WebPush();
0 commit comments