Connection status
Use NCEngine connection status capabilities to monitor and query the current status. Do not use the underlying Rong* interfaces.
Set connection status listener
Register the listener during the application lifecycle. Remove it when no longer needed.
- Kotlin
- Java
kotlin
private const val CONNECTION_HANDLER_ID = "app_connection_status"
NCEngine.addConnectionStatusHandler(
CONNECTION_HANDLER_ID,
ConnectionStatusHandler { event ->
when (event.status) {
ConnectionStatus.CONNECTED -> {
// Connected
}
ConnectionStatus.CONNECTING -> {
// Connecting
}
ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT -> {
// Kicked offline by another client
}
ConnectionStatus.TOKEN_INCORRECT -> {
// Token invalid or expired
}
else -> {
// Other status
}
}
}
)
// When no longer needed
NCEngine.removeConnectionStatusHandler(CONNECTION_HANDLER_ID)
Java
private static final String CONNECTION_HANDLER_ID = "app_connection_status";
NCEngine.addConnectionStatusHandler(
CONNECTION_HANDLER_ID,
event -> {
switch (event.getStatus()) {
case CONNECTED:
// Connected
break;
case CONNECTING:
// Connecting
break;
case KICKED_OFFLINE_BY_OTHER_CLIENT:
// Kicked offline by another client
break;
case TOKEN_INCORRECT:
// Token invalid or expired
break;
default:
// Other status
break;
}
});
// When no longer needed
NCEngine.removeConnectionStatusHandler(CONNECTION_HANDLER_ID);
Get current connection status
- Kotlin
- Java
kotlin
val status = NCEngine.getConnectionStatus()
Java
ConnectionStatus status = NCEngine.getConnectionStatus();
Status values
| Status name | Value |
|---|---|
NETWORK_UNAVAILABLE | -1 |
CONNECTED | 0 |
CONNECTING | 1 |
UNCONNECTED | 2 |
KICKED_OFFLINE_BY_OTHER_CLIENT | 3 |
TOKEN_INCORRECT | 4 |
CONN_USER_BLOCKED | 6 |
SIGNED_OUT | 12 |
SUSPENDED | 13 |
TIMEOUT | 14 |
PROXY_UNAVAILABLE | 17 |
USER_ABANDON | 19 |