serveWebsocket

inline fun <T : RpcService> Routing.serveWebsocket(basePath: String, service: T, env: KsrpcEnvironment<String>)

Hosts the given service over a WebSocket on the supplied basePath within a Ktor Routing block. The server application must have the WebSockets plugin installed.

Samples

val env = ksrpcEnvironment { }
val service = object : GreetingService {
    override suspend fun greet(name: String): String = "Hello, $name!"
}

// Embed ksrpc into a Ktor WebSocket server.
// The server application must have the WebSockets plugin installed.
val server = embeddedServer(Netty, port = 8080) {
    install(ServerWebSockets)
    routing {
        serveWebsocket("/ws", service, env)
    }
}
// server.start(wait = true)

fun Routing.serveWebsocket(basePath: String, channel: SerializedService<String>, env: KsrpcEnvironment<String>)