Log in from multiple devices
Agora Chat supports logging in to the same account from up to 4 devices at the same time by default. You can increase the number of devices per platform up to 10 by going to Agora Console > Project management > Relevant project > Agora Chat configuration > Features > Multi Device.
In cases of multiple device login, all logged-in devices synchronize the following information and operations:
- Messages, including online messages, offline messages, push notifications (if the third-party push service is enabled, the offline device receives it), the corresponding receipts and read status, and so on;
- Friends and group-related operations;
- Message-thread-related operations;
- Conversation-related operations.
The following table summarizes the strategy of forcing other devices to log out and the automatic login security check in the single-device and multi-device login use-cases:
Single/multi-device login | Forced logout strategy | Automatic login security check |
---|---|---|
Single-device login | The newly logged-in device will force the current device to log out. The logged-out device will receive the ConnectionListener#onLogout callback. |
For devices that log in automatically, the device will automatically reconnect to the Agora server after going offline. If the reconnection is successful, the current logged-in device will be forced to log out by default (for multiple devices, the earliest logged-in device will be logged out). If you want to keep the current device logged in, contact support@agora.io. In this use-case, the device that logs in automatically won't be able to log in and will receive error 214, indicating that the number of currently logged-in devices exceeds the limit. |
Multi-device login | If the number of logged-in devices on one end reaches the limit, the device that logged in the latest will force the device that logged in the earliest to log out. The logged-out device will receive the ConnectionListener#onLogout callback. Agora Chat only supports forced logout for the devices on the same end. |
Understand the tech
During initialization, the SDK generates a login ID to identify the device when multiple devices log in and push messages, and sends this ID to the server. The server automatically sends new messages to the user's logged-in device, monitors operations on other devices, and synchronizes multiple devices. The SDK provides the following multi-device use-case functions:
-
Get the login ID list of the other logged-in devices of the current user;
-
Get the list of online logged-in devices of the specified account;
-
Force the specified account to log out from a single device;
-
Force the specified account to log out from all devices;
- Get friend or group operations on other devices.
Prerequisites
Before starting this procedure, initialize and connect the SDK to the server. See SDK quickstart for details.
Implement multi-device login
Get the login ID list of other logged-in devices of the current user
Call getSelfIdsOnOtherPlatform
to get the login ID list of other logged-in devices, and then select the target login ID as the message recipient to send a message to the specified device.
Get the list of online logged-in devices for the specified account
Call getLoggedInDevicesFromServerWithToken
to get the list of online logged-in devices for the specified account from the server by passing in the user ID and user token.
Force the specified account to log out from a single device
Call kickDeviceWithToken
and pass in the user ID and user token to force the specified account to log out from a single logged-in device. Before calling this method, obtain the device ID through the ChatClient#getLoggedInDevicesFromServerWithToken
and DeviceInfo#getResource
methods. The logged-out device will receive the ConnectionListener#onLogout
event.
Force the specified account to log out from all devices
Call kickAllDevicesWithToken
and pass in the user ID and user token to force the specified account to log out from from all logged-in devices. The logged-out device will receive the ConnectionListener#onLogout
event.
Get operations on other devices
Let's say that account A logs in on devices A and B at the same time and performs operations on device A. Device B will receive notifications corresponding to these operations.
You need to implement the MultiDeviceListener
class to listen to operations on other devices, and then call the addMultiDeviceListener
method to add multi-device listening.