Skip to content

Commit

Permalink
Updated samples to use 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr3zee committed Sep 26, 2024
1 parent c4d1a00 commit b4a1dd1
Show file tree
Hide file tree
Showing 29 changed files with 158 additions and 77 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ build
!.idea/detekt.xml
!.idea/kotlinTestDataPluginTestDataPaths.xml

samples/**/.idea/*

.DS_Store

# Ignore generated Detekt reports
Expand Down
11 changes: 11 additions & 0 deletions samples/ktor-all-platforms-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ plugins {
alias(libs.plugins.kotlinx.rpc.platform) apply false
alias(libs.plugins.compose.compiler) apply false
}

allprojects {
configurations.all {
resolutionStrategy {
// Workaround for https://youtrack.jetbrains.com/issue/CMP-6658
force(libs.kotlinx.serialization.core)
force(libs.kotlinx.serialization.json)
force(libs.kotlin.stdlib)
}
}
}
31 changes: 30 additions & 1 deletion samples/ktor-all-platforms-app/composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

plugins {
alias(libs.plugins.kotlinMultiplatform)
Expand All @@ -15,6 +17,24 @@ plugins {
}

kotlin {
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
moduleName = "composeApp"
browser {
val projectDirPath = project.projectDir.path
commonWebpackConfig {
outputFileName = "composeApp.js"
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
static = (static ?: mutableListOf()).apply {
// Serve sources to debug inside browser
add(projectDirPath)
}
}
}
}
binaries.executable()
}

androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
Expand Down Expand Up @@ -53,12 +73,21 @@ kotlin {
implementation(libs.kotlinx.rpc.krpc.client)
implementation(libs.kotlinx.rpc.krpc.serialization.json)
implementation(libs.kotlinx.rpc.krpc.ktor.client)
implementation(libs.ktor.client.cio)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.websockets)
}
desktopMain.dependencies {
implementation(compose.desktop.currentOs)
implementation(libs.ktor.client.cio)
}
iosMain.dependencies {
implementation(libs.ktor.client.cio)
}
wasmJsMain.dependencies {
implementation(libs.ktor.client.js)
}
androidMain.dependencies {
implementation(libs.ktor.client.cio)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import io.ktor.client.*
import io.ktor.http.*
import kotlinx.rpc.krpc.ktor.client.installRPC
import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json
import kotlinx.rpc.krpc.streamScoped
import kotlinx.rpc.withService
import kotlinx.rpc.serialization.json
import kotlinx.rpc.streamScoped
import kotlinx.rpc.transport.ktor.client.installRPC
import kotlinx.rpc.transport.ktor.client.rpc
import kotlinx.rpc.transport.ktor.client.rpcConfig
import ktor_all_platforms_app.composeapp.generated.resources.Res
import ktor_all_platforms_app.composeapp.generated.resources.compose_multiplatform
import org.jetbrains.compose.resources.painterResource
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
actual val DEV_SERVER_HOST: String = "127.0.0.1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import App
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.ComposeViewport
import kotlinx.browser.document

@OptIn(ExperimentalComposeUiApi::class)
fun main() {
ComposeViewport(document.body!!) {
App()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ktor-all-platforms-app</title>
<link type="text/css" rel="stylesheet" href="styles.css">
<script type="application/javascript" src="composeApp.js"></script>
</head>
<body>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
17 changes: 9 additions & 8 deletions samples/ktor-all-platforms-app/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ androidx-test-junit = "1.2.1"
compose = "1.7.2"
compose-plugin = "1.6.11"
junit = "4.13.2"
ktor = "2.3.12"
ktor = "3.0.0-rc-1"
logback = "1.5.8"
kotlinx-serialization-json = "1.7.1"
kotlinx-coroutines-core = "1.9.0"
kotlinx-rpc = "0.2.4"
serialization = "1.7.1"
coroutines = "1.9.0"
kotlinx-rpc = "0.3.0"

[libraries]
# kotlin
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }

Expand All @@ -40,21 +41,21 @@ compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref =
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }

# kotlinx
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization-json" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines-core" }
kotlinx-coroutines-core-jvm = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm", version.ref = "kotlinx-coroutines-core" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" }
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "serialization" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }

# ktor
ktor-server-core = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor" }
ktor-server-netty = { module = "io.ktor:ktor-server-netty-jvm", version.ref = "ktor" }
ktor-server-tests = { module = "io.ktor:ktor-server-tests-jvm", version.ref = "ktor" }
ktor-server-cors-jvm = { module = "io.ktor:ktor-server-cors-jvm", version.ref = "ktor" }
ktor-server-websockets-jvm = { module = "io.ktor:ktor-server-websockets-jvm", version.ref = "ktor" }
ktor-server-host-common-jvm = { module = "io.ktor:ktor-server-host-common-jvm", version.ref = "ktor" }
ktor-server-test-host = { module = "io.ktor:ktor-server-test-host", version.ref = "ktor" }
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-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }

# kotlinx-rpc
kotlinx-rpc-core = { module = "org.jetbrains.kotlinx:kotlinx-rpc-core" }
Expand Down
4 changes: 2 additions & 2 deletions samples/ktor-all-platforms-app/server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ application {

dependencies {
implementation(projects.shared)
implementation(libs.kotlinx.coroutines.core.jvm)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.logback)
implementation(libs.ktor.server.core)
implementation(libs.ktor.server.netty)
Expand All @@ -28,7 +28,7 @@ dependencies {
implementation(libs.kotlinx.rpc.krpc.server)
implementation(libs.kotlinx.rpc.krpc.serialization.json)
implementation(libs.kotlinx.rpc.krpc.ktor.server)
testImplementation(libs.ktor.server.tests)
testImplementation(libs.ktor.server.test.host)
testImplementation(libs.kotlinx.rpc.krpc.client)
testImplementation(libs.kotlinx.rpc.krpc.ktor.client)
testImplementation(libs.kotlin.test.junit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import io.ktor.server.application.*
import io.ktor.server.netty.*
import io.ktor.server.plugins.cors.routing.*
import io.ktor.server.routing.*
import kotlinx.rpc.serialization.json
import kotlinx.rpc.transport.ktor.server.RPC
import kotlinx.rpc.transport.ktor.server.rpc
import kotlinx.rpc.krpc.ktor.server.RPC
import kotlinx.rpc.krpc.ktor.server.rpc
import kotlinx.rpc.krpc.serialization.json.json

fun main(args: Array<String>): Unit = EngineMain.main(args)

Expand Down Expand Up @@ -49,7 +49,7 @@ fun Application.installCORS() {
allowSameOrigin = true

// webpack-dev-server and local development
val allowedHosts = listOf("localhost:3000", "localhost:8080", "127.0.0.1:8080")
val allowedHosts = listOf("localhost:3000", "localhost:8080", "localhost:8081", "127.0.0.1:8080")
allowedHosts.forEach { host ->
allowHost(host, listOf("http", "https", "ws", "wss"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import UserData
import UserService
import io.ktor.server.testing.*
import kotlinx.coroutines.flow.toList
import kotlinx.rpc.krpc.ktor.client.installRPC
import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json
import kotlinx.rpc.krpc.streamScoped
import kotlinx.rpc.withService
import kotlinx.rpc.serialization.json
import kotlinx.rpc.streamScoped
import kotlinx.rpc.transport.ktor.client.installRPC
import kotlinx.rpc.transport.ktor.client.rpc
import kotlinx.rpc.transport.ktor.client.rpcConfig
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down
18 changes: 18 additions & 0 deletions samples/ktor-all-platforms-app/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

plugins {
alias(libs.plugins.kotlinMultiplatform)
Expand All @@ -13,6 +15,21 @@ plugins {
}

kotlin {
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser {
val projectDirPath = project.projectDir.path
commonWebpackConfig {
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
static = (static ?: mutableListOf()).apply {
// Serve sources to debug inside browser
add(projectDirPath)
}
}
}
}
}

androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
Expand All @@ -31,6 +48,7 @@ kotlin {
api(libs.kotlinx.coroutines.core)

implementation(libs.kotlinx.rpc.core)
implementation(libs.kotlinx.serialization.core)
implementation(libs.kotlinx.serialization.json)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ class WasmPlatform: Platform {
override val name: String = "Web with Kotlin/Wasm"
}

actual fun getPlatform(): Platform = WasmPlatform()
actual fun getPlatform(): Platform = WasmPlatform()
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ package kotlinx.rpc.sample.data

import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.plugins.websocket.WebSockets
import io.ktor.client.request.url
import kotlinx.rpc.RPCClient
import kotlinx.rpc.serialization.json
import kotlinx.rpc.transport.ktor.client.rpc
import kotlinx.rpc.transport.ktor.client.rpcConfig
import kotlinx.rpc.transport.ktor.client.installRPC
import kotlinx.rpc.krpc.ktor.client.installRPC
import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json

suspend fun createRpcClient(): RPCClient {
return HttpClient(OkHttp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import kotlinx.rpc.RPCClient
import kotlinx.rpc.streamScoped
import kotlinx.rpc.krpc.streamScoped
import kotlinx.rpc.withService
import kotlinx.rpc.sample.MyService
import kotlinx.rpc.sample.UserData
Expand Down
2 changes: 1 addition & 1 deletion samples/ktor-android-app/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ktor = "2.3.12"
kotlinx-serialization-json = "1.7.3"
kotlinx-coroutines-core = "1.9.0"
logback = "1.5.8"
kotlinx-rpc = "0.2.4"
kotlinx-rpc = "0.3.0"

[libraries]
# kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import io.ktor.server.application.*
import io.ktor.server.cio.*
import io.ktor.server.routing.*
import io.ktor.server.websocket.*
import kotlinx.rpc.serialization.json
import kotlinx.rpc.transport.ktor.server.rpc
import kotlinx.rpc.krpc.ktor.server.rpc
import kotlinx.rpc.krpc.serialization.json.json

fun main(args: Array<String>): Unit = EngineMain.main(args)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.testing.*
import kotlinx.coroutines.flow.toList
import kotlinx.rpc.krpc.ktor.client.installRPC
import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json
import kotlinx.rpc.krpc.streamScoped
import kotlinx.rpc.withService
import kotlinx.rpc.sample.MyService
import kotlinx.rpc.sample.UserData
import kotlinx.rpc.serialization.json
import kotlinx.rpc.streamScoped
import kotlinx.rpc.transport.ktor.client.installRPC
import kotlinx.rpc.transport.ktor.client.rpc
import kotlinx.rpc.transport.ktor.client.rpcConfig
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down
8 changes: 0 additions & 8 deletions samples/ktor-web-app/frontend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ kotlin {
cssSupport {
enabled.set(true)
}

val proxies = devServer?.proxy ?: mutableMapOf()
proxies["/api"] = "http://localhost:8080"

devServer = devServer?.copy(
port = 3000,
proxy = proxies
)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions samples/ktor-web-app/frontend/src/jsMain/kotlin/RPC.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import io.ktor.client.*
import io.ktor.client.engine.js.*
import io.ktor.client.request.*
import kotlinx.rpc.RPCClient
import kotlinx.rpc.serialization.json
import kotlinx.rpc.transport.ktor.client.installRPC
import kotlinx.rpc.transport.ktor.client.rpc
import kotlinx.rpc.transport.ktor.client.rpcConfig
import kotlinx.rpc.krpc.ktor.client.installRPC
import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json

suspend fun initRpcClient(): RPCClient {
return HttpClient(Js) {
Expand Down
3 changes: 1 addition & 2 deletions samples/ktor-web-app/frontend/src/jsMain/kotlin/Welcome.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/

import emotion.react.css
import kotlinx.coroutines.flow.Flow
import kotlinx.rpc.streamScoped
import kotlinx.rpc.krpc.streamScoped
import react.FC
import react.Props
import react.dom.html.ReactHTML.div
Expand Down
Loading

0 comments on commit b4a1dd1

Please sign in to comment.