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 install
php 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=pusher
And 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-cluster
Laravel 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=websockets
And your websocket server keys
PUSHER_APP_ID=local
PUSHER_APP_KEY=local
PUSHER_APP_SECRET=local
PUSHER_APP_CLUSTER=local
Additionally take a look at /config/websockets.php
file
Start websockets server
php artisan websockets:serve
NodeJs 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
6002
port
Set driver in your .env
file
BROADCAST_DRIVER=redis
Removed redis prefix
REDIS_PREFIX=
Additionally take a look at laravel-echo-server.json
file.
Start Echo server
laravel-echo-server start