Laravel Echo Join()和Leaveing()方法未触发

时间:2019-04-08 09:52:31

标签: php laravel laravel-echo laravel-broadcast

这是我的Echo配置:

window.Echo = new Echo({
    authEndpoint: process.env.VUE_APP_API_ENDPOINT.replace('/v1', '/broadcasting/auth'),
    broadcaster: 'pusher',
    key: 'someKey',
    wsHost: window.location.hostname,
    wsPort: 6001,
    disableStats: true
});

window.Echo.connector.pusher.config.auth.headers['Authorization'] = 'Bearer ' + token;

在我的Vue组件的Mounted()挂钩中,我有:

window.Echo.join(`test.1`)

    .here((users) => {
        console.log(users);
    })
    .joining((user) => {
        console.log(user.name);
    })
    .leaving((user) => {
        console.log('Leaving');
    });

然后在destroy()钩子中:

window.Echo.leave('test.1')

但是仅触发here()方法,而没有触发joining()leaving()方法。我在做什么错了?

1 个答案:

答案 0 :(得分:1)

Docs中所述:

  • 一旦频道加入成功,here 回调将立即执行,并收到一个包含当前订阅该频道的所有其他用户的用户信息的数组;
  • 当新用户加入频道时将执行joining方法;
  • 虽然 leaving 方法会在用户离开频道时执行。

因此,您应该使用其他用户加入此频道,然后当前用户将能够收到加入和离开回调。

相关问题