lucify / broadcasting-centrifugo
This package is abandoned and no longer maintained.
The author suggests using the lucify/broadcasting-centrifugo package instead.
Lucify Broadcasting Centrifugo Driver
v1.0.1
2020-04-23 12:58 UTC
Requires
- php: >=7.2.12
- guzzlehttp/guzzle: ^6.3.3
- illuminate/broadcasting: ^7.0
- laravel/framework: ^7.0
Requires (Dev)
- orchestra/testbench: 4.0.*
- phpunit/phpunit: 8.3.*
This package is not auto-updated.
Last update: 2021-08-07 11:19:43 UTC
README
Centrifugo Broadcast driver
Introduction
It is Luzifer Centrifugo Broadcaster, based on:
Requirements
- PHP 7.4+ or newer = Luzifer or Laravel 7+
- Centrifugo Server 2.1.0 or newer (see here)
Dependencies
- guzzlehttp/guzzle
Installation
Require this package with composer:
composer require lucify/centrifugo
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'), '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) ],
Add these three lines to your .env file
CENTRIFUGO_SECRET=very-long-secret-key-from-centrifugo-config
CENTRIFUGO_APIKEY=long-secret-apikey-from-centrifugo-config
CENTRIFUGO_URL=http://your-centrifulo.url
These lines are optional
CENTRIFUGO_SSL_KEY=/etc/ssl/some.pem
CENTRIFUGO_VERIFY=true
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 Lucify\Broadcasting\Centrifugo\Socket; class ExampleController extends Controller { public function home(Socket $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
Name | Description |
---|---|
publish(string $channel, array $data) | Send message into channel. |
broadcast(array $channels, array $data) | Send message into multiple channel. |
presence(string $channel) | Get channel presence information (all clients currently subscribed on this channel). |
presence_stats(string $channel) | Get channel presence information in short form (number of clients). |
history(string $channel) | Get channel history information (list of last messages sent into channel). |
history_remove(string $channel) | Remove channel history information. |
unsubscribe(string $channel, string $user) | Unsubscribe user from channel. |
disconnect(string $user_id) | Disconnect user by it's ID. |
channels() | Get channels information (list of currently active channels). |
info() | Get stats information about running server nodes. |
generateConnectionToken(string $userId, int $exp, array $info) | Generate connection token. |
generatePrivateChannelToken(string $client, string $channel, int $exp, array $info) | Generate private channel token. |
License
The MIT License (MIT). Please see License File for more information.