0

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?

webgrig
  • 49
  • 1
  • 8

1 Answers1

1

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:

"socket.io-client": "^4.0.0"

and it is now:

"socket.io-client": "^2.4.0"

and also still need to change the "socket.io"

"socket.io": "^2.4.0"

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

window.Echo.channel('laravel_database_chat')
    .listen('Message', ({message}) => {
        this.messages.push(message);
    });

or change ".env" file so that there is no prefix.

BROADCAST_DRIVER=redis
...
...
...
REDIS_HOST=127.0.0.1
REDIS_CLIENT=predis
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_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:

QUEUE_CONNECTION=redis
webgrig
  • 49
  • 1
  • 8