@@ -36,21 +36,23 @@ class WebPush
36
36
'GCM ' => 'https://android.googleapis.com/gcm/send ' ,
37
37
);
38
38
39
+ /** @var int Time To Live of notifications */
40
+ private $ TTL ;
41
+
39
42
/**
40
43
* WebPush constructor.
41
44
*
42
45
* @param array $apiKeys Some servers needs authentication. Provide your API keys here. (eg. array('GCM' => 'GCM_API_KEY'))
43
- * @param int|null $TTL Time to live of notifications
46
+ * @param int|null $TTL Time To Live of notifications, default being 4 weeks.
44
47
* @param int|null $timeout Timeout of POST request
45
48
* @param AbstractClient|null $client
46
49
*/
47
- public function __construct (array $ apiKeys = array (), $ TTL = null , $ timeout = null , AbstractClient $ client = null )
50
+ public function __construct (array $ apiKeys = array (), $ TTL = 2419200 , $ timeout = 30 , AbstractClient $ client = null )
48
51
{
49
52
$ this ->apiKeys = $ apiKeys ;
50
53
$ this ->TTL = $ TTL ;
51
54
52
55
$ client = isset ($ client ) ? $ client : new MultiCurl ();
53
- $ timeout = isset ($ timeout ) ? $ timeout : 30 ;
54
56
$ client ->setTimeout ($ timeout );
55
57
$ this ->browser = new Browser ($ client );
56
58
}
@@ -213,21 +215,19 @@ private function sendToStandardEndpoints(array $notifications)
213
215
'Encryption-Key ' => 'keyid=p256dh;dh= ' .$ encrypted ['localPublicKey ' ],
214
216
'Encryption ' => 'keyid=p256dh;salt= ' .$ encrypted ['salt ' ],
215
217
'Content-Encoding ' => 'aesgcm128 ' ,
218
+ 'TTL ' => $ this ->TTL ,
216
219
);
217
220
218
221
$ content = $ encrypted ['cipherText ' ];
219
222
} else {
220
223
$ headers = array (
221
224
'Content-Length ' => 0 ,
225
+ 'TTL ' => $ this ->TTL ,
222
226
);
223
227
224
228
$ content = '' ;
225
229
}
226
230
227
- if (isset ($ this ->TTL )) {
228
- $ headers ['TTL ' ] = $ this ->TTL ;
229
- }
230
-
231
231
$ responses [] = $ this ->sendRequest ($ notification ->getEndpoint (), $ headers , $ content );
232
232
}
233
233
@@ -239,8 +239,11 @@ private function sendToGCMEndpoints(array $notifications)
239
239
$ maxBatchSubscriptionIds = 1000 ;
240
240
$ url = $ this ->urlByServerType ['GCM ' ];
241
241
242
- $ headers ['Authorization ' ] = 'key= ' .$ this ->apiKeys ['GCM ' ];
243
- $ headers ['Content-Type ' ] = 'application/json ' ;
242
+ $ headers = array (
243
+ 'Authorization ' => 'key= ' .$ this ->apiKeys ['GCM ' ],
244
+ 'Content-Type ' => 'application/json ' ,
245
+ 'TTL ' => $ this ->TTL ,
246
+ );
244
247
245
248
$ subscriptionIds = array ();
246
249
/** @var Notification $notification */
@@ -316,4 +319,20 @@ public function setBrowser($browser)
316
319
{
317
320
$ this ->browser = $ browser ;
318
321
}
322
+
323
+ /**
324
+ * @return int
325
+ */
326
+ public function getTTL ()
327
+ {
328
+ return $ this ->TTL ;
329
+ }
330
+
331
+ /**
332
+ * @param int $TTL
333
+ */
334
+ public function setTTL ($ TTL )
335
+ {
336
+ $ this ->TTL = $ TTL ;
337
+ }
319
338
}
0 commit comments