class AblyBroadcaster extends Broadcaster

Properties

protected Container $container

The container instance.

from  Broadcaster
protected Closure|null $authenticatedUserCallback

The callback to resolve the authenticated user information.

from  Broadcaster
static protected array $channels

The registered channel authenticators.

from  Broadcaster
static protected array $channelOptions

The registered channel options.

from  Broadcaster
static protected Closure|null $channelFormatter

The callback used to format outgoing channel values.

from  Broadcaster
static protected null|Request, string): ?string $channelAuthorizer

The callback used to authorize incoming channel names.

from  Broadcaster
protected BindingRegistrar|null $bindingRegistrar

The binding registrar instance.

from  Broadcaster

Methods

array|null
resolveAuthenticatedUser(Request $request)

Resolve the authenticated user payload for the incoming connection request.

void
resolveAuthenticatedUserUsing(Closure|null $callback)

Register the user retrieval callback used to authenticate connections.

channel(HasBroadcastChannel|string $channel, callable|string $callback, array $options = [])

Register a channel authenticator.

static void
formatChannelsUsing(Closure|null $callback)

Register the outgoing channel formatter.

static void
authorizeChannelsUsing(Closure|null $callback)

Register the incoming channel authorizer.

mixed
verifyUserCanAccessChannel(Request $request, string $channel, bool $guarded = false)

Authenticate the incoming request for a given channel.

mixed
validAuthenticationResponseForChannel(Request $request, mixed $result, string $channel)

Return the valid authentication response for the authorized channel.

array
extractAuthParameters(string $pattern, string $channel, callable|string $callback)

Extract the parameters from the given pattern and channel.

array
extractParameters(callable|string $callback)

Extracts the parameters out of what the user passed to handle the channel authentication.

array
extractParametersFromClass(string $callback)

Extracts the parameters out of a class channel's "join" method.

array
extractChannelKeys(string $pattern, string $channel)

Extract the channel keys from the incoming channel name.

mixed
resolveBinding(string $key, string $value, array $callbackParameters)

Resolve the given parameter binding.

mixed
resolveExplicitBindingIfPossible(string $key, mixed $value)

Resolve an explicit parameter binding if applicable.

mixed
resolveImplicitBindingIfPossible(string $key, string $value, array $callbackParameters)

Resolve an implicit parameter binding if applicable.

bool
isImplicitlyBindable(string $key, ReflectionParameter $parameter)

Determine if a given key and parameter is implicitly bindable.

array
formatChannels(array $channels)

Format the channel array into an array of strings.

binder()

Get the model binding registrar instance.

callable
normalizeChannelHandlerToCallable(mixed $callback)

Normalize the given callback into a callable.

mixed
retrieveUser(Request $request, string $channel)

Retrieve the authenticated user using the configured guard (if any).

array
retrieveChannelOptions(string $channel)

Retrieve options for a certain channel.

bool
channelNameMatchesPattern(string $channel, string $pattern)

Check if the channel name from the request matches a pattern from registered channels.

getChannels()

Get all of the registered channels.

static void
flushState()

Flush all static state.

__construct(Container $container, AblyRest $ably)

Create a new broadcaster instance.

mixed
auth(Request $request)

Authenticate the incoming request for a given channel.

mixed
validAuthenticationResponse(Request $request, mixed $result)

Return the valid authentication response.

string
generateAblySignature(string $channelName, string $socketId, array|null $userData = null)

Generate the signature needed for Ably authentication headers.

void
broadcast(array $channels, string $event, array $payload = [])

Broadcast the given event.

Message
buildAblyMessage(string $event, array $payload = [])

Build an Ably message object for broadcasting.

bool
isGuardedChannel(string $channel)

Return true if the channel is protected by authentication.

string
normalizeChannelName(string $channel)

Remove prefix from channel name.

string
getPublicToken()

Get the public token value from the Ably key.

string
getPrivateToken()

Get the private token value from the Ably key.

AblyRest
getAbly()

Get the underlying Ably SDK instance.

void
setAbly(AblyRest $ably)

Set the underlying Ably SDK instance.

Details

in Broadcaster at line 67
array|null resolveAuthenticatedUser(Request $request)

Resolve the authenticated user payload for the incoming connection request.

See: https://pusher.com/docs/channels/library_auth_reference/auth-signatures/#user-authentication.

Parameters

Request $request

Return Value

array|null

in Broadcaster at line 85
void resolveAuthenticatedUserUsing(Closure|null $callback)

Register the user retrieval callback used to authenticate connections.

Boot-only. The callback persists in instance state on the cached broadcaster for the worker lifetime; per-request use races across coroutines.

See: https://pusher.com/docs/channels/library_auth_reference/auth-signatures/#user-authentication.

Parameters

Closure|null $callback

Return Value

void

in Broadcaster at line 97
Broadcaster channel(HasBroadcastChannel|string $channel, callable|string $callback, array $options = [])

Register a channel authenticator.

Boot-only. The channel authorizer and options persist in shared static state on the Broadcaster class for the worker lifetime and apply to every subsequent connection authentication.

Parameters

HasBroadcastChannel|string $channel
callable|string $callback
array $options

Return Value

Broadcaster

in Broadcaster at line 118
static void formatChannelsUsing(Closure|null $callback)

Register the outgoing channel formatter.

Boot-only. The callback persists in shared static state for the worker lifetime and applies to every broadcaster across all coroutines.

Parameters

Closure|null $callback

Return Value

void

in Broadcaster at line 129
static void authorizeChannelsUsing(Closure|null $callback)

Register the incoming channel authorizer.

Boot-only. The callback persists in shared static state for the worker lifetime and applies to every broadcaster across all coroutines.

Parameters

Closure|null $callback

Return Value

void

in Broadcaster at line 139
protected mixed verifyUserCanAccessChannel(Request $request, string $channel, bool $guarded = false)

Authenticate the incoming request for a given channel.

Parameters

Request $request
string $channel
bool $guarded

Return Value

mixed

Exceptions

AccessDeniedHttpException

at line 62
protected mixed validAuthenticationResponseForChannel(Request $request, mixed $result, string $channel)

Return the valid authentication response for the authorized channel.

Parameters

Request $request
mixed $result
string $channel

Return Value

mixed

in Broadcaster at line 189
protected array extractAuthParameters(string $pattern, string $channel, callable|string $callback)

Extract the parameters from the given pattern and channel.

Parameters

string $pattern
string $channel
callable|string $callback

Return Value

array

in Broadcaster at line 205
protected array extractParameters(callable|string $callback)

Extracts the parameters out of what the user passed to handle the channel authentication.

Parameters

callable|string $callback

Return Value

array

in Broadcaster at line 221
protected array extractParametersFromClass(string $callback)

Extracts the parameters out of a class channel's "join" method.

Parameters

string $callback

Return Value

array

Exceptions

Exception

in Broadcaster at line 235
protected array extractChannelKeys(string $pattern, string $channel)

Extract the channel keys from the incoming channel name.

Parameters

string $pattern
string $channel

Return Value

array

in Broadcaster at line 245
protected mixed resolveBinding(string $key, string $value, array $callbackParameters)

Resolve the given parameter binding.

Parameters

string $key
string $value
array $callbackParameters

Return Value

mixed

in Broadcaster at line 259
protected mixed resolveExplicitBindingIfPossible(string $key, mixed $value)

Resolve an explicit parameter binding if applicable.

Parameters

string $key
mixed $value

Return Value

mixed

in Broadcaster at line 275
protected mixed resolveImplicitBindingIfPossible(string $key, string $value, array $callbackParameters)

Resolve an implicit parameter binding if applicable.

Parameters

string $key
string $value
array $callbackParameters

Return Value

mixed

Exceptions

AccessDeniedHttpException

in Broadcaster at line 297
protected bool isImplicitlyBindable(string $key, ReflectionParameter $parameter)

Determine if a given key and parameter is implicitly bindable.

Parameters

string $key
ReflectionParameter $parameter

Return Value

bool

at line 169
protected array formatChannels(array $channels)

Format the channel array into an array of strings.

Parameters

array $channels

Return Value

array

in Broadcaster at line 321
protected BindingRegistrar|null binder()

Get the model binding registrar instance.

Return Value

BindingRegistrar|null

in Broadcaster at line 338
protected callable normalizeChannelHandlerToCallable(mixed $callback)

Normalize the given callback into a callable.

Parameters

mixed $callback

Return Value

callable

in Broadcaster at line 348
protected mixed retrieveUser(Request $request, string $channel)

Retrieve the authenticated user using the configured guard (if any).

Parameters

Request $request
string $channel

Return Value

mixed

in Broadcaster at line 370
protected array retrieveChannelOptions(string $channel)

Retrieve options for a certain channel.

Parameters

string $channel

Return Value

array

in Broadcaster at line 386
protected bool channelNameMatchesPattern(string $channel, string $pattern)

Check if the channel name from the request matches a pattern from registered channels.

Parameters

string $channel
string $pattern

Return Value

bool

in Broadcaster at line 396
Collection getChannels()

Get all of the registered channels.

Return Value

Collection

in Broadcaster at line 404
static void flushState()

Flush all static state.

Return Value

void

at line 21
__construct(Container $container, AblyRest $ably)

Create a new broadcaster instance.

Parameters

Container $container
AblyRest $ably

at line 32
mixed auth(Request $request)

Authenticate the incoming request for a given channel.

Parameters

Request $request

Return Value

mixed

Exceptions

AccessDeniedHttpException

at line 50
mixed validAuthenticationResponse(Request $request, mixed $result)

Return the valid authentication response.

Parameters

Request $request
mixed $result

Return Value

mixed

at line 103
string generateAblySignature(string $channelName, string $socketId, array|null $userData = null)

Generate the signature needed for Ably authentication headers.

Parameters

string $channelName
string $socketId
array|null $userData

Return Value

string

at line 117
void broadcast(array $channels, string $event, array $payload = [])

Broadcast the given event.

Parameters

array $channels
string $event
array $payload

Return Value

void

Exceptions

BroadcastException

at line 135
protected Message buildAblyMessage(string $event, array $payload = [])

Build an Ably message object for broadcasting.

Parameters

string $event
array $payload

Return Value

Message

at line 147
bool isGuardedChannel(string $channel)

Return true if the channel is protected by authentication.

Parameters

string $channel

Return Value

bool

at line 155
string normalizeChannelName(string $channel)

Remove prefix from channel name.

Parameters

string $channel

Return Value

string

at line 185
protected string getPublicToken()

Get the public token value from the Ably key.

Return Value

string

at line 193
protected string getPrivateToken()

Get the private token value from the Ably key.

Return Value

string

at line 201
AblyRest getAbly()

Get the underlying Ably SDK instance.

Return Value

AblyRest

at line 209
void setAbly(AblyRest $ably)

Set the underlying Ably SDK instance.

Parameters

AblyRest $ably

Return Value

void