connect

abstract suspend fun connect()

Attempts to connect the chat session.

This is a suspend function — call it from a coroutine context. State changes during connection are emitted to stateFlow.

Connection failures (e.g., network unreachable, TLS error, authorization failure) are reported via stateFlow and by cancelling this coroutine with kotlinx.coroutines.CancellationException; they are not reported as other exception types to callers. Severe errors (e.g., OutOfMemoryError) propagate normally. After a permanent authorization failure, the session is closed; create a new instance via ChatBuilder.build to retry.

Post-connection failures (server disconnect after a successful open) are handled internally with automatic reconnection using exponential backoff (up to 20 attempts). If all automatic attempts are exhausted, ChatStateEvent.UnexpectedDisconnect is emitted to stateFlow. The application may attempt a manual reconnection at that point, but should verify internet connectivity before doing so.