Presence

Presence channels with Laravel Echo let you track exactly who is currently subscribed, along with rich user data you provide during authorization.


Enable presence

Conveyor must have presence support enabled for the app:

1Constants::USE_PRESENCE => true,

You set this in the server options when starting Conveyor in Pusher mode (see the examples in Laravel Echo / Reverb and Pusher Protocol).

Subscribe to a presence channel

Use the normal Laravel Echo presence API:

1window.Echo.join('room.1')
2  .here(users => console.log('here', users))
3  .joining(user => console.log('joining', user))
4  .leaving(user => console.log('leaving', user))
5  .listenForWhisper('typing', event => console.log('typing', event))
  • .here(users) is called with the full list of currently present users as soon as you successfully join.
  • .joining(user) fires when another user joins the channel.
  • .leaving(user) fires when another user leaves (or their connection drops).
  • .listenForWhisper(eventName, callback) listens for client-to-client messages ("whispers") on this presence channel.

To send a whisper from the client:

1window.Echo.join('room.1').whisper('typing', { name: 'Alex' })

Authorize presence channels

Presence channels require more than a boolean from your authorization callback. You must return an array containing identifying information about the user:

1use Illuminate\Support\Facades\Broadcast;
2
3Broadcast::channel('room.{roomId}', function ($user, int $roomId) {
4    return [
5        'id' => $user->id,
6        'name' => $user->name,
7        // any other fields you want broadcast to other members
8    ];
9});

Laravel's /broadcasting/auth endpoint (which you point Echo at) handles the authorization. Conveyor only validates the Pusher-style signature on the WebSocket subscription request using your app secret.

Client events (whispers)

To allow whispers on presence (and private) channels, enable client messages for the app:

1'apps' => [[
2    // ...
3    'enable_client_messages' => true,
4]],

Query current presence members

You can fetch the list of users currently in a presence channel using the Pusher-compatible REST API:

1GET /apps/{app_id}/channels/presence-room.1/users

Requests must be signed with your app key/secret (see HTTP Requests for the required query parameters and signature process).

See also

  • Laravel Echo / Reverb — overall setup, environment variables, and basic Echo usage.
  • Authorization — details on how Echo authorization (including presence) works with Conveyor.
  • Pusher Protocol — server-side configuration and how presence is relayed over the wire.
  • Native presence is documented separately on the Presence page (under Native Conveyor).