Log-in

Preparing SDKAppID

The SDKAppID is a unique identifier used to distinguish customer accounts. We recommend that each independent app apply for a new SDKAppID. Messages between different SDKAppIDs are naturally isolated and cannot interconnect. You must have the correct SDKAppID to perform initialization. You can view all SDKAppIDs in the Console, click the Create Application button to create a new SDKAppID.




Feature Description

You need to call the SDK login API, authenticate account identity, and have permissions to use features. Upon successful log in to the SDK, you can enter a room and perform a series of operations.

Log In

When logging in to an account for the first time, there is no need to register the account first. You can log in directly. If the SDK detects that it is an unregistered account during log-in, it will automatically register. You can call the login (iOS & Mac / Android) API to log in.
The key parameters of the login interface are as follows:
Parameter
Meaning
Description
UserID
Unique user ID for login
It is recommended to only contain combination of uppercase and lowercase letters (a-z, A-Z), digits (0-9), underscores (_), and hyphens (-). The length should not exceed 32 bytes.
UserSig
Login ticket
Calculate by your business server to ensure security. For the calculation method, refer to User Authentication.
You need to call the login interface in following scenarios:
Use SDK features for the first time after App launch.
Kicked offline while connected: When a user is kicked offline while connected, the SDK will notify you through the onKickedOffline callback. At this point, you can prompt the user via UI and call login to log in again.
No need to call the login interface in following scenarios:
After the user's network is disconnected and reconnected, there is no need to call the login function. The SDK will automatically go online.
When a login process is in progress, there is no need for a duplicate login.
Note:
1. After a successful login by calling the SDK API, the MAU will start calculation. Call the login API reasonably based on business scenario to avoid an extremely high MAU.
2. In an App, the SDK does not support multiple accounts being online simultaneously. If you log in to multiple accounts at the same time, only the last logged-in account will be online.
Below is an example code:
iOS
Android
let sdkAppId = 1400000000 // Please set up your own application's sdkAppID
let userId = "your user id"
let userSig = "userSig from your server"

TUIRoomEngine.login(sdkAppId: sdkAppId, userId: userId, userSig: userSig) {
print("success")
} onError: { code, message in
// The following error codes indicate an expired userSig, and you need to generate a new one to log in again.
// 1. ERR_USER_SIG_EXPIRED(6206)
// 2. ERR_SVR_ACCOUNT_USERSIG_EXPIRED(70001)
// Note: For other error codes, do not call the log-in API here. Avoid the SDK log-in entering an infinite loop.
print("failure, code:\(code), message:\(message)")
}
Context context = getApplicationContext();
int sdkAppId = 1400000000; // Please set up your own application's sdkAppID
String userId = "your user id";
String userSig = "userSig from your server";

TUIRoomEngine.login(context, sdkAppId, userId, userSig,
new TUIRoomDefine().ActionCallback() {
@Override
public void onSuccess() {
Log.i("sdk", "success");
}

@Override
public void onError(TUICommonDefine.Error error, String message) {
// The following error codes indicate an expired userSig, and you need to generate a new one to log in again.
// 1. ERR_USER_SIG_EXPIRED(6206)
// 2. ERR_SVR_ACCOUNT_USERSIG_EXPIRED(70001)
// Note: For other error codes, do not call the log-in API here. Avoid the SDK log-in entering an infinite loop.
Log.i("sdk", "failure code:" + error + ",message:" + message);
}
});

Get Basic Information of the Logged-In User

Upon successful log-in, retrieve the basic information of the login user information by calling getSelfInfo( iOS & Mac / Android). If the login fails, the UserID of the retrieved login user is empty.
Below is an example code:
iOS
Android
// Get basic information of the logged-in user
let selfUserInfo = TUIRoomEngine.getSelfInfo()
TUIRoomDefine.LoginUserInfo loginUserInfo = TUIRoomEngine.getSelfInfo();

Log out

Under normal circumstances, if the lifecycle of your application matches that of the SDK, you do not need to log out before exiting the application. You can exit directly. However, in some special scenarios, for example, if you only use the SDK after entering specific interfaces and no longer use it after exiting those interfaces, you can call the logout ( iOS & Mac / Android ) API to log out of the SDK.
Below is an example code:
iOS
Android
TUIRoomEngine.logout {
print("success")
} onError: { code, message in
print("failure, code:\(code), message:\(message)")
}
TUIRoomEngine.logout(new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
Log.i("sdk","success");
}

@Override
public void onError(TUICommonDefine.Error error, String message) {
Log.i("sdk","error" + error + ",message" + message);
}
});

Account Switch

If you wish to implement the need for account switch in application, you only need to call login each time you switch accounts.
For example, if you have already logged in as alice and now want to switch to bob, you only need to directly login bob. There is no need to explicitly call logout alice before logging in bob. The SDK will automatically handle it internally.