Download the PHP package opekunov/laravel-centrifugo-broadcaster without Composer
On this page you can find all versions of the php package opekunov/laravel-centrifugo-broadcaster. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download opekunov/laravel-centrifugo-broadcaster
More information about opekunov/laravel-centrifugo-broadcaster
Files in opekunov/laravel-centrifugo-broadcaster
Package laravel-centrifugo-broadcaster
Short Description Centrifugo broadcaster for Laravel 8.75-13.x and Centrifugo >= 5.0
License MIT
Homepage https://github.com/opekunov/laravel-centrifugo-broadcaster
Informations about the package laravel-centrifugo-broadcaster
Documentation EN | RU
Laravel Centrifugo 5-6 Broadcaster
Centrifugo 5-6 broadcast driver for Laravel 8.75 - 13.x
For Centrifugo 4.x use version 2.x
For Centrifugo 2.8 - 3.x use version 1.2.6
Features
- Compatible with latest Centrifugo 5.x and 6.x 🚀
- Uses new HTTP API format introduced in Centrifugo 5.x 📡
- Wrapper over Centrifugo HTTP API 🔌
- Authentication with JWT token (HMAC algorithm) 🗝️
Requirements
- PHP >= 8.0 (including 8.4)
- Laravel 8.75 - 13.x
- ext-json
- Centrifugo Server 5.x or newer (see here)
Installation
For Centrifugo 4.x use version 2.x
For Centrifugo 2.8 - 3.x use version 1.2.6
Features
- Compatible with latest Centrifugo 5.x and 6.x 🚀
- Uses new HTTP API format introduced in Centrifugo 5.x 📡
- Wrapper over Centrifugo HTTP API 🔌
- Authentication with JWT token (HMAC algorithm) 🗝️
Requirements
- PHP >= 8.0 (including 8.4)
- Laravel 8.75 - 13.x
- ext-json
- Centrifugo Server 5.x or newer (see here)
Installation
Require this package with composer:
Laravel 10 and below: Open your config/app.php and uncomment BroadcastServiceProvider:
Laravel 11+: Run the install command which will automatically create the necessary configuration:
Open your config/broadcasting.php and add new connection like this:
Also you should add these two lines to your .env file:
These lines are optional:
Don't forget to change the broadcast driver setting in your .env file!
Laravel 11+:
Laravel 10 and below:
Basic Usage
To configure Centrifugo server, read official documentation
For broadcasting events, see official documentation of laravel
Channel authentication example:
Laravel
Frontend. See documentation centrifugal/centrifuge-js
Broadcasting example
Create event (for example SendMessage) with artisan php artisan make:event SendMessageEvent
A simple client usage example:
History example
Centrifugo allows you to retrieve the history of messages in a channel (the channel must have history configured on the server side).
Backend (Laravel):
Frontend (centrifuge-js):
Presence example
Presence allows you to see which users are currently subscribed to a channel (must be enabled in Centrifugo server config).
Backend (Laravel):
Frontend (centrifuge-js):
Server-side subscribe/unsubscribe example
You can manage subscriptions from the backend without client involvement:
Available methods
| Name | Description |
|---|---|
| publish(string $channel, array $data) | Send message into channel. |
| broadcast(array $channels, array $data) | Send message into multiple channel. |
| publishMany(array $data) | Send multiple data to multiple channels. $data - array of data arrays [channel, data] |
| presence(string $channel) | Get channel presence information (all clients currently subscribed on this channel). |
| presenceStats(string $channel) | Get channel presence information in short form (number of clients). |
| history(string $channel, int $limit = 0, ?int $offset = null, ?string $epoch = null, bool $reverse = false) | Get channel history information (list of last messages sent into channel). |
| historyRemove(string $channel) | Remove channel history information. |
| subscribe(string $channel, string $user, array $info = [], array $data = []) | Subscribe user to channel (server-side). |
| unsubscribe(string $channel, string $user) | Unsubscribe user from channel. |
| disconnect(string $userId) | Disconnect user by it's ID. |
| rpc(string $method, array $data = []) | Remote procedure call. |
| channels(string $pattern = '') | Get channels information (list of currently active channels). |
| info() | Get stats information about running server nodes. |
| generateConnectionToken(string|int $userId, int|Carbon $exp = 0, array $info = [], array $channels = []) | Generate connection token. |
| generateSubscriptionToken(string|int $userId, string $channel, int|Carbon $exp = 0, array $info = [], array $override = []) | Generate subscription token. |
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-centrifugo-broadcaster with dependencies
laravel/framework Version ^8.75|^9.0|^10.0|^11.0|^12.0|^13.0
ext-json Version *