1

在我的 laravel 应用程序中,我使用的是 laravel ECHO。在这我试图通过on方法来监听一个事件“pusher:subscribe” 。但我没有发生。我可以根据 laravel echo 文档订阅、add_memeber、remove_memeber。但我无法专门收听 “推送者:订阅”事件。实际上我正在尝试从这个事件中获取数据,我会进一步操作

window.Echo = new Echo({
                broadcaster: 'pusher',
                key: 'myKeyHere',
                authEndpoint: 'pusher/auth',
                auth: {
                    headers: {

                    },
                    params: {
                        username: this.username
                    }
                }
            });


 window.Echo.join('openChat').here((users) => {
                console.log(users);

            }).listen('MessagePublished', (e) => {
                console.log('Message Received');

            }).on('pusher:subscribe', (users) => {
                console.log('NOT WORKING');

            }).joining((user) => {
                console.log('User Joined');
            }).leaving((user) => {
                console.log('User gone');
            });
4

1 回答 1

4

在深入查找文档和论坛后,我了解到pusher:subscribe这是一个内部事件,因此无法通过它捕获Laravel ECHO。但我曾经pusher:subscription_succeeded捕获会员信息..

修改代码:

window.Echo = new Echo({
            broadcaster: 'pusher',
            key: 'myKeyHere',
            authEndpoint: 'pusher/auth',
            auth: {
                headers: {

                },
                params: {
                    username: this.username
                }
            }
        });


  window.Echo.join('openChat').here((users) => {
            console.log(users);

        }).listen('MessagePublished', (e) => {
            console.log('Message Received');

        }).on('pusher:subscription_succeeded', (member) => {
            console.log(member);

        }).joining((user) => {
            console.log('User Joined');
        }).leaving((user) => {
            console.log('User gone');
        });
于 2017-07-17T05:37:27.763 回答