mirror of
https://github.com/tursom/TursomServer.git
synced 2025-01-30 14:20:07 +08:00
update
This commit is contained in:
parent
a8ce78e176
commit
1294fcba16
@ -6,6 +6,7 @@ plugins {
|
||||
dependencies {
|
||||
api(project(":"))
|
||||
api(project(":ts-core"))
|
||||
api(project(":ts-core:ts-buffer"))
|
||||
implementation(project(":ts-core:ts-xml"))
|
||||
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
|
||||
api(group = "com.squareup.retrofit2", name = "converter-gson", version = "2.9.0")
|
||||
@ -14,6 +15,9 @@ dependencies {
|
||||
|
||||
// https://mvnrepository.com/artifact/org.jsoup/jsoup
|
||||
api(group = "org.jsoup", name = "jsoup", version = "1.13.1")
|
||||
|
||||
|
||||
testImplementation(project(":ts-core:ts-coroutine"))
|
||||
}
|
||||
|
||||
@kotlin.Suppress("UNCHECKED_CAST")
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.tursom.http
|
||||
|
||||
import cn.tursom.utils.coroutine.MainDispatcher
|
||||
import cn.tursom.utils.gson
|
||||
import cn.tursom.core.Utils.gson
|
||||
import cn.tursom.core.coroutine.MainDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -33,6 +33,8 @@ class WebSocketClient(
|
||||
val maxContextLength: Int = 4096,
|
||||
private val headers: Map<String, String>? = null,
|
||||
private val handshakerUri: URI? = null,
|
||||
val autoRelease: Boolean = true,
|
||||
var initChannel: ((ch: SocketChannel) -> Unit)? = null
|
||||
) {
|
||||
private val uri: URI = URI.create(url)
|
||||
internal var ch: Channel? = null
|
||||
@ -68,10 +70,12 @@ class WebSocketClient(
|
||||
headers?.forEach { (k, v) ->
|
||||
httpHeaders[k] = v
|
||||
}
|
||||
val handshakerAdapter = WebSocketClientHandshakerAdapter(WebSocketClientHandshakerFactory.newHandshaker(
|
||||
handshakerUri ?: uri, WebSocketVersion.V13, null, true, httpHeaders
|
||||
), this, handler)
|
||||
val handler = WebSocketClientChannelHandler(this, handler)
|
||||
val handshakerAdapter = WebSocketClientHandshakerAdapter(
|
||||
WebSocketClientHandshakerFactory.newHandshaker(
|
||||
handshakerUri ?: uri, WebSocketVersion.V13, null, true, httpHeaders
|
||||
), this, handler
|
||||
)
|
||||
val handler = WebSocketClientChannelHandler(this, handler, autoRelease)
|
||||
val bootstrap = Bootstrap()
|
||||
bootstrap.group(group)
|
||||
.channel(NioSocketChannel::class.java)
|
||||
@ -90,14 +94,12 @@ class WebSocketClient(
|
||||
addLast(WebSocketClientCompressionHandler.INSTANCE)
|
||||
}
|
||||
addLast(handshakerAdapter)
|
||||
//if (log) {
|
||||
// addLast(LoggingHandler())
|
||||
//}
|
||||
addLast(handler)
|
||||
if (autoWrap) {
|
||||
addLast(WebSocketFrameWrapper)
|
||||
}
|
||||
}
|
||||
initChannel?.invoke(ch)
|
||||
}
|
||||
})
|
||||
bootstrap.connect(uri.host, port)
|
||||
|
@ -8,7 +8,8 @@ import io.netty.handler.codec.http.websocketx.*
|
||||
class WebSocketClientChannelHandler(
|
||||
val client: WebSocketClient,
|
||||
val handler: WebSocketHandler,
|
||||
) : SimpleChannelInboundHandler<WebSocketFrame>() {
|
||||
autoRelease: Boolean = true,
|
||||
) : SimpleChannelInboundHandler<WebSocketFrame>(autoRelease) {
|
||||
|
||||
override fun channelInactive(ctx: ChannelHandlerContext) {
|
||||
handler.onClose(client)
|
||||
|
Loading…
Reference in New Issue
Block a user