Compare commits

..

No commits in common. "c9c6d4c0c1f4d51f93d66a7d463191d6bd6263d5" and "04cf8c3d9a95e920763c7b0166ef480b9af7ff7f" have entirely different histories.

5 changed files with 7 additions and 14 deletions

View File

@ -1,10 +1,5 @@
# Changelog # Changelog
## 0.11.2
* `Ktor`:
* Support of `WebSockets` has been improved and added fixes inside of clients
## 0.11.1 ## 0.11.1
* `Repos` * `Repos`

View File

@ -14,5 +14,5 @@ crypto_js_version=4.1.1
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.11.2 version=0.11.1
android_code_version=126 android_code_version=125

View File

@ -19,7 +19,7 @@ import kotlinx.serialization.DeserializationStrategy
* @param checkReconnection This lambda will be called when it is required to reconnect to websocket to establish * @param checkReconnection This lambda will be called when it is required to reconnect to websocket to establish
* connection. Must return true in case if must be reconnected. By default always reconnecting * connection. Must return true in case if must be reconnected. By default always reconnecting
*/ */
inline fun <reified T : Any> HttpClient.createStandardWebsocketFlow( inline fun <reified T> HttpClient.createStandardWebsocketFlow(
url: String, url: String,
noinline checkReconnection: suspend (Throwable?) -> Boolean = { true }, noinline checkReconnection: suspend (Throwable?) -> Boolean = { true },
noinline requestBuilder: HttpRequestBuilder.() -> Unit = {} noinline requestBuilder: HttpRequestBuilder.() -> Unit = {}
@ -32,8 +32,8 @@ inline fun <reified T : Any> HttpClient.createStandardWebsocketFlow(
do { do {
val reconnect = runCatchingSafely { val reconnect = runCatchingSafely {
ws(correctedUrl, requestBuilder) { ws(correctedUrl, requestBuilder) {
while (isActive) { for (received in incoming) {
send(receiveDeserialized<T>()) sendSerialized(received.data)
} }
} }
checkReconnection(null) checkReconnection(null)

View File

@ -12,7 +12,6 @@ import io.ktor.websocket.send
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.SerializationStrategy
@Deprecated("This method will be removed soon")
fun <T> Route.includeWebsocketHandling( fun <T> Route.includeWebsocketHandling(
suburl: String, suburl: String,
flow: Flow<T>, flow: Flow<T>,

View File

@ -15,8 +15,7 @@ import kotlinx.serialization.SerializationStrategy
inline fun <reified T : Any> Route.includeWebsocketHandling( inline fun <reified T : Any> Route.includeWebsocketHandling(
suburl: String, suburl: String,
flow: Flow<T>, flow: Flow<T>,
protocol: URLProtocol? = null, protocol: URLProtocol? = null
noinline dataMapper: suspend WebSocketServerSession.(T) -> T? = { it }
) { ) {
application.apply { application.apply {
pluginOrNull(WebSockets) ?: install(WebSockets) pluginOrNull(WebSockets) ?: install(WebSockets)
@ -24,7 +23,7 @@ inline fun <reified T : Any> Route.includeWebsocketHandling(
webSocket(suburl, protocol ?.name) { webSocket(suburl, protocol ?.name) {
safely { safely {
flow.collect { flow.collect {
sendSerialized(dataMapper(it) ?: return@collect) sendSerialized(it)
} }
} }
} }