jilenloa / echo-socketcluster-broadcast-driver
Laravel socketcluster broadcaster. This is compatible with Laravel Echo client
Installs: 150
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:JavaScript
Requires
- php: >=7.1
- guzzlehttp/guzzle: ^6.2 || ^7.4
Requires (Dev)
- laravel/framework: ^5.8|^6.0|^7.0
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~4.0
Suggests
- laravel/framework: Framework Laravel (^5.8|^6.0|^7.0)
This package is auto-updated.
Last update: 2025-03-07 05:25:37 UTC
README
It's supported on PHP 7.1+, Laravel 5.8+
Before you can use this library, you first need to setup a server "echo-socketcluster-server". It works similarly to the default "laravel-echo-server". However, it is installed when you run the vendor:publish command. Find that below.
php artisan vendor:publish --tag=echosocketcluster
Echo Compatible Server using SocketCluster
The echo-socketcluster-server package is created using SocketCluster and it's part of this repo and you can copy it to any folder of your choice. It comes with its own package.json, so you would need to run the npm install command inside the folder afterwards.
For more information on SocketCluster, visit https://socketcluster.io/.
Laravel Installation
Install package using Composer
composer require jilenloa/echo-socketcluster-broadcast-driver:dev-master
Add below to your broadcasting.php file.
'echosocketcluster' => [ 'driver' => 'echosocketcluster', ],
Add this configuration to your .env file. Update the current setting for BROADCAST_DRIVER to the one below
BROADCAST_DRIVER=echosocketcluster #"redis" is also compatible with this broadcast server just like the default laravel-echo ECHO_SC_HOST=localhost:8001 ECHO_SC_TOKEN=echo-server-token REDIS_KEY_PREFIX=laravel_ # just like you would set in laravel-echo-server.json SOCKETCLUSTER_PORT=8001 SOCKETCLUSTER_WS_ENGINE=uws # defaule engine is "ws" SOCKETCLUSTER_HTTP_TOKEN=echo-server-token
If you have not done this, you can publish the configuration and echo-socketcluster-server files using the command:
php artisan vendor:publish --tag=echosocketcluster
You can then later update the package later using composer:
composer update
Laravel Echo Client
npm install laravel-echo npm install laravel-echo-connector-socketcluster
Below is a sample use of the Laravel Echo client.
import Echo from "laravel-echo"; import SocketClusterConnector from "laravel-echo-connector-socketcluster"; window.socketClusterClient = require('./socketcluster-client'); let echo = new Echo({ client: socketClusterClient, broadcaster: SocketClusterConnector, auth: { headers: { //add custom headers here, useful for JWT authentication }, hostname: 'localhost:8001', //laravel host to authorize channels. this is sometimes optional }, socketcluster: { hostname: 'localhost', port: 8001 } });
For more information on laravel-echo visit https://laravel.com/docs/broadcasting.
Finally
- Before testing, ensure that you have started the echo-socketcluster-server.
If you experience any challenge, don't hesitate to submit an issue here.