Sample Laravel backend for laravel_echo package. Before proceeding make sure you read detailed information from official Laravel Broadcasting documentation
Available integrations:
For authorizing private channels Laravel Sanctum is used.
- Clone this repo
composer installphp artisan migrate
Pusher related connection options available at /config/broadcasting.php. Most of time default options are enough.
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => false,
'encrypted' => false,
],
],Set driver in your .env file
BROADCAST_DRIVER=pusherAnd pusher related keys
PUSHER_APP_ID=your-pusher-app-id
PUSHER_APP_KEY=your-pusher-key
PUSHER_APP_SECRET=your-pusher-secret
PUSHER_APP_CLUSTER=your-pusher-clusterLaravel WebSockets is a package for Laravel 5.7 and up that will get your application started with WebSockets in no-time! It has a drop-in Pusher API replacement, has a debug dashboard, realtime statistics and even allows you to create custom WebSocket controllers.
Defined separate websockets connection that uses pusher driver in /config/broadcasting.php
'websockets' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'useTLS' => false,
'encrypted' => false,
'host' => '127.0.0.1',
'port' => 6001,
],
],Set driver in your .env file
BROADCAST_DRIVER=websocketsAnd your websocket server keys
PUSHER_APP_ID=local
PUSHER_APP_KEY=local
PUSHER_APP_SECRET=local
PUSHER_APP_CLUSTER=localAdditionally take a look at /config/websockets.php file
Start websockets server
php artisan websockets:serveNodeJs server for Laravel Echo broadcasting with Socket.io.
Notes
- As laravel-echo-server has issues with newer socket.io clients, in the fron-end
"socket.io-client": "^2.3.0"is used. - Echo server is configured to listen on
6002port
Set driver in your .env file
BROADCAST_DRIVER=redisRemoved redis prefix
REDIS_PREFIX=Additionally take a look at laravel-echo-server.json file.
Start Echo server
laravel-echo-server start