VOOZH about

URL: https://deepwiki.com/hypervel/support/7.2-broadcasting

⇱ Broadcasting | hypervel/support | DeepWiki


Loading...
Menu

Broadcasting

Purpose and Scope

This page documents the broadcasting system provided by the Broadcast facade, which enables real-time event broadcasting to clients over WebSocket connections. Broadcasting allows server-side events to be pushed to connected clients instantly, supporting features like notifications, live updates, and collaborative editing.

The broadcasting system provides channel management, multiple driver support (Pusher, Ably), channel authentication for private/presence channels, and integration with the event system. For information about dispatching events that trigger broadcasts, see Event System.

Broadcasting Architecture

The broadcasting system follows the Manager pattern to support multiple broadcast drivers and connection management. The Broadcast facade resolves to BroadcastingFactoryContract, which is implemented by BroadcastManager.


Sources: src/Facades/Broadcast.php1-58

Channel Types

Broadcasting supports three channel types, each with different authentication requirements:

Channel TypeMethodAuthenticationUse Case
PublicBroadcast::on()None requiredPublic announcements, status updates
PrivateBroadcast::private()RequiredUser-specific notifications, private data
PresenceBroadcast::presence()Required with user infoChat rooms, collaborative editing, online users

Public Channels

Public channels do not require authentication. Any client can subscribe to them.


Sources: src/Facades/Broadcast.php14

Private Channels

Private channels require authentication. The channel name is prefixed with private- and the server validates the subscription request.


Sources: src/Facades/Broadcast.php15-41

Presence Channels

Presence channels are private channels that track which users are subscribed. They provide member information and join/leave events.


Sources: src/Facades/Broadcast.php16

Broadcasting Events

The broadcasting system provides multiple methods for broadcasting events to channels.

Anonymous Event Broadcasting

The on(), private(), and presence() methods create AnonymousEvent instances that can be broadcast without defining a formal event class:


Sources: src/Facades/Broadcast.php14-16

Named Event Broadcasting

The event() method creates a PendingBroadcast instance that wraps a formal event object. This is used when broadcasting events that implement ShouldBroadcast:


Sources: src/Facades/Broadcast.php17

Queued Broadcasting

The queue() method broadcasts an event asynchronously via the queue system:


Sources: src/Facades/Broadcast.php18

Direct Broadcasting

The broadcast() method sends data directly to specified channels:

Sources: src/Facades/Broadcast.php43

Channel Authentication

Private and presence channels require authentication to prevent unauthorized subscriptions. The authentication flow involves registering channel authorization callbacks and validating subscription requests.

Authentication Flow


Sources: src/Facades/Broadcast.php41-42

Channel Registration

Channel authorization callbacks are registered using the channel() method:

ParameterTypeDescription
$channelstring|HasBroadcastChannelChannel name pattern (e.g., 'user.{id}')
$callbackcallable|stringAuthorization logic returning bool or user data
$optionsarrayAdditional channel options (guards, middleware)

The channel() method returns a Broadcaster instance and stores the channel definition in the channel registry accessible via getChannels().

Sources: src/Facades/Broadcast.php38-39

User Resolution

The broadcasting system needs to resolve the authenticated user for channel authorization:


Sources: src/Facades/Broadcast.php36-37

Broadcast Drivers

The broadcasting system supports multiple drivers through the Manager pattern. Each driver implements the Broadcaster contract.

Supported Drivers


Sources: src/Facades/Broadcast.php21-26

Pusher Driver

The pusher() method creates a Pusher SDK instance configured with the provided settings. Typical configuration includes:

Config KeyDescription
keyPusher application key
secretPusher application secret
app_idPusher application ID
optionsAdditional Pusher options (cluster, encryption)

Sources: src/Facades/Broadcast.php21

Ably Driver

The ably() method creates an Ably SDK instance for broadcasting via Ably's real-time platform:

Sources: src/Facades/Broadcast.php22

Custom Drivers

The extend() method allows registration of custom broadcast drivers:


Sources: src/Facades/Broadcast.php26

Route Registration

The broadcasting system provides methods to register authentication and socket ID routes.

Route Types



























MethodRoutes RegisteredPurpose
routes(array $attributes)Both auth and user routesRegister all broadcasting routes
userRoutes(array $attributes)User info route onlyRegister only the user info endpoint
channelRoutes(array $attributes)Auth route onlyRegister only the channel authorization endpoint

The $attributes parameter accepts route options like middleware, prefix, and domain constraints.

Sources: src/Facades/Broadcast.php10-12

Connection Management

The broadcasting system supports multiple broadcast connections and driver instances.

Driver Selection


Both connection() and driver() are aliases that return a Broadcaster instance. When called without arguments, they return the default driver.

Sources: src/Facades/Broadcast.php19-23

Default Driver Management

MethodDescription
getDefaultDriver()Returns the name of the default broadcast driver
setDefaultDriver(string $name)Sets the default driver for subsequent operations

Sources: src/Facades/Broadcast.php23-24

Driver Lifecycle











































MethodDescription
purge(string $name)Remove a specific driver instance from the pool
forgetDrivers()Clear all cached driver instances
addPoolable(string $driver)Mark a driver as poolable (reusable)
removePoolable(string $driver)Remove a driver from the poolable list
getPoolables()Get array of poolable driver names
setPoolables(array $poolables)Set the complete list of poolable drivers
setReleaseCallback(string $driver, Closure $callback)Set cleanup callback for driver release
getReleaseCallback(string $driver)Get the release callback for a driver

Sources: src/Facades/Broadcast.php25-35

Socket ID Management

The socket() method retrieves the socket ID from the current request, which is used to exclude the broadcasting client from receiving its own events:


When no request is provided, the method uses the current request from the container.

Sources: src/Facades/Broadcast.php13

Channel Management

The broadcasting system maintains a registry of all defined channels and their authorization callbacks.



























MethodReturn TypeDescription
channel($channel, $callback, $options)BroadcasterRegister a channel authorization callback
getChannels()CollectionRetrieve all registered channels
flushChannels()voidClear all registered channels

Sources: src/Facades/Broadcast.php38-40

Application Container Integration

The BroadcastManager maintains references to the PSR-11 container:


Sources: src/Facades/Broadcast.php27-28