Skip to main content

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
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)

Get current connection status

kotlin
val status = NCEngine.getConnectionStatus()

Status values

Status nameValue
NETWORK_UNAVAILABLE-1
CONNECTED0
CONNECTING1
UNCONNECTED2
KICKED_OFFLINE_BY_OTHER_CLIENT3
TOKEN_INCORRECT4
CONN_USER_BLOCKED6
SIGNED_OUT12
SUSPENDED13
TIMEOUT14
PROXY_UNAVAILABLE17
USER_ABANDON19