Tanmay
Tanmay

Reputation: 3189

Laravel Echo joining() and leaving() methods are not triggered

Here is my Echo config:

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;

In the mounted() hook of my vue component, I have:

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

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

And in the destroyed() hook:

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

But only the here() method is being triggered, joining() and leaving() methods aren't. What am I doing wrong?

Upvotes: 1

Views: 4907

Answers (1)

Kaiwen Luo
Kaiwen Luo

Reputation: 513

As explained in Docs:

  • The here callback will be executed immediately once the channel is joined successfully, and will receive an array containing the user information for all of the other users currently subscribed to the channel;
  • The joining method will be executed when a new user joins a channel;
  • While the leaving method will be executed when a user leaves the channel.

So, you should use another user to join this channel, then the current user will be able to receive the joining and leaving callbacks.

Upvotes: 1

Related Questions