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
- CONNECTION My app
- SUBSCRIBED My-channel
- 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
- UNSUBSCRIBED my-channel
- VACATED my-channel
How can I get Laravel Echo to listen to Pusher events?
It was a Namespace issue. Laravel documentation explains it.
Therefore, the event name must be changed in the Pusher Debug Console as such: