arnislielturks / faye-laravel-broadcaster
Faye服务Laravel广播器
0.15
2017-04-27 11:37 UTC
Requires
- php: >=5.4
- arnislielturks/faye-client: ^0.16
- illuminate/broadcasting: ^5.4
Requires (Dev)
README
这是一个https://github.com/ArnisLielturks/faye-client库的包装器。旨在用于Laravel 5+应用程序。这允许通过Laravel事件将消息广播到Faye服务。
安装
- 使用composer安装包
composer require arnislielturks/faye-laravel-broadcaster
- 在config/app.php中注册提供者
// 'providers' => [ ArnisLielturks\FayeBroadcaster\FayeBroadcasterProvider::class, // ];
- 添加配置文件(config/faye.php),内容如下。这应该指向Faye服务
return [ 'server' => 'http://127.0.0.1:8000' ];
- 在(config/broadcasting.php)中将广播驱动器更改为Faye
default' => env('BROADCAST_DRIVER', 'faye'),
或者在.env文件中设置此值
BROADCAST_DRIVER=faye
- 创建一个通过Faye服务发送广播的事件
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']; } }
- 通过控制器发送事件
class TestController extends Controller { public function test() { event(new TestEvent()); return view('main'); } }
发往/test_event通道的出站消息看起来可能像这样
{ id: 123, event: 'test_event', socket: null, event_object: 'App\\Events\\TestEvent' }
就这样!