mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-22 08:37:14 +00:00
fixes
This commit is contained in:
parent
22e8f8e5d6
commit
2f4f9f3003
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
## 0.11.2
|
## 0.11.2
|
||||||
|
|
||||||
|
* `Ktor`:
|
||||||
|
* Support of `WebSockets` has been improved and added fixes inside of clients
|
||||||
|
|
||||||
## 0.11.1
|
## 0.11.1
|
||||||
|
|
||||||
* `Repos`
|
* `Repos`
|
||||||
|
@ -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> HttpClient.createStandardWebsocketFlow(
|
inline fun <reified T : Any> 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> HttpClient.createStandardWebsocketFlow(
|
|||||||
do {
|
do {
|
||||||
val reconnect = runCatchingSafely {
|
val reconnect = runCatchingSafely {
|
||||||
ws(correctedUrl, requestBuilder) {
|
ws(correctedUrl, requestBuilder) {
|
||||||
for (received in incoming) {
|
while (isActive) {
|
||||||
sendSerialized(received.data)
|
send(receiveDeserialized<T>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkReconnection(null)
|
checkReconnection(null)
|
||||||
|
@ -12,6 +12,7 @@ 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>,
|
||||||
|
@ -15,7 +15,8 @@ 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)
|
||||||
@ -23,7 +24,7 @@ inline fun <reified T : Any> Route.includeWebsocketHandling(
|
|||||||
webSocket(suburl, protocol ?.name) {
|
webSocket(suburl, protocol ?.name) {
|
||||||
safely {
|
safely {
|
||||||
flow.collect {
|
flow.collect {
|
||||||
sendSerialized(it)
|
sendSerialized(dataMapper(it) ?: return@collect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user