Connect Android and JVM applications with the Kotlin client.
Kotlin Client SDK
The Kotlin client connects Android and JVM applications to Edge.
Installation
The SDK supports Java 11 and Android API 21 or newer. Use the SDK version supplied with your Edge account.
implementation("app.seuraa:edge-kotlin:VERSION")Client
import app.seuraa.edge.Client
import app.seuraa.edge.ClientOptions
val edge = Client(
ClientOptions(
appKey = "app-key",
auth = "https://api.example.com/seuraa/token",
),
)The auth URL receives the app key and channel name and returns a short-lived channel token.
Use TokenProvider instead when the application needs custom authentication headers or token-fetching behavior.
Subscribe
@Serializable
data class Notification(val title: String)
val channel = edge.channel("private:user-123")
val subscription = channel.subscribe<Notification>("notification.created") { event ->
println(event.data.title)
}Closing subscription removes only that event handler. Call channel.unsubscribe() to leave the channel.
Publish
val result = channel.publish(
"typing.started",
mapOf("documentId" to "document-123"),
)Publishing is a suspending operation because the SDK may refresh the channel token.
Connection Status
lifecycleScope.launch {
edge.status.collect { state ->
println(state.status)
}
}The client reconnects automatically and restores active channel subscriptions. On plans with persisted replay, it also resumes channels using their latest event cursors.
Presence And Errors
channel.onRawEvent { event ->
when (event) {
is PresenceUpdated -> println(event.presence)
is ServerError -> println(event.code.value)
else -> Unit
}
}Call edge.close() when the client is no longer needed.