Laravel Echo没有接受Pusher活动

时间:2016-12-26 22:57:47

标签: laravel laravel-5.3 pusher laravel-echo

我在使用Laravel Echo听Pusher频道时遇到了麻烦。我无法在浏览器中获得任何响应(没有控制台日志)。

在我的bootstrap.js中,我得到了。

import Echo from "laravel-echo"

window.Echo = new Echo({
     broadcaster: 'pusher',
     key: 'myPusherAppKey',
     cluster: 'mt1', //My app is US-EAST
     encrypted: true
});

我使用浏览器控制台并输入:

Echo.channel('my-channel')
    .listen('my-event', (e) => {
        console.log(e);
    });

我可以从Pusher Debug Console看到

  1. 连接我的应用
  2. 订阅我的频道
  3. OCCUPIED My-channel
  4. 然后我使用Pusher Debug Console发送默认事件:

    Channel: my-channel 
    Event: my-event
    Data: {
           "name": "John",
           "message": "Hello"
           }
    

    但是,我的浏览器控制台中没有任何输出

    如果我进一步输入我的浏览器控制台:

    Echo.leave('my-channel');
    

    我可以从Pusher Debug Console看到

    1. 未经授权的my-channel
    2. VACATED my-channel
    3. 如何让Laravel Echo听Pusher事件?

1 个答案:

答案 0 :(得分:7)

这是一个名称空间问题。 Laravel documentation解释了它。

  

Echo将自动假设事件位于App \ Events命名空间

因此,必须在Pusher Debug Console中更改事件名称:

Event: App\Events\my-event