Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Echo cannot subscribe to Pusher private channel

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:

  1. CONNECTION
  2. SUBSCRIBED
  3. 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

  1. Added Broadcast::routes(); in the boot() method of BroadcastServiceProvider
  2. Added Broadcast::channel('Foo.Bar', function ($user, $FooBarId) {return true;}); in the boot() method of BroadcastServiceProvider

  3. Have a queue working with supervisor.

  4. 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?

like image 834
Wistar Avatar asked Dec 27 '16 22:12

Wistar


1 Answers

In config\app, you need to uncomment the following line

App\Providers\BroadcastServiceProvider::class

See documentation

like image 196
Wistar Avatar answered Nov 19 '22 12:11

Wistar