Laravel Echo not receiving Pusher event

7.2k views Asked by At

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?

1

There are 1 answers

0
Wistar On BEST ANSWER

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