Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Livewire and Presence Channel

Hello,

I finally succeeded with presence channels.

What I'm trying to do is : 1 - to refresh automatically my livewire view when a new user joins the application 2 - display the list of the connected users 3 - error with echo-presence in livewire listener

1 - To refresh automatically the view, it is necessary that pusher sends a notification to all connected computers and that my component listens to this notification ... well that's not possible. So I thought about using polling with livewire. Or perhaps with pusher webhooks or something other that I don't know ?

2 - About displaying the list of the connected user, I have declared this in my livewire component ...

protected $listeners = ['echo:my-channel,MessageSent' => 'notifyNewMessage'];

... but I don't understand how I can retrieve the list of the users like with JS.

Echo.join('my-channel')
    .here((users) => {
        console.log(users);
    });

3 - Finally I have a problem with using echo-presence like in the livewire documentation.

protected $listeners = ['echo-presence:my-channel,MessageSent' => 'notifyNewMessage'];

It generates an error : Uncaught TypeError: Echo.join(...)[event_name] is not a function, but even if I have this error, pusher receives the message.

Well channel, socket, ... are some knowledge I'm really not familiar with.

Could you help me ?

Thanks a lot.

Vincent

0 likes
1 reply
vincent15000's avatar

I have found this solution to refresh automatically the list.

<script>
    Echo.join('my-channel')
        .here((users) => {
            Livewire.emit('UsersList', users);
        })
        .joining((user) => {
            Livewire.emit('UserJoining', user);
        })
        .leaving((user) => {
            Livewire.emit('UserLeaving', user);
        })
        .error((error) => {
            console.error(error);
        });
</script>

And in my component.

protected $listeners = [
    //'echo:my-channel,here' => 'notifyMessageSent',
    'UsersList' => 'setUsersList',
    'UserJoining' => 'addUser',
    'UserLeaving' => 'removeUser',
];

But how to do (and is it only possible to do) the same with this listener in Livewire ? For me it doesn't work the event is not detected.

protected $listeners = ['echo:my-channel,MessageSent' => 'notifyNewMessage'];

Please or to participate in this conversation.