The subscription is created on client side when the end-user allows your application to send push messages.
On client side (Javascript), you can simply send to your server the object you receive using JSON.stringify
.
Javascript examples to get a Subscription from the web browser are not provided here. Please refer to other resources such as blog posts or library documentation.
A subscription object will look like:
On server side, you can get a WebPush\Subscription
object from the JSON string using the dedicated method WebPush\Subscription::createFromString
.
By default, the content encoding aesgcm
will be used. This encoding indicates how the payload of the notification should be formatted. The PushManager object from the Push API may list all acceptable encodings. In this case, it could be interesting to set these encodings to the Subscription object.
This will result in something like as follow:
The order of supportedContentEncodings
is important. First supported item will be used. If possible, AES128GCM
should be used as prefered content encoding.