Can’t receive events using laravel echo server

Published

I am tying to implement real time notifications using laravel echo server and socket.io. I see client successfully joined the channel, however client can’t get any event, which is triggered. I’ve tried all of prefixes available, builds of laravel echo server, roll back socket.io to 2.3.0 version. Nothing, just stuck here. I feel it’s something stupid I can’t see, maybe somebody could help me figure it out.

Event class to broadcast:

class TestEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return IlluminateBroadcastingChannel|array
     */
    public function broadcastOn()
    {
        return new Channel('test');
    }

    public function broadcastAs()
    {
        return 'TestEvent';
    }

    public function broadcastWith()
    {
        return [
            'message' => 'Test is successful!'
        ];
    }
}

Docker compose for containerized laravel echo server:

  laravel-echo-server:
    image: oanhnn/laravel-echo-server
    container_name: laravel-echo-server
    depends_on:
      - redis
    environment:
      LARAVEL_ECHO_SERVER_AUTH_HOST: http://localhost:8088
      LARAVEL_ECHO_SERVER_DEBUG: 'true'
      LARAVEL_ECHO_SERVER_DB: redis
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_PREFIX: laravel_database_
      REDIS_DB: 0
    ports:
      - 6001:6001
    restart: unless-stopped
    networks:
      - route-planner

Client side listener:

mounted() {
    window.io = require("socket.io-client");

    window.Echo = new Echo({
      broadcaster: "socket.io",
      host: "http://localhost:6001"
    });

    window.Echo.channel(`laravel_database_test`).listen(
      ".TestEvent",
      e => {
        console.log(e);
      }
    );
  }

Logs of laravel echo server:

[1:45:50 PM] - NbOJ_7qN-xVXCZR_AAAA joined channel: laravel_database_test

Channel: laravel_database_test

Event: TestEvent

Source: Laravel

Published
Categorised as laravel, laravel-echo, socket.io, vue.js Tagged , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq