Listen callback is not working in Pusher API Laravel 5.4

前端 未结 3 2217
名媛妹妹
名媛妹妹 2021-02-19 11:20

Problem

I can confirm that Pusher API is receiving the message. I saw in Debug console of Pusher website. But listen callback is not working at all.

3条回答
  •  日久生厌
    2021-02-19 12:26

    I have been using Laravel 5.4 events quite efficiently since 6 months with a project. I had same trouble when I was doing initial setup. Let me guide you with whatever I have done to get it working.

    I can see you have controller to initiate an Event, SendMessageEvent to send message content to pusherjs. You need to check following stuff to get it going.

    Check 1:

    But you have not mentioned if you have an Eventhandler defined. Event handler works as a bridge between the SendMessageEvent and its actual broadcaster. So define an Eventhandler create one folders like app / Handlers / Events /. (here Handlers and Events are folders. where Events is inside Handlers)

    create one file inside this Events folder with a name e.g.

    HandleMyMessage.php And put this code in it:

    Check 2: There should be one provider at app / Providers / EventServiceProvider.php location, and put following code in EventServiceProvider.php

     [
                'App\Handlers\Events\EventServiceProvider',
            ],
        ];
    
        /**
         * Register any events for your application.
         *
         * @return void
         */
        public function boot()
        {
            parent::boot();
        }
    }
    

    Check 3: And you should change syntax of sending event message in your controller like this:

    $broadcast_data['first_name'] = 'John';
    $broadcast_data['last_name'] = 'Doe';
    $return_socket['data'] = $broadcast_data;
    
    Event::fire(new Message($return_socket));       //  Sending message to pusherjs via Laravel Event.
    

    More on this, you also need Redis installed on your system and run it.

    Hope this helps. If you need more information for any of above, just comment. I am posting a reference link for the same.

    Happy coding!!! :-)

提交回复
热议问题