From 0fc34dc2ac57928480287118f389bea10751b2bd Mon Sep 17 00:00:00 2001 From: Julio Cesar Date: Thu, 18 Dec 2025 15:47:22 -0300 Subject: [PATCH 1/2] [12.x] Add Reverb events documentation --- reverb.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/reverb.md b/reverb.md index 58253194af..4a1ff68806 100644 --- a/reverb.md +++ b/reverb.md @@ -11,6 +11,9 @@ - [Debugging](#debugging) - [Restarting](#restarting) - [Monitoring](#monitoring) +- [Events](#events) + - [Dispatched Events](#dispatched-events) + - [Listening for Events](#listening-for-events) - [Running Reverb in Production](#production) - [Open Files](#open-files) - [Event Loop](#event-loop) @@ -192,6 +195,66 @@ Next, add the Pulse cards for each recorder to your [Pulse dashboard](/docs/{{ve Connection activity is recorded by polling for new updates on a periodic basis. To ensure this information is rendered correctly on the Pulse dashboard, you must run the `pulse:check` daemon on your Reverb server. If you are running Reverb in a [horizontally scaled](#scaling) configuration, you should only run this daemon on one of your servers. + +## Events + +Reverb dispatches internal events during the lifecycle of a connection and message handling. You may listen for these events using [Laravel Event Listener](/docs/{{version}}/events) to perform actions when connections are managed or messages are exchanged. + + +### Dispatched Events + +The following events are dispatched by Reverb: + +
+ +| Event Name | Class | Description | +| --- | --- | --- | +| ChannelCreated | [`Laravel\Reverb\Events\ChannelCreated`](https://github.com/laravel/reverb/blob/main/src/Events/ChannelCreated.php) | Dispatched when a channel is created. This typically occurs when the first connection subscribes to a specific channel. The event receives the `Laravel\Reverb\Protocols\Pusher\Channel` instance. | +| ChannelRemoved | [`Laravel\Reverb\Events\ChannelRemoved`](https://github.com/laravel/reverb/blob/main/src/Events/ChannelRemoved.php) | Dispatched when a channel is removed. This typically occurs when the last connection unsubscribes from a channel. The event receives the `Laravel\Reverb\Protocols\Pusher\Channel` instance. | +| ConnectionPruned | [`Laravel\Reverb\Events\ConnectionPruned`](https://github.com/laravel/reverb/blob/main/src/Events/ConnectionPruned.php) | Dispatched when a stale connection is pruned by the server. The event receives the `Laravel\Reverb\Contracts\Connection` instance. | +| MessageReceived | [`Laravel\Reverb\Events\MessageReceived`](https://github.com/laravel/reverb/blob/main/src/Events/MessageReceived.php) | Dispatched when a message is received from a client connection. The event receives the `Laravel\Reverb\Contracts\Connection` instance and the raw string `$message`. | +| MessageSent | [`Laravel\Reverb\Events\MessageSent`](https://github.com/laravel/reverb/blob/main/src/Events/MessageSent.php) | Dispatched when a message is sent to a client connection. The event receives the `Laravel\Reverb\Contracts\Connection` instance and the raw string `$message`. | + +
+ + +### Listening for Events + +As these events are dispatched internally by Reverb, you cannot modify them directly. However, you can listen for them by defining a listener in your application. + +First, create a listener using the `make:listener` Artisan command: + +```shell +php artisan make:listener LogMessageReceived --event="\Laravel\Reverb\Events\MessageReceived" +``` + +Next, define the logic in your listener's `handle` method. You may access the connection and message data via the event's public properties: + +```php +message; + + // Access the connection details... + $socketId = $event->connection->id(); + } +} +``` + +Finally, ensure your listener is registered in your application's [AppServiceProvider](/docs/{{version}}/events#manually-registering-events) or automatically discovered if you are using event discovery. + ## Running Reverb in Production From 4275e4470e8bb4e32037a1d5b98d56308533c31a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 19 Dec 2025 14:01:35 -0600 Subject: [PATCH 2/2] formatting --- reverb.md | 91 +++++++++++++++++-------------------------------------- 1 file changed, 28 insertions(+), 63 deletions(-) diff --git a/reverb.md b/reverb.md index 4a1ff68806..0d968e91ac 100644 --- a/reverb.md +++ b/reverb.md @@ -11,9 +11,6 @@ - [Debugging](#debugging) - [Restarting](#restarting) - [Monitoring](#monitoring) -- [Events](#events) - - [Dispatched Events](#dispatched-events) - - [Listening for Events](#listening-for-events) - [Running Reverb in Production](#production) - [Open Files](#open-files) - [Event Loop](#event-loop) @@ -21,6 +18,7 @@ - [Ports](#ports) - [Process Management](#process-management) - [Scaling](#scaling) +- [Events](#events) ## Introduction @@ -195,66 +193,6 @@ Next, add the Pulse cards for each recorder to your [Pulse dashboard](/docs/{{ve Connection activity is recorded by polling for new updates on a periodic basis. To ensure this information is rendered correctly on the Pulse dashboard, you must run the `pulse:check` daemon on your Reverb server. If you are running Reverb in a [horizontally scaled](#scaling) configuration, you should only run this daemon on one of your servers. - -## Events - -Reverb dispatches internal events during the lifecycle of a connection and message handling. You may listen for these events using [Laravel Event Listener](/docs/{{version}}/events) to perform actions when connections are managed or messages are exchanged. - - -### Dispatched Events - -The following events are dispatched by Reverb: - -
- -| Event Name | Class | Description | -| --- | --- | --- | -| ChannelCreated | [`Laravel\Reverb\Events\ChannelCreated`](https://github.com/laravel/reverb/blob/main/src/Events/ChannelCreated.php) | Dispatched when a channel is created. This typically occurs when the first connection subscribes to a specific channel. The event receives the `Laravel\Reverb\Protocols\Pusher\Channel` instance. | -| ChannelRemoved | [`Laravel\Reverb\Events\ChannelRemoved`](https://github.com/laravel/reverb/blob/main/src/Events/ChannelRemoved.php) | Dispatched when a channel is removed. This typically occurs when the last connection unsubscribes from a channel. The event receives the `Laravel\Reverb\Protocols\Pusher\Channel` instance. | -| ConnectionPruned | [`Laravel\Reverb\Events\ConnectionPruned`](https://github.com/laravel/reverb/blob/main/src/Events/ConnectionPruned.php) | Dispatched when a stale connection is pruned by the server. The event receives the `Laravel\Reverb\Contracts\Connection` instance. | -| MessageReceived | [`Laravel\Reverb\Events\MessageReceived`](https://github.com/laravel/reverb/blob/main/src/Events/MessageReceived.php) | Dispatched when a message is received from a client connection. The event receives the `Laravel\Reverb\Contracts\Connection` instance and the raw string `$message`. | -| MessageSent | [`Laravel\Reverb\Events\MessageSent`](https://github.com/laravel/reverb/blob/main/src/Events/MessageSent.php) | Dispatched when a message is sent to a client connection. The event receives the `Laravel\Reverb\Contracts\Connection` instance and the raw string `$message`. | - -
- - -### Listening for Events - -As these events are dispatched internally by Reverb, you cannot modify them directly. However, you can listen for them by defining a listener in your application. - -First, create a listener using the `make:listener` Artisan command: - -```shell -php artisan make:listener LogMessageReceived --event="\Laravel\Reverb\Events\MessageReceived" -``` - -Next, define the logic in your listener's `handle` method. You may access the connection and message data via the event's public properties: - -```php -message; - - // Access the connection details... - $socketId = $event->connection->id(); - } -} -``` - -Finally, ensure your listener is registered in your application's [AppServiceProvider](/docs/{{version}}/events#manually-registering-events) or automatically discovered if you are using event discovery. - ## Running Reverb in Production @@ -379,3 +317,30 @@ REVERB_SCALING_ENABLED=true Next, you should have a dedicated, central Redis server to which all of the Reverb servers will communicate. Reverb will use the [default Redis connection configured for your application](/docs/{{version}}/redis#configuration) to publish messages to all of your Reverb servers. Once you have enabled Reverb's scaling option and configured a Redis server, you may simply invoke the `reverb:start` command on multiple servers that are able to communicate with your Redis server. These Reverb servers should be placed behind a load balancer that distributes incoming requests evenly among the servers. + + +## Events + +Reverb dispatches internal events during the lifecycle of a connection and message handling. You may [listen for these events](/docs/{{version}}/events) to perform actions when connections are managed or messages are exchanged. + +The following events are dispatched by Reverb: + +#### `Laravel\Reverb\Events\ChannelCreated` + +Dispatched when a channel is created. This typically occurs when the first connection subscribes to a specific channel. The event receives the `Laravel\Reverb\Protocols\Pusher\Channel` instance. + +#### `Laravel\Reverb\Events\ChannelRemoved` + +Dispatched when a channel is removed. This typically occurs when the last connection unsubscribes from a channel. The event receives the `Laravel\Reverb\Protocols\Pusher\Channel` instance. + +#### `Laravel\Reverb\Events\ConnectionPruned` + +Dispatched when a stale connection is pruned by the server. The event receives the `Laravel\Reverb\Contracts\Connection` instance. + +#### `Laravel\Reverb\Events\MessageReceived` + +Dispatched when a message is received from a client connection. The event receives the `Laravel\Reverb\Contracts\Connection` instance and the raw string `$message`. + +#### `Laravel\Reverb\Events\MessageSent` + +Dispatched when a message is sent to a client connection. The event receives the `Laravel\Reverb\Contracts\Connection` instance and the raw string `$message`.