feat: add websocket package

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-02-01 02:47:39 +08:00
parent 87ac658a22
commit 1d783ebd1f
6 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1 @@
import '@ms/nashorn'

View File

@ -0,0 +1,21 @@
/// <reference types="@ms/ployfill" />
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 default abstract class HttpRequestHandlerAdapter {
private _Handler;
constructor() {
this._Handler == Java.extend(SimpleChannelInboundHandler, {
acceptInboundMessage: (msg: any) => {
return FullHttpRequestMatcher.match(msg)
},
channelRead0: this.channelRead0
})
}
abstract channelRead0(ctx: any, msg: any);
getHandler() {
return this._Handler;
}
}

View File

@ -0,0 +1,23 @@
/// <reference types="@ms/ployfill" />
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 default abstract class TextWebSocketFrameHandlerAdapter {
private _Handler;
constructor() {
this._Handler == Java.extend(SimpleChannelInboundHandler, {
userEventTriggered: this.userEventTriggered,
acceptInboundMessage: (msg: any) => {
return TextWebSocketFrameMatcher.match(msg)
},
channelRead0: this.channelRead0
})
}
abstract userEventTriggered(ctx: any, evt: any);
abstract channelRead0(ctx: any, msg: any);
getHandler() {
return this._Handler;
}
}

View File

@ -0,0 +1,18 @@
import '@ms/api'
const MiaoWebSocket = 'miaowebsocket'
const CharsetUtil = Java.type('io.netty.util.CharsetUtil')
const ChannelInboundHandlerAdapter = Java.type('io.netty.channel.ChannelInboundHandlerAdapter')
export default abstract class WebSocketHandlerAdapter {
private _Handler;
constructor() {
this._Handler = Java.extend(ChannelInboundHandlerAdapter, {
channelRead: this.channelRead
})
}
abstract channelRead(ctx: any, msg: any);
getHandler() {
return this._Handler;
}
}