kot13 / laracent
Centrifugo broadcaster for laravel >= 5.7 and Centrifugo >= 2.1.0
Requires
- php: >=7.2.12
- guzzlehttp/guzzle: ^6.2
- illuminate/broadcasting: ^5.3
Requires (Dev)
- orchestra/testbench: ^3.3
- phpunit/phpunit: ^5.7|^6.1
This package is auto-updated.
Last update: 2024-11-22 02:39:10 UTC
README
Centrifugo broadcast driver for Laravel 5
Introduction
Centrifugo broadcaster for laravel >= 5.7 is fork of centrifuge-broadcaster, based on:
Changenotes
- predis/predis removed from dependencies
- Removed all code, related to Redis
- Updated public functions code in accordance with new version of Centrifugo API
Requirements
- PHP 7.2.12+ or newer
- Laravel 5.7 or newer
- Centrifugo Server 2.1.0 or newer (see here)
Dependencies
- guzzlehttp/guzzle
Installation
Require this package with composer:
composer require alex-hnydiuk/laracent
Open your config/app.php and add the following to the providers array:
'providers' => [ // ... AlexHnydiuk\Laracent\LaracentServiceProvider::class, // And uncomment BroadcastServiceProvider App\Providers\BroadcastServiceProvider::class, ],
Open your config/broadcasting.php and add new connection like this:
'centrifugo' => [ 'driver' => 'centrifugo', 'secret' => env('CENTRIFUGO_SECRET'), 'apikey' => env('CENTRIFUGO_APIKEY'), 'url' => env('CENTRIFUGO_URL', 'http://localhost:8000'), // centrifugo api url 'verify' => env('CENTRIFUGO_VERIFY', false), // Verify host ssl if centrifugo uses this 'ssl_key' => env('CENTRIFUGO_SSL_KEY', null), // Self-Signed SSl Key for Host (require verify=true) ],
Also you should add these two lines to your .env file:
CENTRIFUGO_SECRET=very-long-secret-key-from-centrifugo-config
CENTRIFUGO_APIKEY=long-secret-apikey-from-centrifugo-config
These lines are optional:
CENTRIFUGO_URL=http://localhost:8000
CENTRIFUGO_SSL_KEY=/etc/ssl/some.pem
CENTRIFUGO_VERIFY=false
Don't forget to change BROADCAST_DRIVER
setting in .env file!
BROADCAST_DRIVER=centrifugo
Basic Usage
To configure Centrifugo server, read official documentation
For broadcasting events, see official documentation of laravel
A simple client usage example:
<?php namespace App\Http\Controllers; use AlexHnydiuk\Laracent\Laracent; class ExampleController extends Controller { public function home(Laracent $centrifugo) { // Send message into channel $centrifugo->publish('channel-name', [ 'key' => 'value' ]); // Generate connection token $token = $centrifugo->generateConnectionToken('user id', 'timestamp', 'info'); // Generate private channel token $apiSign = $centrifuge->generatePrivateChannelToken('client', 'channel', 'timestamp', 'info'); // ... } }
Available methods
License
The MIT License (MIT). Please see License File for more information.