socketbus / socketbus-laravel
There is no license information available for the latest version (v1.0.1) of this package.
v1.0.1
2021-01-06 21:09 UTC
Requires
- php: >=5.3.0
- socketbus/socketbus-php: ^1.0.1
Requires (Dev)
- orchestra/testbench: ^3.8
This package is auto-updated.
Last update: 2024-09-07 05:33:08 UTC
README
Installation
composer require socketbus/socketbus-laravel
Configuration
Add the SocketBus driver in your config/broadcasting.php
.
return [ 'connections' => [ /** ... */ 'socketbus' => [ 'driver' => 'socketbus', 'app_id' => env('SOCKET_BUS_APP_ID'), 'secret' => env('SOCKET_BUS_SECRET'), 'custom_encryption_key' => env('SOCKET_BUS_ENCRYPTION_KEY') ] ] ];
In your .env file change BROADCAST_DRIVER
to socketbus
.
Define in your .env SOCKET_BUS_APP_ID
, SOCKET_BUS_SECRET
. If the setting End-to-end Encryption is enabled, add the SOCKET_BUS_ENCRYPTION_KEY
with a random unique string. This key is used to encrypt and decrypt the payloads.
Broadcasting
Define your event
namespace App\Events; use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Broadcasting\PresenceChannel; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; class MyEventEvent implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; /** * Create a new event instance. * * @return void */ public function __construct() { } /** * Get the channels the event should broadcast on. * * @return \Illuminate\Broadcasting\Channel|array */ public function broadcastOn() { return new PrivateChannel("my-event"); } }
Send the event in real-time
use App\Events\MyEventEvent; // sends a realtime message to browser broadcast(new MyEventEvent());