-
-
Save 1mursaleen/2f2265976d59267f3bfccb339b27be44 to your computer and use it in GitHub Desktop.
I'll start with the basics and proceed to addressing the common problems faced while setting up private channels with laravel-echo & laravel-echo-server. | |
I'll try to cover eveything and try to use appropriate highlighting to single out each common problem. | |
Install | |
npm install laravel-echo | |
npm install laravel-echo-server | |
npm install laravel-echo-server -g | |
note that I've installed 'laravel-echo-server' globally and locally in the project. | |
Global installation will allow us to use cli commands for this package, like 'laravel-echo-server init' | |
Local installation because of this good practice: https://medium.com/@titasgailius/running-laravel-echo-server-the-right-way-32f52bb5b1c8 | |
--- | |
In config/app.php | |
Comment out the line below | |
App\Providers\BroadcastServiceProvider::class, | |
--- | |
In .env, you must set these variables: | |
APP_URL=http://your_domain.com | |
// common mistake: be carefull while setting the scheme 'http' or 'https' in both local and production environments. | |
APP_NAME=YourAppName | |
// I'd suggest you use a clean name without underscores, hyphens, periods or any symbols. | |
JWT_SECRET=random_string | |
JWT_TTL=1440 | |
// set these only if you are using this package for jwt authentication https://github.com/tymondesigns/jwt-auth | |
CACHE_DRIVER=redis // optional but I'd suggest redis | |
SESSION_DRIVER=redis // optional but I'd suggest redis | |
QUEUE_CONNECTION=redis // this refers to the config/queue.php file | |
BROADCAST_DRIVER=redis | |
Important Note: | |
your Redis installation has 0 to 16 DBs | |
If you plan to use redis as CACHE_DRIVER, SESSION_DRIVER and BROADCAST_DRIVER -- which I'd certainly suggest -- you must use different DB for each driver. | |
It is widely reported by many laravel developers that redis pub/sub for BROADCAST_DRIVER is affected if a single redis db is used. | |
To use different DBs make the below entries in .env, each of these we'll set in config/database.php as redis connections. | |
REDIS_DB=0 | |
REDIS_CACHE_DB=1 | |
REDIS_BROADCAST_DB=2 | |
--- | |
In config/database.php, at the bottom there is 'Redis Databases' section in which redis's 'default' & 'cache' connections are defined like this | |
'default' => [ | |
'url' => env('REDIS_URL'), | |
'host' => env('REDIS_HOST', '127.0.0.1'), | |
'password' => env('REDIS_PASSWORD', null), | |
'port' => env('REDIS_PORT', 6379), | |
'database' => env('REDIS_DB', 0), | |
], | |
'cache' => [ | |
'url' => env('REDIS_URL'), | |
'host' => env('REDIS_HOST', '127.0.0.1'), | |
'password' => env('REDIS_PASSWORD', null), | |
'port' => env('REDIS_PORT', 6379), | |
'database' => env('REDIS_CACHE_DB', 1), | |
], | |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
where is auth routes configured?
Thanks, kind man!
Setting up websockets with vue and laravel echo is a pain in the ass. Used 8hrs+ and still not getting it to run
This is a fantastic help. Had I found the key that as of Jan 2021 at least, you must use socket.io-client version 2.3.0, not version 3.0, it would have saved me many (more) hours of head-banging.
you must use socket.io-client version 2.3.0, not version 3.0, it would have saved me many (more) hours of head-banging.
Thanks, I wasted two weeks because of the version
Setting up websockets with vue and laravel echo is a pain in the ass. Used 8hrs+ and still not getting it to run
Just if you are wondering, there is this prefix on laravel-echo for client side, called, private, so if you have a laravel private channel xyz, for laravel echo to work, you need to rename it to private-xyz then only It will work.
I have this error and I don't know what can solve it.
laravel-echo-server_1 | [12:20:31 AM] - Sending auth request to: localhost/broadcasting/auth
laravel-echo-server_1 |
laravel-echo-server_1 | [12:20:31 AM] - Error authenticating wcoGigP-jG_jjDARAAAL for private-athletes.1
laravel-echo-server_1 | Error: Invalid URI "localhost/broadcasting/auth"
laravel-echo-server_1 | at Request.init (/usr/src/app/node_modules/request/request.js:273:31)
laravel-echo-server_1 | at new Request (/usr/src/app/node_modules/request/request.js:127:8)
laravel-echo-server_1 | at request (/usr/src/app/node_modules/request/index.js:53:10)
laravel-echo-server_1 | at Function.post (/usr/src/app/node_modules/request/index.js:61:12)
laravel-echo-server_1 | at /usr/src/app/node_modules/laravel-echo-server/dist/channels/private-channel.js:57:27
laravel-echo-server_1 | at new Promise (<anonymous>)
laravel-echo-server_1 | at PrivateChannel.serverRequest (/usr/src/app/node_modules/laravel-echo-server/dist/channels/private-channel.js:54:16)
laravel-echo-server_1 | at PrivateChannel.authenticate (/usr/src/app/node_modules/laravel-echo-server/dist/channels/private-channel.js:21:21)
laravel-echo-server_1 | at Channel.joinPrivate (/usr/src/app/node_modules/laravel-echo-server/dist/channels/channel.js:68:22)
laravel-echo-server_1 | at Channel.join (/usr/src/app/node_modules/laravel-echo-server/dist/channels/channel.js:21:22)
laravel-echo-server_1 | Error sending authentication request.````
I have this error and I don't know what can solve it.
laravel-echo-server_1 | [12:20:31 AM] - Sending auth request to: localhost/broadcasting/auth laravel-echo-server_1 | laravel-echo-server_1 | [12:20:31 AM] - Error authenticating wcoGigP-jG_jjDARAAAL for private-athletes.1 laravel-echo-server_1 | Error: Invalid URI "localhost/broadcasting/auth" laravel-echo-server_1 | at Request.init (/usr/src/app/node_modules/request/request.js:273:31) laravel-echo-server_1 | at new Request (/usr/src/app/node_modules/request/request.js:127:8) laravel-echo-server_1 | at request (/usr/src/app/node_modules/request/index.js:53:10) laravel-echo-server_1 | at Function.post (/usr/src/app/node_modules/request/index.js:61:12) laravel-echo-server_1 | at /usr/src/app/node_modules/laravel-echo-server/dist/channels/private-channel.js:57:27 laravel-echo-server_1 | at new Promise (<anonymous>) laravel-echo-server_1 | at PrivateChannel.serverRequest (/usr/src/app/node_modules/laravel-echo-server/dist/channels/private-channel.js:54:16) laravel-echo-server_1 | at PrivateChannel.authenticate (/usr/src/app/node_modules/laravel-echo-server/dist/channels/private-channel.js:21:21) laravel-echo-server_1 | at Channel.joinPrivate (/usr/src/app/node_modules/laravel-echo-server/dist/channels/channel.js:68:22) laravel-echo-server_1 | at Channel.join (/usr/src/app/node_modules/laravel-echo-server/dist/channels/channel.js:21:22) laravel-echo-server_1 | Error sending authentication request.````
Everyone! I suggest every developer should use LARAGON and ditch xampp wampp etc.
You'll save a lot of time on setting up & resolving environment issues, like this localhost issue.
You'll get http://{project}.test urls automatically.
Sweet mother of god