Integrate Accounts
Update time: 2023/06/01 05:44:29
You must log in to NERoom before performing operations such as creating rooms, joining rooms, sending messages, and share whiteboards.
How it works
sequenceDiagram
Title: Login API Calling Sequence
autonumber
participant App Client
participant App Server
participant NERoom Kit
participant NERoom Server
App Client ->>+ App Server: Request token
App Server ->>+ NERoom Server: Get token
NERoom Server -->>+ App Server: Generate and return token
App Server -->>+ App Client: Return token
App Client ->>+ NERoom Kit: Log in with token
NERoom Kit ->>+ NERoom Server: Verify token
NERoom Server -->>+ NERoom Kit: Success
NERoom Kit -->>+ App Client: Return result
- App clients request a token from App Server.
- App Server get the token from CommsEase NERoom Server with the API of
Creating account
. - CommsEase NERoom Server returns tokens to App Server.
- App Server sends tokens to app clients. The clients manages the tokens.
- App clients request the NERoom SDK to log in to NERoom, passing userUuid and token.
- NERoom SDK requests NEoom Server to verify whether the token is valid.
- NERoom Server verifies the token and returns a success to NERoom SDK.
- NERoom SDK returns a success to the App.
Log in to the system
Configure the settings for anonymous login.
- Initialize the NERoom SDK. For information about how to initialize the SDK, see Initialize SDK.
- Log in by calling the
login
interface in theNEAuthService
instance.
Sample code
Sample code for login
NEAuthService authService = NERoomKit.getInstance().getService(NEAuthService.class);
String account="your account";
String token="your token";
authService.login(account,token, new NECallback2<Unit>() {
@Override
public void onSuccess(@Nullable Unit unit) {
super.onSuccess(unit);
}
@Override
public void onError(int code, @Nullable String message) {
super.onError(code, message);
}
});
Listen to the login status
Configure the settings for anonymous login.
- Initialize NERoom Kit.
- Listen to the login state by calling the
addAuthListener
interface.
Sample code
Implement listening to the login state
NEAuthService authService = NERoomKit.getInstance().getService(NEAuthService.class);
authService.addAuthListener(new NEAuthListener() {
@Override
public void onAuthEvent(@NonNull NEAuthEvent evt) {
if (evt==NEAuthEvent.LOGGED_IN){
Log.d(TAG,"login success");
}
}
});
Check the login state
Configure the settings for anonymous login.
You can check the login state of an account by calling isLoggedIn
.
- ture: logged in
- false: not logged in.
Sample code
Implement checking the login state
NEAuthService authService = NERoomKit.getInstance().getService(NEAuthService.class);
boolean isLoggedIn = authService.isLoggedIn();
Log.d(TAG,"login state:"+isLoggedIn);
Log out
Configure the settings for anonymous login.
To leave a room, call the logout
interface.
After leaving the room, you no longer receive any messages from the room. If you leave the room without calling the logout
interface, you still receive messages from the room.
Sample code
Implement logout
NEAuthService authService = NERoomKit.getInstance().getService(NEAuthService.class);
authService.logout(new NECallback2<Unit>() {
@Override
public void onSuccess(@Nullable Unit unit) {
super.onSuccess(unit);
Log.d(TAG,"success");
}
@Override
public void onError(int code, @Nullable String message) {
super.onError(code, message);
Log.d(TAG,"error");
}
});
API reference
Method | Description |
---|---|
login | Log in |
logout | Log out |
addAuthListener | Add the listener for the login status. |
removeAuthListener | Remove the listener for the login status |
isLoggedIn | Check if the account is logged in. |
Was this page helpful?