Compare commits
No commits in common. "4e24213428ebde1089662e887921f585277e785e" and "4c7ba62a5a26544358a4e50dc3f75d86c4771095" have entirely different histories.
4e24213428
...
4c7ba62a5a
@ -9,6 +9,7 @@ group = "center.sciprog"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
|
||||
}
|
||||
@ -66,12 +67,11 @@ kotlin {
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set("fullstack.kotlin.demo.ServerKt")
|
||||
mainClass.set("center.sciprog.application.ServerKt")
|
||||
}
|
||||
|
||||
tasks.named<Copy>("jvmProcessResources") {
|
||||
val jsBrowserDistribution = tasks.named("jsBrowserDistribution")
|
||||
include("*.js")
|
||||
from(jsBrowserDistribution)
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,13 @@
|
||||
package fullstack.kotlin.demo
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
sealed interface ControlEvent
|
||||
|
||||
@Serializable
|
||||
data class CounterControlEvent(val value: Int) : ControlEvent
|
||||
data class IntControlEvent(val value: Int) : ControlEvent
|
||||
|
||||
@Serializable
|
||||
sealed interface DataEvent
|
||||
|
||||
@Serializable
|
||||
data class CounterDataEvent(val value: Int) : DataEvent
|
||||
data class IntDataEvent(val value: Int) : DataEvent
|
@ -1,5 +1,3 @@
|
||||
package fullstack.kotlin.demo
|
||||
|
||||
import androidx.compose.runtime.*
|
||||
import io.ktor.client.engine.js.Js
|
||||
import io.rsocket.kotlin.RSocket
|
||||
@ -52,14 +50,14 @@ suspend fun main() {
|
||||
fun setCount(value: Int) {
|
||||
count = value
|
||||
scope.launch {
|
||||
sendEvent(CounterControlEvent(value))
|
||||
sendEvent(IntControlEvent(value))
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit){
|
||||
dataFlow.onEach { event ->
|
||||
println("Received $event")
|
||||
if (event is CounterDataEvent) {
|
||||
if (event is IntDataEvent) {
|
||||
count = event.value
|
||||
}
|
||||
}.launchIn(scope)
|
||||
|
@ -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.server.application.call
|
||||
import io.ktor.server.application.install
|
||||
@ -50,9 +54,9 @@ fun main() {
|
||||
|
||||
controlFlow.onEach { event ->
|
||||
println("Received $event")
|
||||
if (event is CounterControlEvent) {
|
||||
if (event is IntControlEvent) {
|
||||
counterState = event.value
|
||||
dataFlow.emit(CounterDataEvent(event.value))
|
||||
dataFlow.emit(IntDataEvent(event.value))
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
||||
@ -74,8 +78,7 @@ fun main() {
|
||||
}
|
||||
//handler for request/stream
|
||||
requestStream { _: Payload ->
|
||||
merge(flowOf(CounterDataEvent(counterState)), dataFlow).map { event ->
|
||||
println("Sent $event")
|
||||
merge(flowOf(IntDataEvent(counterState)), dataFlow).map { event ->
|
||||
buildPayload {
|
||||
data(Json.encodeToString<DataEvent>(event))
|
||||
}
|
Loading…
Reference in New Issue
Block a user