Compare commits

..

No commits in common. "4e24213428ebde1089662e887921f585277e785e" and "4c7ba62a5a26544358a4e50dc3f75d86c4771095" have entirely different histories.

4 changed files with 14 additions and 15 deletions

View File

@ -9,6 +9,7 @@ group = "center.sciprog"
version = "1.0-SNAPSHOT" version = "1.0-SNAPSHOT"
repositories { repositories {
jcenter()
mavenCentral() mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
} }
@ -66,12 +67,11 @@ kotlin {
} }
application { application {
mainClass.set("fullstack.kotlin.demo.ServerKt") mainClass.set("center.sciprog.application.ServerKt")
} }
tasks.named<Copy>("jvmProcessResources") { tasks.named<Copy>("jvmProcessResources") {
val jsBrowserDistribution = tasks.named("jsBrowserDistribution") val jsBrowserDistribution = tasks.named("jsBrowserDistribution")
include("*.js")
from(jsBrowserDistribution) from(jsBrowserDistribution)
} }

View File

@ -1,15 +1,13 @@
package fullstack.kotlin.demo
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@Serializable @Serializable
sealed interface ControlEvent sealed interface ControlEvent
@Serializable @Serializable
data class CounterControlEvent(val value: Int) : ControlEvent data class IntControlEvent(val value: Int) : ControlEvent
@Serializable @Serializable
sealed interface DataEvent sealed interface DataEvent
@Serializable @Serializable
data class CounterDataEvent(val value: Int) : DataEvent data class IntDataEvent(val value: Int) : DataEvent

View File

@ -1,5 +1,3 @@
package fullstack.kotlin.demo
import androidx.compose.runtime.* import androidx.compose.runtime.*
import io.ktor.client.engine.js.Js import io.ktor.client.engine.js.Js
import io.rsocket.kotlin.RSocket import io.rsocket.kotlin.RSocket
@ -52,14 +50,14 @@ suspend fun main() {
fun setCount(value: Int) { fun setCount(value: Int) {
count = value count = value
scope.launch { scope.launch {
sendEvent(CounterControlEvent(value)) sendEvent(IntControlEvent(value))
} }
} }
LaunchedEffect(Unit){ LaunchedEffect(Unit){
dataFlow.onEach { event -> dataFlow.onEach { event ->
println("Received $event") println("Received $event")
if (event is CounterDataEvent) { if (event is IntDataEvent) {
count = event.value count = event.value
} }
}.launchIn(scope) }.launchIn(scope)

View File

@ -1,5 +1,9 @@
package fullstack.kotlin.demo package center.sciprog.application
import ControlEvent
import DataEvent
import IntControlEvent
import IntDataEvent
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
import io.ktor.server.application.call import io.ktor.server.application.call
import io.ktor.server.application.install import io.ktor.server.application.install
@ -50,9 +54,9 @@ fun main() {
controlFlow.onEach { event -> controlFlow.onEach { event ->
println("Received $event") println("Received $event")
if (event is CounterControlEvent) { if (event is IntControlEvent) {
counterState = event.value counterState = event.value
dataFlow.emit(CounterDataEvent(event.value)) dataFlow.emit(IntDataEvent(event.value))
} }
}.launchIn(this) }.launchIn(this)
@ -74,8 +78,7 @@ fun main() {
} }
//handler for request/stream //handler for request/stream
requestStream { _: Payload -> requestStream { _: Payload ->
merge(flowOf(CounterDataEvent(counterState)), dataFlow).map { event -> merge(flowOf(IntDataEvent(counterState)), dataFlow).map { event ->
println("Sent $event")
buildPayload { buildPayload {
data(Json.encodeToString<DataEvent>(event)) data(Json.encodeToString<DataEvent>(event))
} }