refactor(websocket): upgrade socket.io

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-11-18 16:21:56 +08:00
parent 17af1fd49b
commit 47478e13aa
26 changed files with 1844 additions and 1680 deletions

View File

@@ -0,0 +1,45 @@
import { EventEmitter } from 'events'
import { InnerClient } from '../interfaces'
import { AttributeKeys } from './constants'
const TextWebSocketFrame = Java.type('io.netty.handler.codec.http.websocketx.TextWebSocketFrame')
export class NettyClient extends EventEmitter implements InnerClient {
private _id: string
private channel: any
server: any
readyState: string
remoteAddress: string
upgraded: boolean
request: any
constructor(server: any, channel: any) {
super()
this.server = server
this.readyState = 'open'
this.remoteAddress = channel.remoteAddress() + ''
this.upgraded = true
this.request = channel.attr(AttributeKeys.Request).get()
this.channel = channel
this._id = channel.id() + ''
}
get id() {
return this._id
}
send(text: string) {
if (this.readyState == 'open') {
this.channel.writeAndFlush(new TextWebSocketFrame(text))
} else {
console.debug(`send message ${text} to close client ${this._id}`)
}
}
close() {
if (this.readyState = 'open') {
this.channel.close()
this.readyState = 'close'
}
}
}