arnislielturks / faye-laravel-broadcaster
Faye service laravel broadcaster
0.15
2017-04-27 11:37 UTC
Requires
- php: >=5.4
- arnislielturks/faye-client: ^0.16
- illuminate/broadcasting: ^5.4
Requires (Dev)
README
This is a wrapper for https://github.com/ArnisLielturks/faye-client library. Intended for use in Laravel 5+ applications. This allows broadcasting messages to Faye service via Laravel events
Installation
- Install the package via composer:
composer require arnislielturks/faye-laravel-broadcaster
- Register the provider in config/app.php
// 'providers' => [ ArnisLielturks\FayeBroadcaster\FayeBroadcasterProvider::class, // ];
- Add configuration file (config/faye.php) with the following content. This should point to the Faye service
return [ 'server' => 'http://127.0.0.1:8000' ];
- Change the broadcast driver to Faye in (config/broadcasting.php
default' => env('BROADCAST_DRIVER', 'faye'),
OR set this value in .env file
BROADCAST_DRIVER=faye
- Create event which will send out the broadcast via Faye service
class TestEvent implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; //All public attributes will be sent with the message public $id; public $event = 'test_event'; public function __construct() { $this->id = 123; } public function broadcastOn() { //List of channels where this event should be sent return ['/test_event']; } }
- Send out the event via Controller
class TestController extends Controller { public function test() { event(new TestEvent()); return view('main'); } }
Outgoing message to the /test_event channel will look something like this:
{ id: 123, event: 'test_event', socket: null, event_object: 'App\\Events\\TestEvent' }
That's it!