user10668250
user10668250

Reputation:

Broadcasting with Laravel Echo, laravel-echo-server and socket.io is not working

I've setup websockets with Laravel sucessfully with an own implementation.But, after many hours of trying and reading every piece of documentation I could find, I do need further help.

"laravel-echo": "^1.5.2",
"socket.io-client": "^2.2.0",

This is my .env file details

BROADCAST_DRIVER=redis
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120

laravel-echo-server.json

 "database": "redis",
    "databaseConfig": {
        "redis": {},
        "sqlite": {
            "databasePath": "/database/laravel-echo-server.sqlite"
        }
    },
    "devMode": true,

ExampleEvent file

public function broadcastOn()
    {
        return new Channel('test-event');
    }

    public function broadcastWith(){
        return [
            'data' => 'key'
        ];
    }

My Bootstrap.js

window.Echo.channel('test-event')
    .listen('ExampleEvent', (e) => {
        console.log(e);
    });

When Implementhing

Laravel-echo-server:

[10:03:50 PM] - F07Nv9alc-Bsh3LEAAAB joined channel: test-event [10:04:16 PM] - F07Nv9alc-Bsh3LEAAAB left channel: test-event (transport close) Channel: test-event Event: App\Events\ExampleEvent

Redis:

1548349380.228566 [0 127.0.0.1:53929] "EVAL" "-- Pop the first job off of the queue...\nlocal job = redis.call('lpop', KEYS[1])\nlocal reserved = false\n\nif(job ~= false) then\n -- Increment the attempt count and place job on the reserved queue...\n reserved = cjson.decode(job)\n reserved['attempts'] = reserved['attempts'] + 1\n reserved = cjson.encode(reserved)\n redis.call('zadd', KEYS[2], ARGV[1], reserved)\nend\n\nreturn {job, reserved}" "2" "queues:default" "queues:default:reserved" "1548349470" 1548349380.228773 [0 lua] "lpop" "queues:default"

This statement is being repeated continuously..

Moreover there is no output in browser

Upvotes: 0

Views: 2180

Answers (1)

Nikola Gavric
Nikola Gavric

Reputation: 3543

You need to set the redis configuration inside laravel-echo-config.json file so it knows from where to "ask for messages", an example:

"databaseConfig": {
    "redis": {
        "host": "http://127.0.0.1"
        "port": "6379"
    },
}

Upvotes: 1

Related Questions