0

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

1 Answer 1

1

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"
    },
}
Sign up to request clarification or add additional context in comments.

5 Comments

I am getting this error now, when i start echo server: [ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND 127.0.0.1 127.0.0.1:6379 at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)
You need to put in your address and port where you have redis connection open at
It is open at this port only
when i removed that, i got this in redis server on making attempt in browser: "RPUSH" "queues:default" "{\"displayName\":\"App\\\\Events\\\\ExampleEvent\",\"job\":\"Illuminate\\\\Queue\\\\CallQueuedHandler@call\",\"maxTries\":null,\"timeout\":null,\"timeoutAt\":null,\"data\":
{\"commandName\":\"Illuminate\\\\Broadcasting\\\\BroadcastEvent\",\"command\":\"O:38:\\\"Illuminate\\\\Broadcasting\\\\BroadcastEvent\\\":7:{s:5:\\\"event\\\";O:23:\\\"App\\\\Events\\\\ExampleEvent\\\":1:{s:6:\\\"socket\\\";N;}s:10:\\\"connection\\\";N;s:5:\\\"queue\\\";N;s:15:\\\"chainConnection\\\";N;s:10:\\\"chainQueue\\\";N;s:5:\\\"delay\\\";N;s:7:\\\"chained\\\";a:0:{}}\"},\"id\":\"Bz0WsB4JiS02oqEPmDrugxFgYO4kMuCw\",\"attempts\":0}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.