Add native rsocket-tcp
This commit is contained in:
parent
07adf143cf
commit
879073e339
@ -1,5 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("ru.mipt.npm.gradle.mpp")
|
id("ru.mipt.npm.gradle.mpp")
|
||||||
|
id("ru.mipt.npm.gradle.native")
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ suspend fun MagixEndpoint.startDemoDeviceServer(): ApplicationEngine = embeddedS
|
|||||||
val cosFlow = MutableSharedFlow<Meta?>()// = device.cos.flow()
|
val cosFlow = MutableSharedFlow<Meta?>()// = device.cos.flow()
|
||||||
|
|
||||||
launch {
|
launch {
|
||||||
subscribe(controlsMagixFormat).collect { (magix, payload) ->
|
subscribe(controlsMagixFormat).collect { (_, payload) ->
|
||||||
(payload as? PropertyChangedMessage)?.let { message ->
|
(payload as? PropertyChangedMessage)?.let { message ->
|
||||||
when (message.property) {
|
when (message.property) {
|
||||||
"sin" -> sinFlow.emit(message.value)
|
"sin" -> sinFlow.emit(message.value)
|
||||||
|
@ -30,9 +30,9 @@ public interface MagixClient<T> {
|
|||||||
*
|
*
|
||||||
* @param host host name of magix server event loop
|
* @param host host name of magix server event loop
|
||||||
* @param port port of magix server event loop
|
* @param port port of magix server event loop
|
||||||
* @param path
|
* @param path context path for WS connection
|
||||||
*/
|
*/
|
||||||
static MagixClient<JsonElement> rSocketWs(String host, int port, String path) {
|
static MagixClient<JsonElement> rSocketWs(String host, int port, String path) {
|
||||||
return ControlsMagixClient.Companion.rSocketWs(host, port, JsonElement.Companion.serializer(), path);
|
return ControlsMagixClient.Companion.rSocketWs(host, port, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package ru.mipt.npm.magix.client
|
|||||||
|
|
||||||
import kotlinx.coroutines.jdk9.asPublisher
|
import kotlinx.coroutines.jdk9.asPublisher
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.serialization.KSerializer
|
|
||||||
import ru.mipt.npm.magix.api.MagixEndpoint
|
import ru.mipt.npm.magix.api.MagixEndpoint
|
||||||
import ru.mipt.npm.magix.api.MagixMessage
|
import ru.mipt.npm.magix.api.MagixMessage
|
||||||
import ru.mipt.npm.magix.api.MagixMessageFilter
|
import ru.mipt.npm.magix.api.MagixMessageFilter
|
||||||
@ -36,7 +35,6 @@ internal class ControlsMagixClient<T>(
|
|||||||
fun <T> rSocketWs(
|
fun <T> rSocketWs(
|
||||||
host: String,
|
host: String,
|
||||||
port: Int,
|
port: Int,
|
||||||
payloadSerializer: KSerializer<T>,
|
|
||||||
path: String = "/rsocket"
|
path: String = "/rsocket"
|
||||||
): ControlsMagixClient<T> {
|
): ControlsMagixClient<T> {
|
||||||
val endpoint = runBlocking {
|
val endpoint = runBlocking {
|
||||||
|
@ -28,7 +28,11 @@ kotlin {
|
|||||||
}
|
}
|
||||||
jvmMain {
|
jvmMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("io.ktor:ktor-network:$ktorVersion")
|
implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
linuxX64Main{
|
||||||
|
dependencies {
|
||||||
implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion")
|
implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ru.mipt.npm.magix.rsocket
|
package ru.mipt.npm.magix.rsocket
|
||||||
|
|
||||||
import io.ktor.network.sockets.SocketOptions
|
import io.ktor.network.sockets.SocketOptions
|
||||||
import io.ktor.util.InternalAPI
|
|
||||||
import io.rsocket.kotlin.core.RSocketConnectorBuilder
|
import io.rsocket.kotlin.core.RSocketConnectorBuilder
|
||||||
import io.rsocket.kotlin.transport.ktor.tcp.TcpClientTransport
|
import io.rsocket.kotlin.transport.ktor.tcp.TcpClientTransport
|
||||||
import ru.mipt.npm.magix.api.MagixEndpoint
|
import ru.mipt.npm.magix.api.MagixEndpoint
|
||||||
@ -11,7 +10,6 @@ import kotlin.coroutines.coroutineContext
|
|||||||
/**
|
/**
|
||||||
* Create a plain TCP based [RSocketMagixEndpoint] connected to [host] and [port]
|
* Create a plain TCP based [RSocketMagixEndpoint] connected to [host] and [port]
|
||||||
*/
|
*/
|
||||||
@OptIn(InternalAPI::class)
|
|
||||||
public suspend fun MagixEndpoint.Companion.rSocketWithTcp(
|
public suspend fun MagixEndpoint.Companion.rSocketWithTcp(
|
||||||
host: String,
|
host: String,
|
||||||
port: Int = DEFAULT_MAGIX_RAW_PORT,
|
port: Int = DEFAULT_MAGIX_RAW_PORT,
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package rsocket
|
||||||
|
|
||||||
|
import io.ktor.network.sockets.SocketOptions
|
||||||
|
import io.rsocket.kotlin.core.RSocketConnectorBuilder
|
||||||
|
import io.rsocket.kotlin.transport.ktor.tcp.TcpClientTransport
|
||||||
|
import ru.mipt.npm.magix.api.MagixEndpoint
|
||||||
|
import ru.mipt.npm.magix.rsocket.RSocketMagixEndpoint
|
||||||
|
import ru.mipt.npm.magix.rsocket.buildConnector
|
||||||
|
import kotlin.coroutines.coroutineContext
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a plain TCP based [RSocketMagixEndpoint] connected to [host] and [port]
|
||||||
|
*/
|
||||||
|
public suspend fun MagixEndpoint.Companion.rSocketWithTcp(
|
||||||
|
host: String,
|
||||||
|
port: Int = DEFAULT_MAGIX_RAW_PORT,
|
||||||
|
tcpConfig: SocketOptions.TCPClientSocketOptions.() -> Unit = {},
|
||||||
|
rSocketConfig: RSocketConnectorBuilder.ConnectionConfigBuilder.() -> Unit = {},
|
||||||
|
): RSocketMagixEndpoint {
|
||||||
|
val transport = TcpClientTransport(
|
||||||
|
hostname = host,
|
||||||
|
port = port,
|
||||||
|
configure = tcpConfig
|
||||||
|
)
|
||||||
|
val rSocket = buildConnector(rSocketConfig).connect(transport)
|
||||||
|
|
||||||
|
return RSocketMagixEndpoint(rSocket, coroutineContext)
|
||||||
|
}
|
@ -19,7 +19,7 @@ val rsocketVersion: String by rootProject.extra
|
|||||||
val ktorVersion: String = ru.mipt.npm.gradle.KScienceVersions.ktorVersion
|
val ktorVersion: String = ru.mipt.npm.gradle.KScienceVersions.ktorVersion
|
||||||
|
|
||||||
dependencies{
|
dependencies{
|
||||||
api(project(":magix:magix-api"))
|
api(projects.magix.magixApi)
|
||||||
api("io.ktor:ktor-server-cio:$ktorVersion")
|
api("io.ktor:ktor-server-cio:$ktorVersion")
|
||||||
api("io.ktor:ktor-server-websockets:$ktorVersion")
|
api("io.ktor:ktor-server-websockets:$ktorVersion")
|
||||||
api("io.ktor:ktor-server-content-negotiation:$ktorVersion")
|
api("io.ktor:ktor-server-content-negotiation:$ktorVersion")
|
||||||
|
Loading…
Reference in New Issue
Block a user