Presence
In real-time messaging solutions, it is often important to know whether a user is currently online or offline. For example, in instant messaging, chat applications, and online collaboration tools, users need to see the availability of their contacts. This information is typically displayed as a status message or icon next to a user's name. Presence features in Signaling SDK enable you to monitor join, leave, and status change notifications for users in a channel. Using Presence, you can:
- Get a list of users currently in a channel and their temporary status data.
- Get a list of channels a specified user has joined or is subscribed to.
- Read, set, or remove user status.
- Receive real-time event notifications when users join or leave specified channels.
- Receive user status change event notifications in real time.
Understand the tech
Presence provides real-time information about the availability, and the current status of users, for effective communication and collaboration. It enables you to retrieve a list of users in a channel, or to query the list of channels for a specific user. The following figure illustrates how you integrate presence features into your app.
Prerequisites
To follow this page, you must have:
- Set up the Signaling SDK reference app.
Implement presence
To implement presence,
Add the presence event listener
Enable presence notifications when you subscribe to a channel
Obtain a list of users in the channel
To get a list of users in a channel, call getOnlineUsers()
:
Set local user status
To set the local user status, call setState
.
Get the status of a remote user
To read the status of a remote user, call getState
.
Test presence
This section explains how to run the Signaling reference app and test presence features. To run the project, take the following steps:
For each user in your tests:
-
Configure the project
-
Open the file
<samples-root>/signaling-manager/src/main/res/raw/config.json
- Replace the value for
appId
with the value from Agora Console. - Generate an RTM token using your
uid
. - Replace the value for
token
with the Signaling token. - Replace the value for
uid
with the the value you used to generate the token. - Ensure that the
channelName
is filled in. The channel name can be any string.
-
-
Run the reference app
- In Android Studio, connect a physical Android device to your development machine.
- Click Run to start the app.
- A moment later you see the project installed on your device.
-
Test presence functionality:
- Run multiple instances of the SDK quickstart example.
- Log in to Signaling from each instance using a different user ID.
- Subscribe to the same channel from all instances. You see a list of all users in the channel.
- Unsubscribe a user from the channel. You see that the corresponding user ID disappears from the user list.
Reference
This section contains additional information that either supplements the content on this page or directs you to documentation that covers other aspects of this product.