Open goaround opened 2 years ago
Using the approach suggested sets a lower padding value for every notification sent using the current webpush instance. To mitigate this only to reduce the padding on firefox v1 I restricted the lowering of the padding to the subscriptions that have a Firefox v1 endpoint.
Here's what I did:
<?php
namespace App\Providers\Models;
use Illuminate\Support\Str;
use Minishlink\WebPush\Encryption;
use Minishlink\WebPush\SubscriptionInterface;
use Minishlink\WebPush\WebPush as MWWebpush;
class WebPush extends MWWebpush
{
// Solves:
// https://github.com/laravel-notification-channels/webpush/issues/103
// https://github.com/web-push-libs/web-push-php/issues/108#issuecomment-545977603
// Had to lower the Mobile Firefox padding for it to work. It probably can go higher but no longer works under 2847 as suggested.
const MAX_MOBILE_FIREFOX_PADDING = 2048;
public function queueNotification(SubscriptionInterface $subscription, ?string $payload = null, array $options = [], array $auth = []): void
{
$this->setAutomaticPadding(Encryption::MAX_COMPATIBILITY_PAYLOAD_LENGTH);
if(Str::startsWith($subscription->getEndpoint(), 'https://updates.push.services.mozilla.com/wpush/v1')){
$this->setAutomaticPadding(self::MAX_MOBILE_FIREFOX_PADDING);
}
parent::queueNotification($subscription, $payload, $options, $auth);
}
}
<?php
namespace App\Providers;
use App\Providers\Models\WebPush;
use Minishlink\WebPush\WebPush as MWWebPush;
use NotificationChannels\WebPush\WebPushChannel;
use NotificationChannels\WebPush\WebPushServiceProvider as NCWebPushServiceProvider;
class WebPushServiceProvider extends NCWebPushServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
parent::boot();
$this->app->when(WebPushChannel::class)
->needs(MWWebPush::class)
->give(function () {
return (new WebPush(
$this->webPushAuth(), [], 30, config('webpush.client_options', [])
))->setReuseVAPIDHeaders(true);
});
}
}
Enable the service provide in config/app.php
Disable automatic loading of the service provider in composer.json
"extra": {
"laravel": {
"dont-discover": [
"laravel-notification-channels/webpush"
]
}
},
I'll assume some maintenance responsibility over time yet I am completely able to bypass the firefox problem and retain max padding compatibility.
To support Firefox Android, automatic padding applied by WebPush has to be disabled: https://github.com/web-push-libs/web-push-php#how-can-i-disable-or-customize-automatic-padding
This PR just applies the default 3052 bytes but you can set
automatic_padding
to false to support Firefox AndroidFix for https://github.com/laravel-notification-channels/webpush/issues/103#issuecomment-1205132556