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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ kotlin {
## Usage

```kotlin
IO.socket("http://localhost:3000", IO.Options()) { socket ->
val opt = IO.Options()
// opt.trustAllCerts = true
IO.socket("http://localhost:3000", opt) { socket ->
socket.on(Socket.EVENT_CONNECT) { args ->
println("on connect ${args.joinToString()}")

Expand Down Expand Up @@ -156,6 +158,7 @@ Maven central portal credentials and signing configs are set in `~/.gradle/gradl
# on macOS: need manual release on website
./gradlew clean \
publishKotlinMultiplatformPublicationToMavenCentralRepository \
publishAndroidReleasePublicationToMavenCentralRepository \
publishJvmPublicationToMavenCentralRepository \
publishIosArm64PublicationToMavenCentralRepository \
publishIosSimulatorArm64PublicationToMavenCentralRepository \
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.4.0"
const val releaseVersion = "1.4.1"

val androidNS = "$releaseGroup.${releaseName.replace('-', '.')}"
}
1 change: 1 addition & 0 deletions example/androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<application
android:allowBackup="false"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import kotlinx.io.bytestring.unsafe.UnsafeByteStringOperations
class Greeting {
@OptIn(UnsafeByteStringApi::class)
fun greet() {
IO.socket("http://172.16.11.186:3000", IO.Options()) { socket ->
val opt = IO.Options()
//opt.trustAllCerts = true
IO.socket("http://172.16.11.186:3000", opt) { socket ->
socket.on(Socket.EVENT_CONNECT) { args ->
println("Greeting on connect ${args.joinToString()}")

Expand Down
27 changes: 27 additions & 0 deletions kmp-socketio/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,35 @@ plugins {
alias(libs.plugins.kmp)
alias(libs.plugins.vanniktech.mavenPublish)
alias(libs.plugins.kover)
alias(libs.plugins.android.library)
}

version = Consts.releaseVersion
group = Consts.releaseGroup

android {
namespace = "${Consts.androidNS}.android"
compileSdk = libs.versions.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()
}

compileOptions {
sourceCompatibility = JavaVersion.toVersion(libs.versions.jvm.get().toInt())
targetCompatibility = JavaVersion.toVersion(libs.versions.jvm.get().toInt())
}
testOptions {
unitTests.all {
it.failOnNoDiscoveredTests = false
}
}
}

kotlin {
jvm()
androidTarget {
publishLibraryVariants("release")
}

iosArm64()
iosSimulatorArm64()
Expand Down Expand Up @@ -69,6 +91,11 @@ kotlin {
api(libs.ktor.client.cio) // cio engine works fine
}
}
androidMain {
dependencies {
api(libs.ktor.client.okhttp)
}
}
jvmTest {
dependencies {
implementation(libs.kotlin.test)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.piasy.kmp.socketio.engineio.transports

import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.okhttp.OkHttp
import java.security.SecureRandom
import java.security.cert.X509Certificate
import javax.net.ssl.SSLContext
import javax.net.ssl.X509TrustManager

actual fun httpClient(
trustAllCerts: Boolean,
config: HttpClientConfig<*>.() -> Unit
): HttpClient = HttpClient(OkHttp) {
if (trustAllCerts) {
val trustManager = object : X509TrustManager {
override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?) = Unit
override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) = Unit
override fun getAcceptedIssuers(): Array<X509Certificate> = emptyArray()
}

val sslContext = SSLContext.getInstance("TLS").apply {
init(null, arrayOf(trustManager), SecureRandom())
}

engine {
config {
sslSocketFactory(sslContext.socketFactory, trustManager)
hostnameVerifier { _, _ -> true }
}
}
}

config(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ object TestUtil {

@JvmStatic
fun closeManager(manager: Manager) {
manager.close()
manager.engine?.scope?.launch {
manager.close()
}
}

@JvmStatic
Expand Down
Loading