I am not able to listen to an event in a private channel. However, I can listen to public channel.
The problem
This works:
Echo.channel('Foo.Bar')
.listen('MyEvent', (e) => {
console.log('It worked!');
});
I can see in Pusher Debug Console that there are three consecutive events:
Plus, if I send Channel: Foo.Bar; Event: App\Events\MyEvent
, I can see the output in my browser console.
However, this doesn't work:
Echo.private('Foo.Bar')
.listen('MyEvent', (e) => {
console.log('It privately worked!');
});
I do not see the subscription in the Pusher Debug Console. Obviously, if I send Channel: private-Foo.Bar; Event: App\Events\MyEvent
, I do not see an output in my browser console.
What I did
Broadcast::routes();
in the boot()
method of BroadcastServiceProvider
Added Broadcast::channel('Foo.Bar', function ($user, $FooBarId) {return true;});
in the boot()
method of BroadcastServiceProvider
Have a queue working with supervisor.
config\broadcasting
set up properly with app, key, secret, driver, cluster, encrypt. (I can send event from my app to Pusher)Side notes
I can send and listen to public events with my app. It is only when the channel becomes private that I am not able to listen (my app can send events on private channel to Pusher).
I suspect it is probably related to authentication because Broadcast::channel('Foo.Bar', callback)
in the BroadcastServiceProvider
is not being executed.
What am I missing here?
In config\app
, you need to uncomment the following line
App\Providers\BroadcastServiceProvider::class
See documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With