Laravel Echo cannot subscribe to Pusher private channel

霸气de小男生 提交于 2019-12-07 17:09:14

问题


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?


回答1:


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

App\Providers\BroadcastServiceProvider::class

See documentation



来源:https://stackoverflow.com/questions/41353073/laravel-echo-cannot-subscribe-to-pusher-private-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!