Skip to content

Repository files navigation

Not official Socket IO lib. for usage in Kotlin Multiplatform

Kotlin Maven Central

badge-android badge-ios badge-desktop badge-js badge-wasm

Supported targets

Target Implemented Tested
Android
iOS
JVM Desktop
JS
WasmJS

Implementation

In your shared module's build.gradle.kts add:

kotlin.sourceSets.commonMain.dependencies {
  implementation("tech.ryadom:kio:0.0.4")
}

Creation

val socket: Socket = kioSocket("https://yourdomain.com") {
    // Configure min. log level or set custom logger
    logging {
        level = LogLevel.INFO
    }

    // Configure socket.io options
    options {
        isSecure = true
        allowCredentials = true
    }
}

socket.open()

Listening

// For specific event
socket.on("connect") {
}

// Once for specific event
socket.once("event") {
}

// For any events
socket.onAny {
}

Sending

val args = // create your packet
socket.emit("event", args)

// WARN: Do not send json like this. It will be string like this '{}'
socket.emit("event", Json.encodeToString(args))

// Do like that:
socket.emit("event", Json.encodeToJsonEvent(args))

Support

If you find a bug or want to contribute an improvement, please create an Issue or send an email to opensource@ryadom.tech. Any support will be appreciated.

About

Socket IO library for usage in Kotlin Multiplatform

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages