After create an event and sending it to Redis, I try to subscribe to the event and I make a request to laravel-echo-server, via socket.io in a Vue component.
window.Echo.channel('chat')
.listen('Message', ({message}) => {
this.messages.push(message);
});
I started laravel-echo-server with command
laravel-echo-server start
{
"authHost": "http://localhost",
"authEndpoint": "/broadcasting/auth",
"clients": [],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": false,
"allowOrigin": "",
"allowMethods": "",
"allowHeaders": ""
}
}
Also, I started the queue.
php artisan queue:work
And the Laravel development server.
php artisan serve
After submitting the form, redis-monitor shows that the event is generated and gets to the Redis server, bub I get a response en Firefox browser.
http://127.0.0.1:6001/socket.io/?EIO=4&transport=polling&t=NXbeHKa
96:0{"sid":"tmJyofZrnWNMGxIqAALI","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}2:40
And the message does not come to clients who subscribed
How can I fix this?
The problem was that the latest versions of the "socket.io-client" library were installed on my system
In the "package.json" file, I changed the version of this library it was so:
and it is now:
and also still need to change the "socket.io"
Another point to keep in mind is that Laravel has created a "laravel_database_" prefix for the Redis channel. To subscribe to it, you either need to add this prefix to the channel name
or change ".env" file so that there is no prefix.
And one more thing, if you want to use the Laravel queue together with Redis, you need to write the configuration for the queue in the ".env" file: