本文介绍了Laravel Echo无法订阅Pusher私人频道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法收听私人频道中的事件.但是,我可以收听公共频道.

I am not able to listen to an event in a private channel. However, I can listen to public channel.

问题

这有效:

Echo.channel('Foo.Bar')
    .listen('MyEvent', (e) => {
        console.log('It worked!');
    });

我可以在Pusher调试控制台中看到三个连续的事件:

I can see in Pusher Debug Console that there are three consecutive events:

  1. 连接
  2. 已订阅
  3. 已占用

此外,如果我发送Channel: Foo.Bar; Event: App\Events\MyEvent,则可以在浏览器控制台中看到输出.

Plus, if I send Channel: Foo.Bar; Event: App\Events\MyEvent, I can see the output in my browser console.

但是,这不起作用:

Echo.private('Foo.Bar')
    .listen('MyEvent', (e) => {
        console.log('It privately worked!');
    });

在Pusher调试控制台中看不到订阅.显然,如果发送Channel: private-Foo.Bar; Event: App\Events\MyEvent,则在浏览器控制台中看不到输出.

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.

我做什么

  1. BroadcastServiceProviderboot()方法中添加了Broadcast::routes();
  2. 添加了Broadcast::channel('Foo.Bar', function ($user, $FooBarId) {return true;});BroadcastServiceProvider

  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

具有与主管一起工作的队列.

旁注

我可以使用我的应用发送和收听 public 事件.只有当频道变为私有时,我才能收听(我的应用可以将私有频道上的事件发送给Pusher).

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).

我怀疑它可能与身份验证有关,因为未执行BroadcastServiceProvider中的Broadcast::channel('Foo.Bar', callback).

I suspect it is probably related to authentication because Broadcast::channel('Foo.Bar', callback) in the BroadcastServiceProvider is not being executed.

我在这里想念什么?

推荐答案

config\app中,您需要取消注释以下行

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

App\Providers\BroadcastServiceProvider::class

请参见文档

这篇关于Laravel Echo无法订阅Pusher私人频道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 05:14