# Features & Events

Transport feature flags and connection lifecycle events in the SurrealDB Kotlin SDK.

The SDK exposes the capabilities of the active transport as a set of [`SurrealFeature`](#feature) values, and the lifecycle of the connection as a stream of [`SurrealConnectionEvent`](#connection-events).

**Source:** [surrealdb.kotlin](https://github.com/surrealdb/surrealdb.kotlin)

```kotlin title="Import"
import com.surrealdb.kotlin.SurrealFeature
import com.surrealdb.kotlin.engine.SurrealConnectionEvent
```

---

## `SurrealFeature` {#feature}

An enum of the features a transport may support. Inspect the active set via the [`features`](/docs/reference/kotlin/api/core/surreal-client.md#properties) property, or check a single feature with [`.supports()`](/docs/reference/kotlin/api/core/surreal-client.md#supports).

<table>
    <thead>
        <tr><th>Value</th><th>Available on</th></tr>
    </thead>
    <tbody>
        <tr><td><code>LiveQueries</code></td><td>WebSocket</td></tr>
        <tr><td><code>Transactions</code></td><td>WebSocket</td></tr>
        <tr><td><code>Sessions</code></td><td>WebSocket</td></tr>
        <tr><td><code>RefreshTokens</code></td><td>WebSocket</td></tr>
        <tr><td><code>ExportImport</code></td><td>WebSocket, HTTP</td></tr>
        <tr><td><code>SurrealML</code></td><td>WebSocket, HTTP</td></tr>
    </tbody>
</table>

```kotlin title="Example"
if (client.supports(SurrealFeature.LiveQueries)) {
    val subscription = client.live("person")
}
```

---

## `SurrealConnectionEvent` {#connection-events}

A sealed class emitted on the client's [`connectionEvents`](/docs/reference/kotlin/api/core/surreal-client.md#properties) [`SharedFlow`](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/).

<table>
    <thead>
        <tr><th>Variant</th><th>Payload</th><th>Description</th></tr>
    </thead>
    <tbody>
        <tr><td><code>Connecting</code></td><td>-</td><td>A connection attempt has started.</td></tr>
        <tr><td><code>Connected</code></td><td>-</td><td>The connection is established.</td></tr>
        <tr><td><code>Disconnected</code></td><td>-</td><td>The connection has dropped.</td></tr>
        <tr><td><code>Reconnecting</code></td><td><code>attempt: Int</code>, <code>delayMillis: Long</code></td><td>A reconnect is scheduled.</td></tr>
        <tr><td><code>Error</code></td><td><code>cause: Throwable</code></td><td>A connection error occurred.</td></tr>
    </tbody>
</table>

```kotlin title="Example"
client.connectionEvents.collect { event ->
    when (event) {
        is SurrealConnectionEvent.Connected -> println("connected")
        is SurrealConnectionEvent.Reconnecting -> println("attempt ${event.attempt}")
        is SurrealConnectionEvent.Error -> println("error: ${event.cause.message}")
        else -> {}
    }
}
```

## Learn more

- [Connecting to SurrealDB](/docs/reference/kotlin/concepts/connecting-to-surrealdb.md)
- [SurrealClient API reference](/docs/reference/kotlin/api/core/surreal-client.md)
