refactor(websocket): upgrade socket.io
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
20
packages/websocket/src/netty/adapter/httprequest.ts
Normal file
20
packages/websocket/src/netty/adapter/httprequest.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
const TypeParameterMatcher = Java.type('io.netty.util.internal.TypeParameterMatcher')
|
||||
const SimpleChannelInboundHandler = Java.type('io.netty.channel.SimpleChannelInboundHandler')
|
||||
const FullHttpRequestMatcher = TypeParameterMatcher.get(base.getClass('io.netty.handler.codec.http.FullHttpRequest'))
|
||||
|
||||
export abstract class HttpRequestHandlerAdapter {
|
||||
private _Handler;
|
||||
constructor() {
|
||||
let HttpRequestHandlerAdapterImpl = Java.extend(SimpleChannelInboundHandler, {
|
||||
acceptInboundMessage: (msg: any) => {
|
||||
return FullHttpRequestMatcher.match(msg)
|
||||
},
|
||||
channelRead0: this.channelRead0.bind(this)
|
||||
})
|
||||
this._Handler = new HttpRequestHandlerAdapterImpl();
|
||||
}
|
||||
abstract channelRead0(ctx: any, request: any);
|
||||
getHandler() {
|
||||
return this._Handler;
|
||||
}
|
||||
}
|
||||
3
packages/websocket/src/netty/adapter/index.ts
Normal file
3
packages/websocket/src/netty/adapter/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './text_websocket_frame'
|
||||
export * from './websocket'
|
||||
export * from './httprequest'
|
||||
24
packages/websocket/src/netty/adapter/text_websocket_frame.ts
Normal file
24
packages/websocket/src/netty/adapter/text_websocket_frame.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
const TypeParameterMatcher = Java.type('io.netty.util.internal.TypeParameterMatcher')
|
||||
const TextWebSocketFrameMatcher = TypeParameterMatcher.get(base.getClass('io.netty.handler.codec.http.websocketx.TextWebSocketFrame'))
|
||||
const SimpleChannelInboundHandler = Java.type('io.netty.channel.SimpleChannelInboundHandler')
|
||||
|
||||
export abstract class TextWebSocketFrameHandlerAdapter {
|
||||
private _Handler
|
||||
constructor() {
|
||||
let TextWebSocketFrameHandlerAdapterImpl = Java.extend(SimpleChannelInboundHandler, {
|
||||
userEventTriggered: this.userEventTriggered.bind(this),
|
||||
acceptInboundMessage: (msg: any) => {
|
||||
return TextWebSocketFrameMatcher.match(msg)
|
||||
},
|
||||
channelRead0: this.channelRead0.bind(this),
|
||||
exceptionCaught: this.exceptionCaught.bind(this)
|
||||
})
|
||||
this._Handler = new TextWebSocketFrameHandlerAdapterImpl()
|
||||
}
|
||||
abstract userEventTriggered(ctx: any, evt: any)
|
||||
abstract channelRead0(ctx: any, msg: any)
|
||||
abstract exceptionCaught(ctx: any, cause: Error)
|
||||
getHandler() {
|
||||
return this._Handler
|
||||
}
|
||||
}
|
||||
21
packages/websocket/src/netty/adapter/websocket.ts
Normal file
21
packages/websocket/src/netty/adapter/websocket.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
const ChannelInboundHandlerAdapter = Java.type('io.netty.channel.ChannelInboundHandlerAdapter')
|
||||
|
||||
export abstract class WebSocketHandlerAdapter {
|
||||
private _Handler
|
||||
constructor() {
|
||||
let ChannelInboundHandlerAdapterImpl = Java.extend(ChannelInboundHandlerAdapter, {
|
||||
channelRead: this.channelRead.bind(this),
|
||||
channelInactive: this.channelInactive.bind(this),
|
||||
channelUnregistered: this.exceptionCaught.bind(this),
|
||||
exceptionCaught: this.exceptionCaught.bind(this)
|
||||
})
|
||||
this._Handler = new ChannelInboundHandlerAdapterImpl()
|
||||
}
|
||||
abstract channelRead(ctx: any, channel: any)
|
||||
abstract channelInactive(ctx: any)
|
||||
abstract channelUnregistered(ctx: any)
|
||||
abstract exceptionCaught(ctx: any, cause: Error)
|
||||
getHandler() {
|
||||
return this._Handler
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user