P
P
palansky2019-08-12 10:30:58
Broadcast
palansky, 2019-08-12 10:30:58

How to implement user status output with Laravel echo and Pusher?

Hello, how to implement user status tracking in a real-time application?
For example, if the user is online and subscribed to the channel, then the status is 'online', for example, otherwise 'offline', 'busy', etc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Razgelday, 2019-08-20
@palansky

To do this, you need to use Presence channels (see https://laravel.com/docs/master/broadcasting#prese... ).
Presence channels are the same private channels, but you can additionally get information about connected users in them, as well as track the events of "joining" and "disconnecting" users from the channel.
Example:

Echo.join(`chat.${roomId}`)
    .here((users) => {
        console.log(users); // Получаем список всех юзеров
    })
    .joining((user) => {
        console.log(user.name); //  Кто-то подключился к каналу, можно сделать его 'online'
    })
    .leaving((user) => {
        console.log(user.name); // Кто-то вышел из канала, можно сделать его 'offline'
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question