### Install Laravel Wave Package and Broadcasting Setup Source: https://github.com/qruto/laravel-wave/blob/main/README.md This command installs the Laravel Wave package via Composer, which is required for Laravel 11 or higher, and then runs the artisan command to set up the broadcasting configuration for your Laravel application. ```bash composer require qruto/laravel-wave php artisan install:broadcasting ``` -------------------------------- ### Install Laravel Wave with Composer and npm Source: https://github.com/qruto/laravel-wave/blob/main/README.md This snippet shows how to install the Laravel Wave package on both server and client sides using Composer for PHP dependencies and npm for JavaScript dependencies. ```bash composer require qruto/laravel-wave npm install laravel-wave ``` -------------------------------- ### Configure Laravel Echo with WaveConnector Source: https://github.com/qruto/laravel-wave/blob/main/README.md This JavaScript snippet demonstrates how to import Echo and WaveConnector and then initialize window.Echo to use WaveConnector as the broadcaster, enabling real-time communication via Laravel Wave. This is for manual setup. ```javascript import Echo from 'laravel-echo'; import { WaveConnector } from 'laravel-wave'; window.Echo = new Echo({broadcaster: WaveConnector}); ``` -------------------------------- ### Update Laravel Echo Configuration for Wave (Laravel 10/Lower) Source: https://github.com/qruto/laravel-wave/blob/main/README.md This diff shows the changes required in resources/js/bootstrap.js for Laravel 10 or lower to switch from Pusher to WaveConnector for Laravel Echo, removing the old configuration and adding the new Wave-specific setup. ```diff - import Echo from 'laravel-echo'; - import Pusher from 'pusher-js'; - window.Pusher = Pusher; - window.Echo = new Echo({ - broadcaster: 'pusher', - key: import.meta.env.VITE_PUSHER_APP_KEY, - wsHost: import.meta.env.VITE_PUSHER_HOST ?? `ws-${import.meta.env.VITE_PUSHER_APP_CLUSTER}.pusher.com`, - wsPort: import.meta.env.VITE_PUSHER_PORT ?? 80, - wssPort: import.meta.env.VITE_PUSHER_PORT ?? 443, - forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? 'https') === 'https', - enabledTransports: ['ws', 'wss'], - }); + import Echo from 'laravel-echo'; + import { WaveConnector } from 'laravel-wave'; + window.Echo = new Echo({ broadcaster: WaveConnector }); ``` -------------------------------- ### Wave/Echo Client Configuration Options Reference Source: https://github.com/qruto/laravel-wave/blob/main/README.md Defines the available configuration options for `Wave` and `Echo` instances, detailing their names, types, default values, and descriptions for connection, authentication, and behavior. ```APIDOC endpoint: Type: string Default: /wave Description: Primary SSE connection route. namespace: Type: string Default: App.Events Description: Namespace of events to listen for. auth.headers: Type: object Default: {} Description: Additional authentication headers. authEndpoint: Type: string? Default: /broadcasting/auth Description: Authentication endpoint. csrfToken: Type: string? Default: undefined or string Description: CSRF token, defaults from XSRF-TOKEN cookie. bearerToken: Type: string? Default: undefined Description: Bearer tokenfor authentication. request: Type: [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options)? Default: undefined Description: Custom settings for connection and authentication requests. pauseInactive: Type: boolean Default: false Description: If true, closes connection when the page is hidden and reopens when visible. debug: Type: boolean Default: false Description: Toggles debug mode. If set to true, provides detailed event logs in the console, helping with event diagnosis and troubleshooting. ``` -------------------------------- ### Run Project Tests Source: https://github.com/qruto/laravel-wave/blob/main/README.md Command to execute the project's test suite using Composer. ```bash composer test ``` -------------------------------- ### Initialize Wave and Echo with Custom Options Source: https://github.com/qruto/laravel-wave/blob/main/README.md Demonstrates how to instantiate `Echo` with a custom broadcaster and endpoint, and `Wave` with specific authentication settings like `authEndpoint` and `csrfToken`. ```javascript new Echo({ broadcaster: WaveConnector, endpoint: '/sse-endpoint', bearerToken: 'bearer-token', //... }); // or new Wave({ authEndpoint: '/custom-broadcasting/auth', csrfToken: 'csrf-token', }) ``` -------------------------------- ### Send SSE Ping Event at Interval Source: https://github.com/qruto/laravel-wave/blob/main/README.md Demonstrates how to manually send Server-Sent Events (SSE) ping events using the `sse:ping` Artisan command with a specified interval to maintain persistent connections. ```bash php artisan sse:ping --interval=30 ``` -------------------------------- ### Publish Laravel Wave Configuration File Source: https://github.com/qruto/laravel-wave/blob/main/README.md This command publishes the default configuration file for Laravel Wave to your application's config directory, allowing you to customize various server options such as event stream lifetime, reconnection attempts, and ping settings. ```bash php artisan vendor:publish --tag="wave-config" ``` -------------------------------- ### Schedule SSE Ping Event with Laravel Scheduler Source: https://github.com/qruto/laravel-wave/blob/main/README.md Shows how to use Laravel's task scheduler to automatically send an SSE ping event every minute, ensuring connection persistence, especially when `fastcgi_read_timeout` is greater than 60s. ```php protected function schedule(Schedule $schedule) { $schedule->command('sse:ping')->everyMinute(); } ``` -------------------------------- ### Laravel Wave Server Configuration Options (config/wave.php) Source: https://github.com/qruto/laravel-wave/blob/main/README.md This PHP array defines the core server-side configuration for Laravel Wave. It includes settings for `resume_lifetime` (event history duration), `retry` (client reconnection delay), `ping` (heartbeat mechanism for persistent connections), `path` (route registration), `middleware` (route protection), and `auth_middleware`/`guard` (authentication for presence channels and whisper events). ```php return [ /* |-------------------------------------------------------------------------- | Resume Lifetime |-------------------------------------------------------------------------- | | Define how long (in seconds) you wish an event stream to persist so it | can be resumed after a reconnect. The connection automatically | re-establishes with every closed response. | | * Requires a cache driver to be configured. | */ 'resume_lifetime' => 60, /* |-------------------------------------------------------------------------- | Reconnection Time |-------------------------------------------------------------------------- | | This value determines how long (in milliseconds) to wait before | attempting a reconnect to the server after a connection has been lost. | By default, the client attempts to reconnect immediately. For more | information, please refer to the Mozilla developer's guide on event | stream format. | https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format | */ 'retry' => null, /* |-------------------------------------------------------------------------- | Ping |-------------------------------------------------------------------------- | | A ping event is automatically sent on every SSE connection request if the | last event occurred before the set `frequency` value (in seconds). This | ensures the connection remains persistent. | | By setting the `eager_env` option, a ping event will be sent with each | request. This is useful for development or for applications that do not | frequently expect events. The `eager_env` option can be set as an `array` or `null`. | | For manual control of the ping event with the `sse:ping` command, you can | disable this option. | */ 'ping' => [ 'enable' => true, 'frequency' => 30, 'eager_env' => 'local', // null or array ], /* |-------------------------------------------------------------------------- | Routes Path |-------------------------------------------------------------------------- | | This path is used to register the necessary routes for establishing the | Wave connection, storing presence channel users, and handling simple whisper events. | */ 'path' => 'wave', /* |-------------------------------------------------------------------------- | Route Middleware |-------------------------------------------------------------------------- | | Define which middleware Wave should assign to the routes that it registers. | You may modify these middleware as needed. However, the default value is | typically sufficient. | */ 'middleware' => [ 'web', ], /* |-------------------------------------------------------------------------- | Auth & Guard |-------------------------------------------------------------------------- | | Define the default authentication middleware and guard type for | authenticating users for presence channels and whisper events. | */ 'auth_middleware' => 'auth', 'guard' => 'web', ]; ``` -------------------------------- ### Listen to Eloquent Model Events with Wave API Source: https://github.com/qruto/laravel-wave/blob/main/README.md This JavaScript snippet demonstrates how to initialize the Wave instance and then use its model method to subscribe to various Eloquent model events (e.g., notification, updated, deleted, trashed, restored) for specific models and IDs. ```javascript import { Wave } from 'laravel-wave'; window.Wave = new Wave(); wave.model('User', '1') .notification('team.invite', (notification) => { console.log(notification); }) .updated((user) => console.log('user updated', user)) .deleted((user) => console.log('user deleted', user)) .trashed((user) => console.log('user trashed', user)) .restored((user) => console.log('user restored', user)) .updated('Team', (team) => console.log('team updated', team)); ``` -------------------------------- ### Customize Wave Model Namespace Configuration Source: https://github.com/qruto/laravel-wave/blob/main/README.md This JavaScript snippet shows how to configure the Wave instance with a custom namespace option. This allows users to specify a different base namespace for their Eloquent models, overriding the default App.Models prefix. ```javascript window.Wave = new Wave({namespace: 'App.Path.Models'}); ``` -------------------------------- ### Set Redis as Laravel Broadcasting Driver Source: https://github.com/qruto/laravel-wave/blob/main/README.md This configuration snippet updates the .env file to specify 'redis' as the broadcasting driver for Laravel, which is required for Laravel Wave to function correctly. ```ini BROADCAST_DRIVER = redis ``` -------------------------------- ### Disable PHP FPM Request Terminate Timeout Source: https://github.com/qruto/laravel-wave/blob/main/README.md Illustrates how to disable the `request_terminate_timeout` setting in PHP FPM configuration to prevent requests from being terminated after a specific duration, useful for long-running SSE connections. ```ini request_terminate_timeout = 0 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.