What problem does this feature proposal attempt to solve?
When broadcasting subscriptions you can filter out the user that triggered the broadcast with:
public function filter(Subscriber $subscriber, mixed $root): bool
{
return $subscriber->socket_id !== request()->header('X-Socket-ID');
}
The problem comes when the broadcast is queued instead of dispatching it synchronously, when queued request() is always empty and the filter will be ignorred.
Which possible solutions should be considered?
One solution could be passing the request to the BroadcastSubscriptionJob and setting it on execution:
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Facade;
class BroadcastSubscriptionJob implements ShouldQueue
{
use Queueable;
use SerializesModels;
public function __construct(
/**
* The subscription field that was requested.
*/
public GraphQLSubscription $subscription,
/**
* The name of the field.
*/
public string $fieldName,
/**
* The root element to be passed when resolving the subscription.
*/
public mixed $root,
/**
* The request context when the broadcast was triggered
*/
public Request $request,
) {}
public function handle(BroadcastsSubscriptions $broadcaster): void
{
App::instance('request', $this->request);
Facade::clearResolvedInstance('request');
$broadcaster->broadcast($this->subscription, $this->fieldName, $this->root);
}
}
Other solution could be adding a "native" toOthers functionality to the broadcaster:
What problem does this feature proposal attempt to solve? When broadcasting subscriptions you can filter out the user that triggered the broadcast with:
The problem comes when the broadcast is queued instead of dispatching it synchronously, when queued
request()
is always empty and the filter will be ignorred.Which possible solutions should be considered?
One solution could be passing the request to the
BroadcastSubscriptionJob
and setting it on execution:Other solution could be adding a "native"
toOthers
functionality to the broadcaster:The problem with this solution is that it could break compatibility with the
BroadcastsSubscriptions
interface.