Laravel Transmission Channels - Check Connections

I cannot find this in documents or by searching, maybe someone has some tips. I am trying to check how many connections are in the presence channel on the server.

I can normally check on the Echo interface like this:

Echo.join('chat')
    .here((users) => {
        // users.length is the proper count of connections
    })

But is there a way to get the same number of connections, but in the backend code somewhere inside Laravel?

+4
source share
3 answers

If you use Pusher, the backend can simply do the following:

$response = $pusher->get( '/channels/presence-channel-name/users' );
if( $response[ 'status'] == 200 ) {
  // convert to associative array for easier consumption
  $users = json_decode( $response[ 'body' ], true )[ 'users' ];
}

$userCount = count($users);

You can read more about this in the documentation. pusher-http-php sdk also has some documentation for this.

, , /channels/[channel_name]/users, channel_name .

.

, webhooks.

, . , , .

Pusher :

{
  "name": "member_added", // or "member_removed"
  "channel": "presence-your_channel_name",
  "user_id": "a_user_id"
}

, , redis.

+4

, . (- JS) WebSocket-Server ( NodeJS- Pusher-Servers). Laravel , .

, , (redis push). , - , .

: https://support.pusher.com/hc/en-us/articles/204113596-Showing-who-s-online-with-a-large-number-of-users https://pusher.com/docs/rest_api#method-get-channels

Redis NodeJS, laravel.

:

Echo.join('chat')
.here((users) => {
    //request to laravel api with users.length
})

, ,

+1

Or maybe this as an answer

{"user_id": "a_user_id" "name": "member_added", // or "member_removed" "channel": "presence-your_channel_name",}

0
source

Source: https://habr.com/ru/post/1677568/


All Articles