Connection

A bidirectional channel that can both host and call services/sub-services.

(Meaning @KsServices can be used for both input and output of any @KsMethod)

Properties

Link copied to clipboard
Link copied to clipboard
abstract val env: KsrpcEnvironment<T>

Functions

Link copied to clipboard
abstract suspend fun call(channelId: ChannelId, endpoint: String, data: CallData<T>): CallData<T>
Link copied to clipboard
abstract suspend fun close()
abstract suspend fun close(id: ChannelId)
Link copied to clipboard
inline suspend fun <T : RpcService, R : RpcService, S> SingleChannelConnection<S>.connect(crossinline host: suspend (R) -> T)

Connects both default channels for a connection (incoming and outgoing).

@JvmName(name = "connectSerialized")
suspend fun <T> SingleChannelConnection<T>.connect(host: suspend (SerializedService<T>) -> SerializedService<T>)

Raw version of connect, performing the same functionality with SerializedService directly.

Link copied to clipboard
open suspend override fun defaultChannel(): SerializedService<T>

Get a SerializedService that is the default on this client (i.e. using DEFAULT channel id). This should act as the root service for most scenarios.

Link copied to clipboard
abstract suspend fun onClose(onClose: suspend () -> Unit)

Add a callback to be invoked when SuspendCloseable.close is called.

Link copied to clipboard
abstract suspend fun registerDefault(service: SerializedService<T>)

Register the primary service to be hosted on this communication channel.

Link copied to clipboard
inline suspend fun <T : RpcService, S> SingleChannelHost<S>.registerDefault(service: T)
suspend fun <T : RpcService, S> SingleChannelHost<S>.registerDefault(service: T, obj: RpcObject<T>)

Register a service to be hosted on the default channel.

Link copied to clipboard
abstract suspend fun registerHost(service: SerializedService<T>): ChannelId

Add a serialized service that can receive calls on this channel with the returned ChannelId. The calls will be allowed until close is called.

Link copied to clipboard
inline suspend fun <T : RpcService, S> ChannelHost<S>.registerHost(service: T): ChannelId
suspend fun <T : RpcService, S> ChannelHost<S>.registerHost(service: T, obj: RpcObject<T>): ChannelId

Register a service to be hosted, the ChannelId ollocated to this service is returned. Generally this should not be called directly, as it will happen automatically when services are returned from KsMethod tagged methods.

Link copied to clipboard
abstract suspend fun wrapChannel(channelId: ChannelId): SerializedService<T>

Takes a given channel id and creates a service wrapper to make calls on that channel.