问题描述
我无法收听私人频道中的事件一个>.但是,我可以收听公共频道.
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:
- 连接
- 已订阅
- 已占用
此外,如果我发送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.
我做什么
- 在
BroadcastServiceProvider
的boot()
方法中添加了Broadcast::routes();
-
添加了
Broadcast::channel('Foo.Bar', function ($user, $FooBarId) {return true;});
在BroadcastServiceProvider
- Added
Broadcast::routes();
in theboot()
method ofBroadcastServiceProvider
Added
Broadcast::channel('Foo.Bar', function ($user, $FooBarId) {return true;});
in theboot()
method ofBroadcastServiceProvider
具有与主管一起工作的队列.
旁注
我可以使用我的应用发送和收听 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私人频道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!