File tree Expand file tree Collapse file tree
shared/src/commonMain/kotlin/com/piasy/kmp/socketio/example
androidMain/kotlin/com/piasy/kmp/socketio/engineio/transports
jvmTest/kotlin/com/piasy/kmp/socketio/engineio Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,7 +37,9 @@ kotlin {
3737## Usage
3838
3939``` kotlin
40- IO .socket(" http://localhost:3000" , IO .Options ()) { socket ->
40+ val opt = IO .Options ()
41+ // opt.trustAllCerts = true
42+ IO .socket(" http://localhost:3000" , opt) { socket ->
4143 socket.on(Socket .EVENT_CONNECT ) { args ->
4244 println (" on connect ${args.joinToString()} " )
4345
@@ -156,6 +158,7 @@ Maven central portal credentials and signing configs are set in `~/.gradle/gradl
156158# on macOS: need manual release on website
157159./gradlew clean \
158160 publishKotlinMultiplatformPublicationToMavenCentralRepository \
161+ publishAndroidReleasePublicationToMavenCentralRepository \
159162 publishJvmPublicationToMavenCentralRepository \
160163 publishIosArm64PublicationToMavenCentralRepository \
161164 publishIosSimulatorArm64PublicationToMavenCentralRepository \
Original file line number Diff line number Diff line change 11object Consts {
22 const val releaseGroup = " com.piasy"
33 const val releaseName = " kmp-socketio"
4- const val releaseVersion = " 1.4.0 "
4+ const val releaseVersion = " 1.4.1 "
55
66 val androidNS = " $releaseGroup .${releaseName.replace(' -' , ' .' )} "
77}
Original file line number Diff line number Diff line change 66 <application
77 android : allowBackup =" false"
88 android : supportsRtl =" true"
9+ android : usesCleartextTraffic =" true"
910 android : theme =" @style/AppTheme" >
1011 <activity
1112 android : name =" .MainActivity"
Original file line number Diff line number Diff line change @@ -10,7 +10,9 @@ import kotlinx.io.bytestring.unsafe.UnsafeByteStringOperations
1010class Greeting {
1111 @OptIn(UnsafeByteStringApi ::class )
1212 fun greet () {
13- IO .socket(" http://172.16.11.186:3000" , IO .Options ()) { socket ->
13+ val opt = IO .Options ()
14+ // opt.trustAllCerts = true
15+ IO .socket(" http://172.16.11.186:3000" , opt) { socket ->
1416 socket.on(Socket .EVENT_CONNECT ) { args ->
1517 println (" Greeting on connect ${args.joinToString()} " )
1618
Original file line number Diff line number Diff line change @@ -6,13 +6,35 @@ plugins {
66 alias(libs.plugins.kmp)
77 alias(libs.plugins.vanniktech.mavenPublish)
88 alias(libs.plugins.kover)
9+ alias(libs.plugins.android.library)
910}
1011
1112version = Consts .releaseVersion
1213group = Consts .releaseGroup
1314
15+ android {
16+ namespace = " ${Consts .androidNS} .android"
17+ compileSdk = libs.versions.compileSdk.get().toInt()
18+ defaultConfig {
19+ minSdk = libs.versions.minSdk.get().toInt()
20+ }
21+
22+ compileOptions {
23+ sourceCompatibility = JavaVersion .toVersion(libs.versions.jvm.get().toInt())
24+ targetCompatibility = JavaVersion .toVersion(libs.versions.jvm.get().toInt())
25+ }
26+ testOptions {
27+ unitTests.all {
28+ it.failOnNoDiscoveredTests = false
29+ }
30+ }
31+ }
32+
1433kotlin {
1534 jvm()
35+ androidTarget {
36+ publishLibraryVariants(" release" )
37+ }
1638
1739 iosArm64()
1840 iosSimulatorArm64()
@@ -69,6 +91,11 @@ kotlin {
6991 api(libs.ktor.client.cio) // cio engine works fine
7092 }
7193 }
94+ androidMain {
95+ dependencies {
96+ api(libs.ktor.client.okhttp)
97+ }
98+ }
7299 jvmTest {
73100 dependencies {
74101 implementation(libs.kotlin.test)
Original file line number Diff line number Diff line change 1+ package com.piasy.kmp.socketio.engineio.transports
2+
3+ import io.ktor.client.HttpClient
4+ import io.ktor.client.HttpClientConfig
5+ import io.ktor.client.engine.okhttp.OkHttp
6+ import java.security.SecureRandom
7+ import java.security.cert.X509Certificate
8+ import javax.net.ssl.SSLContext
9+ import javax.net.ssl.X509TrustManager
10+
11+ actual fun httpClient (
12+ trustAllCerts : Boolean ,
13+ config : HttpClientConfig <* >.() -> Unit
14+ ): HttpClient = HttpClient (OkHttp ) {
15+ if (trustAllCerts) {
16+ val trustManager = object : X509TrustManager {
17+ override fun checkClientTrusted (chain : Array <out X509Certificate >? , authType : String? ) = Unit
18+ override fun checkServerTrusted (chain : Array <out X509Certificate >? , authType : String? ) = Unit
19+ override fun getAcceptedIssuers (): Array <X509Certificate > = emptyArray()
20+ }
21+
22+ val sslContext = SSLContext .getInstance(" TLS" ).apply {
23+ init (null , arrayOf(trustManager), SecureRandom ())
24+ }
25+
26+ engine {
27+ config {
28+ sslSocketFactory(sslContext.socketFactory, trustManager)
29+ hostnameVerifier { _, _ -> true }
30+ }
31+ }
32+ }
33+
34+ config(this )
35+ }
Original file line number Diff line number Diff line change @@ -43,7 +43,9 @@ object TestUtil {
4343
4444 @JvmStatic
4545 fun closeManager (manager : Manager ) {
46- manager.close()
46+ manager.engine?.scope?.launch {
47+ manager.close()
48+ }
4749 }
4850
4951 @JvmStatic
You can’t perform that action at this time.
0 commit comments