feat: 更新WebSocket 优化逻辑

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2021-08-03 16:59:43 +08:00
parent 7d02194ac7
commit b36b63277f
45 changed files with 5465 additions and 2376 deletions

View File

@@ -1,24 +1,26 @@
import { Transport } from '../transport'
import { AttributeKeys } from './constants'
import { WebSocketClient } from '../server/client'
const TextWebSocketFrame = Java.type('io.netty.handler.codec.http.websocketx.TextWebSocketFrame')
export class NettyClient extends Transport {
export class NettyClient extends WebSocketClient {
private channel: any
constructor(server: any, channel: any) {
super(server)
this.remoteAddress = channel.remoteAddress() + ''
this.request = channel.attr(AttributeKeys.Request).get()
this._id = channel.id() + ''
constructor(channel: any) {
super()
this.id = channel.id() + ''
this.channel = channel
}
doSend(text: string) {
this.channel.writeAndFlush(new TextWebSocketFrame(text))
send(text: string, opts?: any, callback?: (err?: Error) => void) {
try {
this.channel.writeAndFlush(new TextWebSocketFrame(text))
callback?.()
} catch (error) {
callback?.(error)
}
}
doClose() {
close() {
this.channel.close()
}
}