Skip to content

Commit f5f5080

Browse files
authored
Updated samples to match current API state (#58)
1 parent 221798a commit f5f5080

File tree

52 files changed

+343
-325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+343
-325
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Contributions are made using Github [pull requests](https://help.github.com/en/a
7575

7676
[//]: # (TODO change repo link to the repo)
7777
1. Fork the `kotlinx.rpc` repository and work on your fork.
78-
2. [Create](https://github.com/kotlin/kotlinx.rpc/compare) a new PR with a request to merge to the **main** branch.
78+
2. [Create](https://github.com/kotlin/kotlinx-rpc/compare) a new PR with a request to merge to the **main** branch.
7979
3. Ensure that the description is clear and refers to an existing ticket/bug if applicable.
8080
4. Make sure any code contributed is covered by tests and no existing tests are broken.
8181

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div align="center">
22
<picture>
3-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/kotlin/kotlinx.rpc/main/.github/images/logo.svg">
4-
<img alt="kotlinx.rpc logo" src="https://raw.githubusercontent.com/kotlin/kotlinx.rpc/main/.github/images/logo.svg">
3+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/kotlin/kotlinx-rpc/main/.github/images/logo.svg">
4+
<img alt="kotlinx.rpc logo" src="https://raw.githubusercontent.com/kotlin/kotlinx-rpc/main/.github/images/logo.svg">
55
</picture>
66
</div>
77

samples/ktor-all-platforms-app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
alias(libs.plugins.kotlinJvm) apply false
1212
alias(libs.plugins.kotlinMultiplatform) apply false
1313
alias(libs.plugins.kotlinPluginSerialization) apply false
14-
alias(libs.plugins.krpc) apply false
15-
alias(libs.plugins.krpc.platform) apply false
14+
alias(libs.plugins.kotlinx.rpc) apply false
15+
alias(libs.plugins.kotlinx.rpc.platform) apply false
1616
alias(libs.plugins.ksp) apply false
1717
}

samples/ktor-all-platforms-app/composeApp/build.gradle.kts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
alias(libs.plugins.kotlinMultiplatform)
99
alias(libs.plugins.androidApplication)
1010
alias(libs.plugins.jetbrainsCompose)
11-
alias(libs.plugins.krpc.platform)
11+
alias(libs.plugins.kotlinx.rpc.platform)
1212
}
1313

1414
kotlin {
@@ -48,9 +48,9 @@ kotlin {
4848
implementation(compose.components.resources)
4949
implementation(projects.shared)
5050

51-
implementation(libs.krpc.runtime.client)
52-
implementation(libs.krpc.runtime.serialization.json)
53-
implementation(libs.krpc.transport.ktor.client)
51+
implementation(libs.kotlinx.rpc.runtime.client)
52+
implementation(libs.kotlinx.rpc.runtime.serialization.json)
53+
implementation(libs.kotlinx.rpc.transport.ktor.client)
5454
implementation(libs.ktor.client.cio)
5555
implementation(libs.ktor.client.core)
5656
implementation(libs.ktor.client.websockets)
@@ -62,15 +62,15 @@ kotlin {
6262
}
6363

6464
android {
65-
namespace = "org.jetbrains.krpc.sample"
65+
namespace = "kotlinx.rpc.sample"
6666
compileSdk = libs.versions.android.compileSdk.get().toInt()
6767

6868
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
6969
sourceSets["main"].res.srcDirs("src/androidMain/res")
7070
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
7171

7272
defaultConfig {
73-
applicationId = "org.jetbrains.krpc.sample"
73+
applicationId = "kotlinx.rpc.sample"
7474
minSdk = libs.versions.android.minSdk.get().toInt()
7575
targetSdk = libs.versions.android.targetSdk.get().toInt()
7676
versionCode = 1
@@ -101,7 +101,7 @@ compose.desktop {
101101

102102
nativeDistributions {
103103
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
104-
packageName = "org.jetbrains.krpc.sample"
104+
packageName = "kotlinx.rpc.sample"
105105
packageVersion = "1.0.0"
106106
}
107107
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
package org.jetbrains.krpc.sample
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.rpc.sample
26

37
import App
48
import android.os.Bundle
@@ -21,4 +25,4 @@ class MainActivity : ComponentActivity() {
2125
@Composable
2226
fun AppAndroidPreview() {
2327
App()
24-
}
28+
}

samples/ktor-all-platforms-app/composeApp/src/commonMain/kotlin/App.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@ import androidx.compose.runtime.*
1313
import androidx.compose.ui.Alignment
1414
import androidx.compose.ui.Modifier
1515
import io.ktor.client.*
16-
import io.ktor.client.plugins.websocket.*
1716
import io.ktor.http.*
17+
import kotlinx.rpc.client.withService
18+
import kotlinx.rpc.internal.streamScoped
19+
import kotlinx.rpc.serialization.json
20+
import kotlinx.rpc.transport.ktor.client.installRPC
21+
import kotlinx.rpc.transport.ktor.client.rpc
22+
import kotlinx.rpc.transport.ktor.client.rpcConfig
1823
import ktor_all_platforms_app.composeapp.generated.resources.Res
1924
import ktor_all_platforms_app.composeapp.generated.resources.compose_multiplatform
2025
import org.jetbrains.compose.resources.ExperimentalResourceApi
2126
import org.jetbrains.compose.resources.painterResource
22-
import org.jetbrains.krpc.client.withService
23-
import org.jetbrains.krpc.serialization.json
24-
import org.jetbrains.krpc.transport.ktor.client.rpc
25-
import org.jetbrains.krpc.transport.ktor.client.rpcConfig
2627

2728
expect val DEV_SERVER_HOST: String
2829

2930
val client by lazy {
3031
HttpClient {
31-
install(WebSockets)
32+
installRPC()
3233
}
3334
}
3435

@@ -64,8 +65,10 @@ fun App() {
6465
}
6566

6667
LaunchedEffect(service) {
67-
service.subscribeToNews().collect { article ->
68-
news.add(article)
68+
streamScoped {
69+
service.subscribeToNews().collect { article ->
70+
news.add(article)
71+
}
6972
}
7073
}
7174

samples/ktor-all-platforms-app/gradle/libs.versions.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ktor = "2.3.8"
2020
logback = "1.4.14"
2121
kotlinx-serialization-json = "1.6.1"
2222
kotlinx-coroutines-core = "1.7.3"
23-
krpc = "5.4-beta"
23+
kotlinx-rpc = "6.0-beta"
2424

2525
[libraries]
2626
# kotlin
@@ -57,13 +57,13 @@ ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
5757
ktor-client-websockets = { module = "io.ktor:ktor-client-websockets", version.ref = "ktor" }
5858
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
5959

60-
# krpc
61-
krpc-runtime = { module = "org.jetbrains.krpc:krpc-runtime" }
62-
krpc-runtime-client = { module = "org.jetbrains.krpc:krpc-runtime-client" }
63-
krpc-runtime-server = { module = "org.jetbrains.krpc:krpc-runtime-server" }
64-
krpc-transport-ktor-client = { module = "org.jetbrains.krpc:krpc-transport-ktor-client" }
65-
krpc-transport-ktor-server = { module = "org.jetbrains.krpc:krpc-transport-ktor-server" }
66-
krpc-runtime-serialization-json = { module = "org.jetbrains.krpc:krpc-runtime-serialization-json" }
60+
# kotlinx-rpc
61+
kotlinx-rpc-runtime = { module = "org.jetbrains.kotlinx:kotlinx-rpc-runtime" }
62+
kotlinx-rpc-runtime-client = { module = "org.jetbrains.kotlinx:kotlinx-rpc-runtime-client" }
63+
kotlinx-rpc-runtime-server = { module = "org.jetbrains.kotlinx:kotlinx-rpc-runtime-server" }
64+
kotlinx-rpc-transport-ktor-client = { module = "org.jetbrains.kotlinx:kotlinx-rpc-transport-ktor-client" }
65+
kotlinx-rpc-transport-ktor-server = { module = "org.jetbrains.kotlinx:kotlinx-rpc-transport-ktor-server" }
66+
kotlinx-rpc-runtime-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-rpc-runtime-serialization-json" }
6767

6868
# other
6969
logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
@@ -79,6 +79,6 @@ kotlinPluginSerialization = { id = "org.jetbrains.kotlin.plugin.serialization",
7979
kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
8080
ktor = { id = "io.ktor.plugin", version.ref = "ktor" }
8181
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
82-
krpc = { id = "org.jetbrains.krpc.plugin", version.ref = "krpc" }
83-
krpc-platform = { id = "org.jetbrains.krpc.platform", version.ref = "krpc" }
82+
kotlinx-rpc = { id = "org.jetbrains.kotlinx.rpc.plugin", version.ref = "kotlinx-rpc" }
83+
kotlinx-rpc-platform = { id = "org.jetbrains.kotlinx.rpc.platform", version.ref = "kotlinx-rpc" }
8484
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
TEAM_ID=
2-
BUNDLE_ID=org.jetbrains.krpc.sample.ktor-all-platforms-app
2+
BUNDLE_ID=kotlinx.rpc.sample.ktor-all-platforms-app
33
APP_NAME=ktor-all-platforms-app

samples/ktor-all-platforms-app/server/build.gradle.kts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
plugins {
66
alias(libs.plugins.kotlinJvm)
77
alias(libs.plugins.ktor)
8-
alias(libs.plugins.krpc.platform)
8+
alias(libs.plugins.kotlinx.rpc.platform)
99
application
1010
}
1111

12-
group = "org.jetbrains.krpc.sample"
12+
group = "kotlinx.rpc.sample"
1313
version = "1.0.0"
1414
application {
15-
mainClass.set("org.jetbrains.krpc.sample.ApplicationKt")
15+
mainClass.set("kotlinx.rpc.sample.ApplicationKt")
1616
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=${extra["development"] ?: "false"}")
1717
}
1818

@@ -25,11 +25,11 @@ dependencies {
2525
implementation(libs.ktor.server.cors.jvm)
2626
implementation(libs.ktor.server.websockets.jvm)
2727
implementation(libs.ktor.server.host.common.jvm)
28-
implementation(libs.krpc.runtime.server)
29-
implementation(libs.krpc.runtime.serialization.json)
30-
implementation(libs.krpc.transport.ktor.server)
28+
implementation(libs.kotlinx.rpc.runtime.server)
29+
implementation(libs.kotlinx.rpc.runtime.serialization.json)
30+
implementation(libs.kotlinx.rpc.transport.ktor.server)
3131
testImplementation(libs.ktor.server.tests)
32-
testImplementation(libs.krpc.runtime.client)
33-
testImplementation(libs.krpc.transport.ktor.client)
32+
testImplementation(libs.kotlinx.rpc.runtime.client)
33+
testImplementation(libs.kotlinx.rpc.transport.ktor.client)
3434
testImplementation(libs.kotlin.test.junit)
3535
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
package org.jetbrains.krpc.sample
5+
package kotlinx.rpc.sample
66

77
import UserService
88
import io.ktor.http.*
99
import io.ktor.server.application.*
1010
import io.ktor.server.netty.*
1111
import io.ktor.server.plugins.cors.routing.*
1212
import io.ktor.server.routing.*
13-
import io.ktor.server.websocket.*
14-
import org.jetbrains.krpc.serialization.json
15-
import org.jetbrains.krpc.transport.ktor.server.rpc
13+
import kotlinx.rpc.serialization.json
14+
import kotlinx.rpc.transport.ktor.server.RPC
15+
import kotlinx.rpc.transport.ktor.server.rpc
1616

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

1919
@Suppress("unused")
2020
fun Application.module() {
21-
install(WebSockets)
21+
install(RPC)
2222

2323
installCORS()
2424

@@ -30,7 +30,7 @@ fun Application.module() {
3030
}
3131
}
3232

33-
registerService<UserService>(UserServiceImpl())
33+
registerService<UserService> { ctx -> UserServiceImpl(ctx) }
3434
}
3535
}
3636
}

0 commit comments

Comments
 (0)