Skip to content

Commit

Permalink
Actualize sample with latest versions (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
whyoleg authored May 22, 2024
1 parent be1ffac commit 8d45e93
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 197 deletions.
12 changes: 7 additions & 5 deletions samples/chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

* api - shared chat API for both client and server
* client - client API implementation via requesting to RSocket with Protobuf serialization.
Works on JVM(TCP/WS), Native(TCP/WS), NodeJS(WS/TCP), Browser(WS).
Works on JVM(TCP/WS), Native(TCP/WS), Js(WS).
Tasks for running clients:
* JVM: `run`
* Native: `runDebugExecutableNative` / `runReleaseExecutableNative`
* NodeJs: `nodejsNodeRun` / `nodejsNodeDevelopmentRun` / `nodejsNodeProductionRun`
* Browser: `browserBrowserRun` / `browserBrowserDevelopmentRun` / `browserBrowserProductionRun`
* Native: `runDebugExecutable[TARGET]` / `runReleaseExecutable[TARGET]`
(where `[TARGET]` is one of `LinuxX64`, `MacosArm64` or `MacosX64`)
* NodeJs: `jsNodeRun` / `jsNodeDevelopmentRun` / `jsNodeProductionRun`
* Browser: `jsBrowserRun` / `jsBrowserDevelopmentRun` / `jsBrowserProductionRun`
* server - server API implementation with storage in concurrent map
and exposing it through RSocket with Protobuf serialization.
Can be started on JVM(TCP/WS), Native(TCP/WS), NodeJS(TCP).
Tasks for running servers:
* JVM: `run`
* Native: `runDebugExecutableNative` / `runReleaseExecutableNative`
* Native: `runDebugExecutable[TARGET]` / `runReleaseExecutable[TARGET]`
(where `[TARGET]` is one of `LinuxX64`, `MacosArm64` or `MacosX64`)
* NodeJs: `jsNodeRun` / `jsNodeDevelopmentRun` / `jsNodeProductionRun`
21 changes: 7 additions & 14 deletions samples/chat/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,8 +14,6 @@
* limitations under the License.
*/

import org.jetbrains.kotlin.konan.target.*

plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
Expand All @@ -30,19 +28,14 @@ kotlin {
browser()
nodejs()
}
when {
HostManager.hostIsLinux -> linuxX64("native")
HostManager.hostIsMingw -> null //no native support for TCP in ktor mingwX64("native")
HostManager.hostIsMac -> macosX64("native")
else -> null
}
linuxX64()
macosX64()
macosArm64()

sourceSets {
commonMain {
dependencies {
api("io.rsocket.kotlin:rsocket-core:$rsocketVersion")
api("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinxSerializationVersion")
}
commonMain.dependencies {
api("io.rsocket.kotlin:rsocket-core:$rsocketVersion")
api("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinxSerializationVersion")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,20 +14,18 @@
* limitations under the License.
*/

package io.rsocket.kotlin.samples.chat.client
import org.jetbrains.kotlin.gradle.targets.js.nodejs.*
import org.jetbrains.kotlin.gradle.targets.js.npm.*

import io.rsocket.kotlin.samples.chat.api.*
import kotlinx.coroutines.*
plugins {
kotlin("multiplatform") apply false
}

suspend fun main() {
coroutineScope {
//only WS is supported on browser JS
// native WS server is incompatible with js WS client
(Servers.WS - Servers.Native.WS).forEach {
val client = ApiClient(it, "Yuri")
launch {
client.use(it, "RSocket is awesome! (from browser)")
}
}
plugins.withType<NodeJsRootPlugin> {
// ignore package lock
extensions.configure<NpmExtension> {
lockFileDirectory.set(layout.buildDirectory.dir("kotlin-js-store"))
packageLockMismatchReport.set(LockFileMismatchReport.NONE)
packageLockAutoReplace.set(true)
}
}
69 changes: 25 additions & 44 deletions samples/chat/client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

import org.jetbrains.kotlin.konan.target.*
import org.jetbrains.kotlin.gradle.plugin.mpp.*

plugins {
kotlin("multiplatform")
Expand All @@ -33,56 +33,37 @@ kotlin {
jvm {
withJava()
}
js("browser") {
browser {
binaries.executable()
}
}
js("nodejs") {
nodejs {
binaries.executable()
}
js {
browser()
nodejs()
binaries.executable()
}
when {
HostManager.hostIsLinux -> linuxX64("native")
HostManager.hostIsMingw -> null //no native support for TCP in ktor mingwX64("clientNative")
HostManager.hostIsMac -> macosX64("native")
else -> null
}?.binaries {
executable {
entryPoint = "io.rsocket.kotlin.samples.chat.client.main"
linuxX64()
macosX64()
macosArm64()
targets.withType<KotlinNativeTarget>().configureEach {
binaries {
executable {
entryPoint = "io.rsocket.kotlin.samples.chat.client.main"
}
}
}

sourceSets {
commonMain {
dependencies {
implementation(project(":api"))
implementation("io.rsocket.kotlin:rsocket-transport-ktor-websocket-client:$rsocketVersion")
}
commonMain.dependencies {
implementation(project(":api"))
implementation("io.rsocket.kotlin:rsocket-transport-ktor-websocket-client:$rsocketVersion")
}
val jvmMain by getting {
dependencies {
implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
}
jvmMain.dependencies {
implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
}
findByName("nativeMain")?.apply {
dependencies {
implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
}
nativeMain.dependencies {
implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
}
val browserMain by getting {
dependencies {
implementation("io.ktor:ktor-client-js:$ktorVersion")
}
}
val nodejsMain by getting {
dependencies {
implementation("io.ktor:ktor-client-js:$ktorVersion")
implementation("io.rsocket.kotlin:rsocket-transport-nodejs-tcp:$rsocketVersion")
}
jsMain.dependencies {
implementation("io.ktor:ktor-client-js:$ktorVersion")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,14 +19,12 @@ package io.rsocket.kotlin.samples.chat.client
import io.rsocket.kotlin.samples.chat.api.*
import kotlinx.coroutines.*

suspend fun main() {
coroutineScope {
// native WS server is incompatible with js WS client
(Servers.ALL - Servers.Native.WS).forEach {
val client = ApiClient(it, "Kolya")
launch {
client.use(it, "RSocket is awesome! (from nodeJS)")
}
suspend fun main(): Unit = coroutineScope {
// only WS is supported on browser JS
Servers.WS.forEach {
val client = ApiClient(it, "Kolya")
launch {
client.use(it, "RSocket is awesome! (from js)")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright 2015-2022 the original author or authors.
~ Copyright 2015-2024 the original author or authors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down
32 changes: 0 additions & 32 deletions samples/chat/client/src/nodejsMain/kotlin/clientTransport.kt

This file was deleted.

22 changes: 11 additions & 11 deletions samples/chat/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2015-2022 the original author or authors.
# Copyright 2015-2024 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,16 +15,16 @@
#
group=io.rsocket.kotlin.sample.chat
version=1.0.0
kotlinVersion=1.6.20
ktorVersion=2.0.0
kotlinxSerializationVersion=1.3.2
rsocketVersion=0.15.4
kotlin.js.compiler=ir
kotlin.mpp.stability.nowarn=true
kotlin.native.binary.memoryModel=experimental
kotlin.native.binary.freezing=disabled
kotlinVersion=2.0.0
ktorVersion=2.3.11
kotlinxSerializationVersion=1.6.3
rsocketVersion=0.16.0

#Kotlin
kotlin.js.yarn=false
#Gradle
org.gradle.jvmargs=-Xmx2g
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx2g
org.gradle.vfs.watch=true
Binary file modified samples/chat/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion samples/chat/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 8d45e93

Please sign in to comment.