SeuraaEdge
v1
Docs/SDKs
SDKs

Integrate Kotlin and JVM backends with Edge.

Kotlin Server SDK

Use the Kotlin server SDK to issue channel tokens, publish events, query presence, and revoke tokens from Kotlin and JVM backends.

Installation

The SDK targets Java 11.

kotlin
implementation("app.seuraa:edge-kotlin-server:VERSION")

Create A Client

kotlin
import app.seuraa.edge.server.Client
import app.seuraa.edge.server.ClientOptions

val edge = Client(
    ClientOptions(
        appKey = System.getenv("SEURAA_APP_KEY"),
        appSecret = System.getenv("SEURAA_APP_SECRET"),
    ),
)

Issue A Channel Token

kotlin
import app.seuraa.edge.server.SignInRequest

val session = edge.auth.signIn(
    SignInRequest(
        channel = "private:user-123",
        expiresInSeconds = 60,
        permissions = listOf("subscribe"),
        userId = "user-123",
    ),
)

The result contains the signed token, its tokenId, the channel, and its expiresAt timestamp.

Publish An Event

kotlin
import kotlinx.serialization.Serializable

@Serializable
data class Notification(val title: String)

edge.channels.publish(
    channel = "private:user-123",
    eventName = "notification.created",
    data = Notification("Your report is ready"),
)

Provide a stable client event ID when retrying the same application operation:

kotlin
import app.seuraa.edge.server.PublishOptions

edge.channels.publish(
    channel = "private:user-123",
    eventName = "notification.created",
    data = Notification("Your report is ready"),
    options = PublishOptions(clientEventId = "notification-456"),
)

Query Presence

kotlin
val presence = edge.channels.presence("presence:document-123")

println(presence.count)
println(presence.members)

Revoke A Token

kotlin
import app.seuraa.edge.server.RevokeTokenOptions

edge.auth.revoke(
    session.tokenId,
    RevokeTokenOptions(ttlSeconds = 3600),
)

Set the revocation TTL to cover the token's remaining lifetime.

Errors

Failed Edge requests throw ServerException. It contains the HTTP statusCode and responseBody.