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.
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!!! :-)