如何绑定 "pusher:subscribe" 事件,使用 Laravel 的 Echo

How to bind "pusher:subscribe" event , using Laravel's Echo

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

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');
            });

在文档和论坛中深入查找后,我了解到 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');
        });