Compare commits
2 Commits
4c7ba62a5a
...
4e24213428
Author | SHA1 | Date | |
---|---|---|---|
4e24213428 | |||
3890689f5c |
@ -9,7 +9,6 @@ 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")
|
||||||
}
|
}
|
||||||
@ -67,11 +66,12 @@ kotlin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
mainClass.set("center.sciprog.application.ServerKt")
|
mainClass.set("fullstack.kotlin.demo.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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
|
package fullstack.kotlin.demo
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
sealed interface ControlEvent
|
sealed interface ControlEvent
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class IntControlEvent(val value: Int) : ControlEvent
|
data class CounterControlEvent(val value: Int) : ControlEvent
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
sealed interface DataEvent
|
sealed interface DataEvent
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class IntDataEvent(val value: Int) : DataEvent
|
data class CounterDataEvent(val value: Int) : DataEvent
|
@ -1,3 +1,5 @@
|
|||||||
|
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
|
||||||
@ -50,14 +52,14 @@ suspend fun main() {
|
|||||||
fun setCount(value: Int) {
|
fun setCount(value: Int) {
|
||||||
count = value
|
count = value
|
||||||
scope.launch {
|
scope.launch {
|
||||||
sendEvent(IntControlEvent(value))
|
sendEvent(CounterControlEvent(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(Unit){
|
LaunchedEffect(Unit){
|
||||||
dataFlow.onEach { event ->
|
dataFlow.onEach { event ->
|
||||||
println("Received $event")
|
println("Received $event")
|
||||||
if (event is IntDataEvent) {
|
if (event is CounterDataEvent) {
|
||||||
count = event.value
|
count = event.value
|
||||||
}
|
}
|
||||||
}.launchIn(scope)
|
}.launchIn(scope)
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package center.sciprog.application
|
package fullstack.kotlin.demo
|
||||||
|
|
||||||
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
|
||||||
@ -54,9 +50,9 @@ fun main() {
|
|||||||
|
|
||||||
controlFlow.onEach { event ->
|
controlFlow.onEach { event ->
|
||||||
println("Received $event")
|
println("Received $event")
|
||||||
if (event is IntControlEvent) {
|
if (event is CounterControlEvent) {
|
||||||
counterState = event.value
|
counterState = event.value
|
||||||
dataFlow.emit(IntDataEvent(event.value))
|
dataFlow.emit(CounterDataEvent(event.value))
|
||||||
}
|
}
|
||||||
}.launchIn(this)
|
}.launchIn(this)
|
||||||
|
|
||||||
@ -78,7 +74,8 @@ fun main() {
|
|||||||
}
|
}
|
||||||
//handler for request/stream
|
//handler for request/stream
|
||||||
requestStream { _: Payload ->
|
requestStream { _: Payload ->
|
||||||
merge(flowOf(IntDataEvent(counterState)), dataFlow).map { event ->
|
merge(flowOf(CounterDataEvent(counterState)), dataFlow).map { event ->
|
||||||
|
println("Sent $event")
|
||||||
buildPayload {
|
buildPayload {
|
||||||
data(Json.encodeToString<DataEvent>(event))
|
data(Json.encodeToString<DataEvent>(event))
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user