Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.3.1"
const val releaseVersion = "1.3.2"

val androidNS = "$releaseGroup.${releaseName.replace('-', '.')}"
}
15 changes: 7 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ compileSdk = "35"
minSdk = "21"
targetSdk = "35"
agp = "8.7.3"
kotlin = "2.1.10"
mockk = "1.13.16"
kotlin = "2.2.0"
ktor = "3.2.2"
coroutine = "1.10.1"
compose = "1.7.8"
coroutine = "1.10.2"
compose = "1.8.3"

[libraries]
junit = "junit:junit:4.13.2"
hamcrest = "org.hamcrest:hamcrest-library:3.0"
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
mockk = "io.mockk:mockk:1.14.4"
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutine" }
json = "org.json:json:20250107"
kommand = "com.kgit2:kommand:2.3.0"

socketioParser = "org.hildan.socketio:socketio-kotlin:2.0.0"
socketioParser = "org.hildan.socketio:socketio-kotlin:2.6.0"
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutine" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-websockets = { module = "io.ktor:ktor-client-websockets", version.ref = "ktor" }
Expand Down Expand Up @@ -48,7 +47,7 @@ android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kmp = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
versions = "com.github.ben-manes.versions:0.51.0"
versionUpdate = "nl.littlerobots.version-catalog-update:0.8.5"
versions = "com.github.ben-manes.versions:0.52.0"
versionUpdate = "nl.littlerobots.version-catalog-update:1.0.0"
vanniktech-mavenPublish = "com.vanniktech.maven.publish:0.30.0"
kover = "org.jetbrains.kotlinx.kover:0.9.1"
8 changes: 3 additions & 5 deletions kmp-socketio/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ version = Consts.releaseVersion
group = Consts.releaseGroup

kotlin {
jvm {
withJava()
}
jvm()

iosArm64()
iosSimulatorArm64()
Expand All @@ -26,8 +24,8 @@ kotlin {
binaries.executable()
}

mingwX64 {}
linuxX64 {}
mingwX64()
linuxX64()

applyDefaultHierarchyTemplate()
sourceSets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open class WebSocket(
private val factory: HttpClientFactory = DefaultHttpClientFactory(trustAllCerts = opt.trustAllCerts),
rawMessage: Boolean,
) : Transport(opt, scope, NAME, rawMessage) {
private var ws: DefaultClientWebSocketSession? = null
private var ws: WebSocketSession? = null

@WorkThread
override fun pause(onPause: () -> Unit) {
Expand All @@ -49,10 +49,12 @@ open class WebSocket(
}
}) {
ws = this
val respHeaders = call.response.headers.toMap()
scope.launch {
emit(EVENT_RESPONSE_HEADERS, respHeaders)
onOpen()
if (this is DefaultClientWebSocketSession) {
val respHeaders = call.response.headers.toMap()
scope.launch {
emit(EVENT_RESPONSE_HEADERS, respHeaders)
onOpen()
}
}

listen()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.piasy.kmp.socketio.engineio.transports

import com.piasy.kmp.socketio.engineio.Transport
import com.piasy.kmp.xlog.Platform
import io.ktor.client.HttpClientConfig
import io.ktor.client.HttpClient
import io.ktor.client.plugins.logging.*
import io.ktor.client.plugins.websocket.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.websocket.WebSocketSession
import kotlinx.coroutines.CoroutineScope

expect fun httpClient(trustAllCerts: Boolean = false, config: HttpClientConfig<*>.() -> Unit = {}): HttpClient
Expand Down Expand Up @@ -50,7 +50,7 @@ interface HttpClientFactory {
suspend fun createWs(
url: String,
request: HttpRequestBuilder.() -> Unit,
block: suspend DefaultClientWebSocketSession.() -> Unit,
block: suspend WebSocketSession.() -> Unit,
)

suspend fun httpRequest(
Expand Down Expand Up @@ -85,7 +85,7 @@ class DefaultHttpClientFactory(
override suspend fun createWs(
url: String,
request: HttpRequestBuilder.() -> Unit,
block: suspend DefaultClientWebSocketSession.() -> Unit,
block: suspend WebSocketSession.() -> Unit,
) = wsClient.webSocket(url, request, block)

override suspend fun httpRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ abstract class ConnectionTest {
)
val responseResult = runCatching {
trustAllCertsHttpClientFactory.httpRequest(
url = "https://expired.badssl.com/",
url = "https://localhost:8443/",
) {}
}
assertTrue(responseResult.isSuccess)
Expand All @@ -97,7 +97,7 @@ abstract class ConnectionTest {
)
val responseResult = runCatching {
trustAllCertsHttpClientFactory.httpRequest(
url = "https://expired.badssl.com/",
url = "https://localhost:8443/",
) {}
}
assertTrue(responseResult.isFailure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public void call(Object... args) {
assertThat((Integer)values.take(), is(2));
}

@Test(timeout = TIMEOUT)
@Test(timeout = TIMEOUT * 2)
public void reconnectDelayShouldIncreaseEveryTime() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<>();
IO.Options opts = createOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WebSocketTest : BaseTest() {

val factory = mockk<HttpClientFactory>()
val requestBuilder = slot<HttpRequestBuilder.() -> Unit>()
val block = slot<suspend DefaultClientWebSocketSession.() -> Unit>()
val block = slot<suspend WebSocketSession.() -> Unit>()
coEvery { factory.createWs(any(), capture(requestBuilder), capture(block)) } coAnswers {
requestBuilder.captured(HttpRequestBuilder())
block.captured(ws)
Expand Down
11 changes: 11 additions & 0 deletions kmp-socketio/src/jvmTest/resources/socket-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,14 @@ before(io.engine, 'handleUpgrade', function(req, socket, head) {
server.listen(port, function() {
console.log('Socket.IO server listening on port', port);
});

https_server = require('https').createServer({
key: fs.readFileSync(__dirname + '/key.pem'),
cert: fs.readFileSync(__dirname + '/cert.pem')
}, (req, res) => {
console.log('got https req');
res.end('self signed https server');
});
https_server.listen(8443, function() {
console.log('https server listening on port 8443');
});
5 changes: 0 additions & 5 deletions kotlin-js-store/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2488,11 +2488,6 @@ type-is@~1.6.18:
media-typer "0.3.0"
mime-types "~2.1.24"

[email protected]:
version "5.5.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba"
integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==

ua-parser-js@^0.7.30:
version "0.7.32"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.32.tgz#cd8c639cdca949e30fa68c44b7813ef13e36d211"
Expand Down
Loading