SDK · Kotlin/Android

Kotlin/JVM client SDK for the imcore IM server. WebSocket + JSON over coroutines; consumable by Android apps and JVM services. Default WebSocket via OkHttp.

Add it (Gradle)

dependencies {
    implementation(project(":imcore-sdk")) // or a published coordinate
}

Runtime dependencies it brings: kotlinx-coroutines-core, kotlinx-serialization-json, okhttp.

Usage

import com.imcore.sdk.*
import kotlinx.coroutines.launch
import kotlinx.serialization.json.*

val im = ImcoreClient(
    url = "wss://your-host/acc",
    auth = AuthConfig(token = "<jwt>", login = LoginPayload(userId = "1001", userName = "alice")),
)

// Observe pushes and status with Flows (collect in your own scope):
scope.launch { im.events("chat_message").collect { msg -> println("msg $msg") } }
scope.launch { im.status.collect { s -> println("status $s") } } // Idle/Connecting/Open/Authenticated/Closed
scope.launch { im.reconnected.collect { /* re-pull conversations + cursor history */ } }

// connect() returns AFTER the server acknowledges login, and THROWS if login is
// refused (e.g. bad token) — always guard it.
try {
    im.connect()
    im.dm.send(targetUserId = "1002", text = "hi")
    val queued = im.dm.sendQueued(targetUserId = "1002", text = "works offline")
    println("${queued.status} ${queued.tempId}")

    val history = im.dm.history(targetUserId = "1002", limit = 20)
    val cached = im.cache.getMessages("dm:1001:1002")

    im.push.register(
        deviceId = "<stable-device-id>",
        platform = "android",
        pushToken = "<fcm-token>",
        vendor = "fcm",
        appId = "<application-id>",
    )

    // Escape hatch for any command not yet wrapped:
    im.request("chat_group_create", buildJsonObject { put("name", "team") })
    im.send("chat_dm_typing", buildJsonObject { put("targetUserID", "1002") })
} catch (e: RequestError) {
    println("imcore error: ${e.message}")
}

Scope (v1)

Transport core + seq-correlated request/response + login-ack-gated connect + typed DM/group/room/community send/receive/history + local message/conversation cache + tempID-backed offline send queue + push device registration wrapper. Not included: media upload helpers, E2EE, Compose wrappers.

Development

cd clients/kotlin
./gradlew build
./gradlew test       # unit tests (fake channel + coroutines-test virtual clock, no server)

# Integration test against a live server:
IMCORE_TEST_WS_URL=wss://host/acc IMCORE_TEST_WS_TOKEN=<jwt> \
IMCORE_TEST_USER_ID=1001 IMCORE_TEST_PEER_ID=1002 ./gradlew test --tests "com.imcore.sdk.IntegrationTest"