This client provides access to Centrifugo's presence functionality, allowing you to see who is currently subscribed to channels. Presence must be enabled in channel configuration for these operations to work.
Key features:
- Get detailed presence information (all connected clients)
- Get presence statistics (client and user counts only)
- Client and connection metadata
- User identification and custom info
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionpresence(PresenceRequest request) Get channel presence information.default PresenceResponseGet channel presence information.presenceStats(PresenceStatsRequest request) Get channel presence stats.default PresenceStatsResponsepresenceStats(String channel) Get channel presence stats.
-
Method Details
-
presence
Get channel presence information.Returns detailed information about all clients currently subscribed to the specified channel, including client IDs, user IDs, connection info, and channel-specific metadata.
Returned information includes:
- Client ID for each connected client
- User ID (if authenticated)
- Connection info (optional custom data)
- Channel info (subscription-specific data)
Use cases:
- Showing "who's online" in chat rooms
- Displaying active participants in collaborative apps
- Implementing user lists and activity indicators
- Building presence-aware features
Example:
PresenceRequest request = PresenceRequest.builder().channel("chat:room1").build(); PresenceResponse response = client.presence(request); Map<String, ClientInfo> presence = response.getResult().getPresence(); for (ClientInfo clientInfo : presence.values()) { System.out.println("User: " + clientInfo.getUser() + ", Client: " + clientInfo.getClient()); }- Parameters:
request- the presence request containing the channel name- Returns:
- the presence response containing detailed client information
- See Also:
-
presence
Get channel presence information.Returns detailed information about all clients currently subscribed to the specified channel, including client IDs, user IDs, connection info, and channel-specific metadata.
Returned information includes:
- Client ID for each connected client
- User ID (if authenticated)
- Connection info (optional custom data)
- Channel info (subscription-specific data)
Use cases:
- Showing "who's online" in chat rooms
- Displaying active participants in collaborative apps
- Implementing user lists and activity indicators
- Building presence-aware features
Example:
PresenceRequest request = PresenceRequest.builder().channel("chat:room1").build(); PresenceResponse response = client.presence(request); Map<String, ClientInfo> presence = response.getResult().getPresence(); for (ClientInfo clientInfo : presence.values()) { System.out.println("User: " + clientInfo.getUser() + ", Client: " + clientInfo.getClient()); }- Parameters:
channel- the channel to get presence information for- Returns:
- the presence response containing detailed client information
- See Also:
-
presenceStats
Get channel presence stats.Returns lightweight presence statistics for a channel without detailed client information. This is more efficient than full presence when you only need counts.
Statistics include:
- Number of connected clients
- Number of unique users (based on user ID)
Use cases:
- Displaying channel activity counters
- Monitoring channel usage
- Building channel browser interfaces
- Analytics and reporting
Example:
PresenceStatsRequest request = PresenceStatsRequest.builder().channel("chat:room1") .build(); PresenceStatsResponse response = client.presenceStats(request); int numClients = response.getResult().getNumClients(); int numUsers = response.getResult().getNumUsers(); System.out.println("Channel has " + numClients + " connections from " + numUsers + " unique users");- Parameters:
request- the presence stats request containing the channel name- Returns:
- the presence stats response containing client and user counts
- See Also:
-
presenceStats
Get channel presence stats.Returns lightweight presence statistics for a channel without detailed client information. This is more efficient than full presence when you only need counts.
Statistics include:
- Number of connected clients
- Number of unique users (based on user ID)
Use cases:
- Displaying channel activity counters
- Monitoring channel usage
- Building channel browser interfaces
- Analytics and reporting
Example:
PresenceStatsRequest request = PresenceStatsRequest.builder().channel("chat:room1") .build(); PresenceStatsResponse response = client.presenceStats(request); int numClients = response.getResult().getNumClients(); int numUsers = response.getResult().getNumUsers(); System.out.println("Channel has " + numClients + " connections from " + numUsers + " unique users");- Parameters:
channel- the channel to get presence stats for- Returns:
- the presence stats response containing client and user counts
- See Also:
-