Skip to content

Commit

Permalink
release v1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Piasy committed Feb 11, 2025
1 parent 576241c commit 91a870a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 34 deletions.
26 changes: 8 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ KMP (pure Kotlin) implementation of SocketIO client.
| Platform | 🛠Builds🛠 + 🔬Tests🔬 |
| :----------------: | :------------------: |
| `JVM` 17 | 🚀 |
| `Browser` (Chrome) | 🚀 |
| `JS` (Chrome) | 🚀 |
| `WasmJS` (Chrome) | 🚀 |
| `Android` | 🚀 |
| `iOS` | 🚀 |
| `macOS` | 🚀 |
Expand Down Expand Up @@ -63,26 +64,13 @@ Most of the APIs are the same as socket.io-client-java, here are some difference
- Create socket is asynchronous, to make it's easier to guarantee thread safety.
- Binary messages can't be nested, because `emit` only accepts String/Boolean/Number/JsonElement/ByteString, other types will be converted to String using `toString()`, so there is no way to put ByteString in JsonElement.

### Set logging callback

```kotlin
Logger.setLogger(object : LoggerInterface {
override fun debug(tag: String, log: String) {
TODO("Not yet implemented")
}

override fun info(tag: String, log: String) {
TODO("Not yet implemented")
}

override fun error(tag: String, log: String) {
TODO("Not yet implemented")
}
})
```
### Logging with [kmp-xlog](https://github.com/HackWebRTC/kmp-xlog)

## Example

Before running examples, run `node kmp-socketio/src/jvmTest/resources/socket-server.js` to start the socket-io echo server,
and update the local IP address in `example/shared/src/commonMain/kotlin/com/piasy/kmp/socketio/example/Greeting.kt`.

### Android

Open the project (the repo root dir) in Android studio, and run the example.androidApp target.
Expand All @@ -105,6 +93,8 @@ Use Chrome CORS Unblock extension to workaround with CORS error.

### WASM JS

Use Chrome CORS Unblock extension to workaround with CORS error.

```bash
./gradlew :example:shared:wasmJsBrowserRun
```
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Constants.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object Consts {
const val releaseGroup = "com.piasy"
const val releaseName = "kmp-socketio"
const val releaseVersion = "1.1.1"
const val releaseVersion = "1.1.2"

val androidNS = "$releaseGroup.${releaseName.replace('-', '_')}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@ import kotlinx.io.bytestring.unsafe.UnsafeByteStringOperations
class Greeting {
@OptIn(UnsafeByteStringApi::class)
fun greet() {
IO.socket(
"https://echo.websocket.org/",
IO.Options().apply {
transports = listOf("websocket")
}
) { socket ->
IO.socket("http://172.16.11.25:3000", IO.Options()) { socket ->
socket.on(Socket.EVENT_CONNECT) { args ->
println("on connect ${args.joinToString()}")
println("Greeting on connect ${args.joinToString()}")

val bin = UnsafeByteStringOperations.wrapUnsafe(byteArrayOf(0x1, 0x3, 0x1, 0x4))
socket.emit("echo", 1, "2", bin, GMTDate())
}.on("echoBack") { args ->
println("on echoBack ${args.joinToString()}")
println("Greeting on echoBack ${args.joinToString()}")
}

socket.open()
Expand Down
10 changes: 4 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ iosDeploymentTarget = "14.0"
compileSdk = "35"
minSdk = "21"
targetSdk = "35"
agp = "8.8.0"
agp = "8.7.3"
kotlin = "2.1.0"
mockk = "1.13.16"
ktor = "3.0.3"
coroutine = "1.10.1"
compose = "1.7.6"
kotlinxBrowser = "0.3"
kmpXlog = "1.3.1"
compose = "1.7.7"

[libraries]
junit = "junit:junit:4.13.2"
Expand All @@ -22,7 +20,7 @@ kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-t
json = "org.json:json:20250107"
socketioParser = "org.hildan.socketio:socketio-kotlin:2.0.0"
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutine" }
kotlinx-browser = { module = "org.jetbrains.kotlinx:kotlinx-browser", version.ref = "kotlinxBrowser" }
kotlinx-browser = "org.jetbrains.kotlinx:kotlinx-browser:0.3"
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-websockets = { module = "io.ktor:ktor-client-websockets", version.ref = "ktor" }
ktor-client-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
Expand All @@ -34,7 +32,7 @@ ktor-client-curl = { module = "io.ktor:ktor-client-curl", version.ref = "ktor" }
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }
ktor-client-java = { module = "io.ktor:ktor-client-java", version.ref = "ktor" }
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
kmpXlog = { module = "com.piasy:kmp-xlog", version.ref = "kmpXlog" }
kmpXlog = "com.piasy:kmp-xlog:1.3.1"

androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ open class PollingXHR(
} else {
EngineIO.decodeHttpBatch(data, SocketIO::decode)
}
} catch (e: InvalidSocketIOPacketException) {
} catch (e: Exception) { // InvalidSocketIOPacketException | InvalidEngineIOPacketException
val log = "onPollComplete decode error: ${e.message}"
logE(log)
onError(log)
Expand Down
5 changes: 5 additions & 0 deletions kotlin-js-store/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@js-joda/[email protected]":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@js-joda/core/-/core-3.2.0.tgz#3e61e21b7b2b8a6be746df1335cf91d70db2a273"
integrity sha512-PMqgJ0sw5B7FKb2d5bWYIoxjri+QlW/Pys7+Rw82jSH0QN3rB05jZ/VrrsUdh1w4+i2kw9JOejXGq/KhDOX7Kg==

"@leichtgewicht/ip-codec@^2.0.1":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b"
Expand Down

0 comments on commit 91a870a

Please sign in to comment.