ksrpcEnvironment



fun ksrpcEnvironment(stringFormat: StringFormat = Json, builder: KsrpcEnvironmentBuilder<String>.() -> Unit): KsrpcEnvironment<String>

Creates a string-based KsrpcEnvironment using the given stringFormat (JSON by default).

The builder lambda configures optional settings such as the KsrpcEnvironmentBuilder.errorListener. Pass a custom kotlinx.serialization.StringFormat to control how payloads are encoded on the wire.

Samples

// Create an environment with default settings (JSON serialization).
val env = ksrpcEnvironment { }

// Create an environment with a custom Json configuration.
val customEnv = ksrpcEnvironment(
    Json {
        ignoreUnknownKeys = true
        prettyPrint = true
    }
) { }
// Set an error listener to handle transport-level errors.
val env = ksrpcEnvironment {
    errorListener = ErrorListener { throwable ->
        println("ksrpc error: ${throwable.message}")
    }
}

// Reconfigure an existing environment with a new error listener.
val reconfigured = env.reconfigure {
    errorListener = ErrorListener { throwable ->
        println("Reconfigured handler: ${throwable.message}")
    }
}