class Channel

Traits

Properties

protected ChannelConnectionManager $connections

The channel connections.

protected SubscriptionResult $lastSubscriptionResult

The result from the most recent shared state subscribe/unsubscribe call.

Methods

array
__serialize()

Prepare the channel instance values for serialization.

void
__unserialize(array $values)

Restore the channel after serialization.

__construct(string $name)

Create a new channel instance.

string
name()

Get the channel name.

array
connections()

Get all connections for the channel.

find(Connection $connection)

Find a connection.

findById(string $id)

Find a connection by its ID.

void
subscribe(Connection $connection, string|null $auth = null, string|null $data = null, string|null $userId = null)

Subscribe to the given channel.

void
handleChannelOccupied(Connection $connection, SharedState $sharedState)

Handle channel occupied — dispatch events, check disconnect smoothing.

lastSubscriptionResult()

Get the result from the most recent subscribe/unsubscribe shared state call.

void
unsubscribe(Connection $connection, string|null $userId = null)

Unsubscribe from the given channel.

void
handleChannelVacated(Connection $connection)

Handle channel vacated — remove from manager, dispatch events, clean up locks.

void
dispatchSubscriptionCountWebhook(Connection $connection)

Dispatch the subscription_count webhook if enabled and not throttled.

bool
subscribed(Connection $connection)

Determine if the connection is subscribed to the channel.

void
broadcast(array $payload, Connection|null $except = null)

Send a message to all connections subscribed to the channel.

void
broadcastToAll(array $payload)

Send a broadcast to all connections.

void
broadcastInternally(array $payload, Connection|null $except = null)

Broadcast a message triggered from an internal source.

array
data()

Get the data associated with the channel.

Details

in SerializesChannels at line 16
array __serialize()

Prepare the channel instance values for serialization.

Return Value

array

in SerializesChannels at line 26
void __unserialize(array $values)

Restore the channel after serialization.

Parameters

array $values

Return Value

void

at line 36
__construct(string $name)

Create a new channel instance.

Parameters

string $name

at line 44
string name()

Get the channel name.

Return Value

string

at line 54
array connections()

Get all connections for the channel.

Return Value

array

at line 62
ChannelConnection|null find(Connection $connection)

Find a connection.

Parameters

Connection $connection

Return Value

ChannelConnection|null

at line 70
ChannelConnection|null findById(string $id)

Find a connection by its ID.

Parameters

string $id

Return Value

ChannelConnection|null

at line 80
void subscribe(Connection $connection, string|null $auth = null, string|null $data = null, string|null $userId = null)

Subscribe to the given channel.

Presence channels pass the userId for global refcount tracking.

Parameters

Connection $connection
string|null $auth
string|null $data
string|null $userId

Return Value

void

at line 102
protected void handleChannelOccupied(Connection $connection, SharedState $sharedState)

Handle channel occupied — dispatch events, check disconnect smoothing.

Parameters

Connection $connection
SharedState $sharedState

Return Value

void

at line 146
protected SubscriptionResult lastSubscriptionResult()

Get the result from the most recent subscribe/unsubscribe shared state call.

Used by presence channel traits to check memberAdded/memberRemoved.

Return Value

SubscriptionResult

at line 156
void unsubscribe(Connection $connection, string|null $userId = null)

Unsubscribe from the given channel.

Presence channels pass the userId for global refcount tracking.

Parameters

Connection $connection
string|null $userId

Return Value

void

at line 176
protected void handleChannelVacated(Connection $connection)

Handle channel vacated — remove from manager, dispatch events, clean up locks.

Parameters

Connection $connection

Return Value

void

at line 218
protected void dispatchSubscriptionCountWebhook(Connection $connection)

Dispatch the subscription_count webhook if enabled and not throttled.

Fires on every subscribe/unsubscribe for non-presence channels. Throttled to once per 5 seconds for channels with >100 subscribers.

Parameters

Connection $connection

Return Value

void

at line 246
bool subscribed(Connection $connection)

Determine if the connection is subscribed to the channel.

Parameters

Connection $connection

Return Value

bool

at line 254
void broadcast(array $payload, Connection|null $except = null)

Send a message to all connections subscribed to the channel.

Parameters

array $payload
Connection|null $except

Return Value

void

at line 279
void broadcastToAll(array $payload)

Send a broadcast to all connections.

Parameters

array $payload

Return Value

void

at line 294
void broadcastInternally(array $payload, Connection|null $except = null)

Broadcast a message triggered from an internal source.

Parameters

array $payload
Connection|null $except

Return Value

void

at line 302
array data()

Get the data associated with the channel.

Return Value

array