onveyor
Site menu
GitHub
Native Conveyor / Presence Native mode

Presence

Presence tracks which sockets are connected to a channel in native Conveyor mode.

Using Laravel Echo's .join()?See Presence for Laravel Echo →

Native presence

Enable presence on the server:

php
Constants::USE_PRESENCE => true

When a socket connects to or disconnects from a channel, Conveyor broadcasts a presence payload to that channel. The presence event name is channel-presence, sent in the normal native action envelope:

jsonserver → channel
{
  "action": "channel-connect",
  "data": "{\"event\":\"channel-presence\",\"channel\":\"chat.room.1\",\"fds\":[1]}",
  "fd": 1
}

Customize the payload with these filters:

FILTER_PRESENCE_MESSAGE_CONNECTConstants::FILTER_PRESENCE_MESSAGE_CONNECT
FILTER_PRESENCE_MESSAGE_DISCONNECTConstants::FILTER_PRESENCE_MESSAGE_DISCONNECT

Associate users in native mode

To link a user to the current socket fd, send assoc-user-to-fd-action with a userId:

jsonclient → server
{
  "action": "assoc-user-to-fd-action",
  "userId": 1
}

Use authentication or middleware before trusting a user-provided id.

Next steps

  • For presence channels with Laravel Echo — .join(), .here(), whispers — see Presence in the Laravel section.
  • Native presence is independent of Laravel Echo. It uses the channel-presence event plus the optional user association action.