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:
- CONNECTION
- SUBSCRIBED
- OCCUPIED
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
- Added
Broadcast::routes();
in theboot()
method ofBroadcastServiceProvider
Added
Broadcast::channel('Foo.Bar', function ($user, $FooBarId) {return true;});
in theboot()
method ofBroadcastServiceProvider
Have a queue working with supervisor.
- Have my
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 lineSee documentation