laracomponents / centrifuge-broadcaster
Centrifuge broadcaster for laravel >= 5.3
Installs: 6 195
Dependents: 0
Suggesters: 0
Security: 0
Stars: 21
Watchers: 4
Forks: 10
Open Issues: 2
Requires
- php: >=5.6.4
- guzzlehttp/guzzle: ^6.2
- illuminate/broadcasting: ^5.3
- predis/predis: ^1.1
Requires (Dev)
- orchestra/testbench: ^3.3
- phpunit/phpunit: ^5.7|^6.1
This package is not auto-updated.
Last update: 2024-11-15 23:11:19 UTC
README
Introduction
Centrifuge broadcaster for laravel >= 5.3
Requirements
- PHP 5.6.4+ or newer
- Laravel 5.3 or newer
- Centrifugo Server 1.6.1 or newer (see here)
Installation
Require this package with composer:
composer require laracomponents/centrifuge-broadcaster
Open your config/app.php and add the following to the providers array:
'providers' => [ // ... LaraComponents\Centrifuge\CentrifugeServiceProvider::class, // And uncomment BroadcastServiceProvider App\Providers\BroadcastServiceProvider::class, ],
Open your config/broadcasting.php and add the following to it:
'connections' => [ 'centrifuge' => [ 'driver' => 'centrifuge', 'secret' => env('CENTRIFUGE_SECRET'), // you secret key 'url' => env('CENTRIFUGE_URL', 'http://localhost:8000'), // centrifuge api url 'redis_api' => env('CENTRIFUGE_REDIS_API', false), // enable or disable Redis API 'redis_connection' => env('CENTRIFUGE_REDIS_CONNECTION', 'default'), // name of redis connection 'redis_prefix' => env('CENTRIFUGE_REDIS_PREFIX', 'centrifugo'), // prefix name for queue in Redis 'redis_num_shards' => env('CENTRIFUGE_REDIS_NUM_SHARDS', 0), // number of shards for redis API queue 'verify' => env('CENTRIFUGE_VERIFY', false), // Verify host ssl if centrifuge uses this 'ssl_key' => env('CENTRIFUGE_SSL_KEY', null), // Self-Signed SSl Key for Host (require verify=true) ], // ... ],
For the redis configuration, add a new connection in config/database.php
'redis' => [ 'centrifuge' => [ 'host' => env('REDIS_HOST', '127.0.0.1'),, 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 0, ], // ... ],
You can also add a configuration to your .env file:
CENTRIFUGE_SECRET=very-long-secret-key
CENTRIFUGE_URL=http://localhost:8000
CENTRIFUGE_REDIS_API=false
CENTRIFUGE_REDIS_CONNECTION=centrifuge
CENTRIFUGE_REDIS_PREFIX=centrifugo
CENTRIFUGE_REDIS_NUM_SHARDS=0
CENTRIFUGE_SSL_KEY=/etc/ssl/some.pem
CENTRIFUGE_VERIFY=false
Do not forget to install the broadcast driver
BROADCAST_DRIVER=centrifuge
Basic Usage
To configure the Centrifugo server, read the official documentation
For broadcasting events, see the official documentation of laravel
A simple example of using the client:
<?php namespace App\Http\Controllers; use LaraComponents\Centrifuge\Centrifuge; class ExampleController extends Controller { public function home(Centrifuge $centrifuge) { // Send message into channel $centrifuge->publish('channel-name', [ 'key' => 'value' ]); // Generate token $token = $centrifuge->generateToken('user id', 'timestamp', 'info'); // Generate api sign $apiSign = $centrifuge->generateApiSign('data'); // ... } }
Available methods
License
The MIT License (MIT). Please see License File for more information.