hyphenate_SDK4.0 4.8.0
hyphenate java IM SDK
Public Member Functions | List of all members
com.hyphenate.EMConnectionListener Interface Reference

Public Member Functions

void onConnected ()
 
void onDisconnected (final int errorCode)
 
default void onTokenExpired ()
 
default void onTokenWillExpire ()
 
default void onLogout (final int errorCode)
 
default void onLogout (final int errorCode, String info)
 
default void onLogout (final int errorCode, EMLoginExtensionInfo info)
 

Detailed Description

The chat connection listener.

Under unstable network conditions, the app receives the onDisconnected callback. In this case, you don't need to reconnect manually as the chat SDK will handle it automatically.

There are two callback methods for connection: onConnected, onDisconnected.

Note: We recommend you not to update the UI based on the two methods, because they are called on the worker thread. If you update the UI in the methods, other UI errors might occur. Also remember not to make the two methods do a lot of time-consuming work, which might invoke other listeners to handle this connection event.

Adds a connection listener:
```java
EMClient.getInstance().addConnectionListener(mConnectionListener);
```

Removes a connection listener:
```java
EMClient.getInstance().removeConnectionListener(mConnectionListener);
```

Member Function Documentation

◆ onConnected()

void com.hyphenate.EMConnectionListener.onConnected ( )

Occurs when the SDK connects to the chat server successfully.

◆ onDisconnected()

void com.hyphenate.EMConnectionListener.onDisconnected ( final int  errorCode)

Occurs when the SDK disconnects from the chat server.

Note that the logout may not be performed at the bottom level when the SDK is disconnected.

Common errors are as follows: EMError#USER_REMOVED,EMError#USER_LOGIN_ANOTHER_DEVICE, EMError#SERVER_SERVICE_RESTRICTED,EMError#USER_KICKED_BY_CHANGE_PASSWORD and EMError#USER_KICKED_BY_OTHER_DEVICE

◆ onLogout() [1/3]

default void com.hyphenate.EMConnectionListener.onLogout ( final int  errorCode)

◆ onLogout() [2/3]

default void com.hyphenate.EMConnectionListener.onLogout ( final int  errorCode,
EMLoginExtensionInfo  info 
)

Occurs when the UNDERLYING SDK logs out.

Common errors are as follows:

EMError#USER_LOGIN_ANOTHER_DEVICEEMError#USER_REMOVEDEMError#USER_BIND_ANOTHER_DEVICEEMError#SERVER_SERVICE_RESTRICTEDEMError#USER_LOGIN_TOO_MANY_DEVICESEMError#USER_KICKED_BY_CHANGE_PASSWORDEMError#USER_KICKED_BY_OTHER_DEVICE

Parameters
infoThe login extension information Object that contains two parameters: info.deviceExt and info.deviceInfo.

If errorCode is EMError#USER_LOGIN_ANOTHER_DEVICE:

  • info.deviceExt: The custom extension information of the device that kicks the current device offline. In other scenarios, info.deviceExt is empty.
  • info.deviceInfo: The user-defined name of the device that kicks the current device offline. If the device does not have a custom name, the device model is indicated in the callback by default. In the case of other errors, deviceInfo is empty.
Parameters
errorCodeThe error code.

◆ onLogout() [3/3]

default void com.hyphenate.EMConnectionListener.onLogout ( final int  errorCode,
String  info 
)

Occurs when the UNDERLYING SDK logs out.

Parameters
errorCodeThe error code.

Common errors are as follows:

EMError#USER_LOGIN_ANOTHER_DEVICEEMError#USER_REMOVEDEMError#USER_BIND_ANOTHER_DEVICEEMError#SERVER_SERVICE_RESTRICTEDEMError#USER_LOGIN_TOO_MANY_DEVICESEMError#USER_KICKED_BY_CHANGE_PASSWORDEMError#USER_KICKED_BY_OTHER_DEVICE

Parameters
infoThe error extension information.

If errorCode is EMError#USER_LOGIN_ANOTHER_DEVICE, info is the user-defined name of the device that kicks the current device offline. If the device does not have a custom name, the device model is indicated in the callback by default. In the case of other errors, info is empty.

◆ onTokenExpired()

default void com.hyphenate.EMConnectionListener.onTokenExpired ( )

Occurs when the token has expired.

The common error is EMError#TOKEN_EXPIRED.

◆ onTokenWillExpire()

default void com.hyphenate.EMConnectionListener.onTokenWillExpire ( )

Occurs when the token is about to expire.

The common error is EMError#TOKEN_WILL_EXPIRE.


The documentation for this interface was generated from the following file: