Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Echo not receiving Pusher event

I am having trouble with Laravel Echo to listener to Pusher channels. I am not able to get any response in my browser (no console log).

In my bootstrap.js I got.

import Echo from "laravel-echo"

window.Echo = new Echo({
     broadcaster: 'pusher',
     key: 'myPusherAppKey',
     cluster: 'mt1', //My app is US-EAST
     encrypted: true
});

I use my browser console and type:

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

I can see from the Pusher Debug Console that

  1. CONNECTION My app
  2. SUBSCRIBED My-channel
  3. OCCUPIED My-channel

I then use the Pusher Debug Console to send the default event:

Channel: my-channel 
Event: my-event
Data: {
       "name": "John",
       "message": "Hello"
       }

However, I do not get any output in my browser console.

If I further type in my browser console:

Echo.leave('my-channel');

I can see from Pusher Debug Console

  1. UNSUBSCRIBED my-channel
  2. VACATED my-channel

How can I get Laravel Echo to listen to Pusher events?

like image 244
Wistar Avatar asked Dec 06 '22 16:12

Wistar


1 Answers

It was a Namespace issue. Laravel documentation explains it.

Echo will automatically assume the events are located in the App\Events namespace

Therefore, the event name must be changed in the Pusher Debug Console as such:

Event: App\Events\my-event
like image 99
Wistar Avatar answered Jan 03 '23 17:01

Wistar