update WebSocketClient

This commit is contained in:
tursom 2021-07-05 17:30:30 +08:00
parent befef46add
commit 0e44169327
3 changed files with 8 additions and 0 deletions

View File

@ -195,6 +195,12 @@ open class WebSocketClient<in T : WebSocketClient<T, H>, H : WebSocketHandler<T,
return ch!!.writeAndFlush(PongWebSocketFrame(data))
}
fun onOpen() {
}
fun onClose() {
}
companion object {
val group: EventLoopGroup = NioEventLoopGroup()
}

View File

@ -12,6 +12,7 @@ class WebSocketClientChannelHandler<T : WebSocketClient<T, H>, H : WebSocketHand
) : SimpleChannelInboundHandler<WebSocketFrame>(autoRelease) {
override fun channelInactive(ctx: ChannelHandlerContext) {
client.onClose()
handler.onClose(client)
if (client.ch == ctx.channel()) {
client.ch = null

View File

@ -29,6 +29,7 @@ class WebSocketClientHandshakerAdapter<T : WebSocketClient<T, H>, H : WebSocketH
handshakeFuture!!.setSuccess()
//msg.retain()
//ctx.fireChannelRead(msg)
client.onOpen()
handler.onOpen(client)
return
} else {