feat: add websocket package
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
87ac658a22
commit
1d783ebd1f
34
packages/websocket/package.json
Normal file
34
packages/websocket/package.json
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"name": "@ms/websocket",
|
||||||
|
"version": "0.1.1",
|
||||||
|
"description": "MiaoScript api package",
|
||||||
|
"keywords": [
|
||||||
|
"miaoscript",
|
||||||
|
"minecraft",
|
||||||
|
"bukkit",
|
||||||
|
"sponge"
|
||||||
|
],
|
||||||
|
"author": "MiaoWoo <admin@yumc.pw>",
|
||||||
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
|
"license": "ISC",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"publishConfig": {
|
||||||
|
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"clean": "rimraf dist",
|
||||||
|
"watch": "npx tsc --watch",
|
||||||
|
"build": "yarn clean && npx tsc",
|
||||||
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^3.0.0",
|
||||||
|
"typescript": "^3.7.4"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@ms/api": "^0.1.1",
|
||||||
|
"@ms/common": "^0.1.0"
|
||||||
|
},
|
||||||
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
|
}
|
1
packages/websocket/src/index.ts
Normal file
1
packages/websocket/src/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
import '@ms/nashorn'
|
21
packages/websocket/src/netty/httprequest.ts
Normal file
21
packages/websocket/src/netty/httprequest.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
23
packages/websocket/src/netty/text_websocket_frame.ts
Normal file
23
packages/websocket/src/netty/text_websocket_frame.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
18
packages/websocket/src/netty/websocket.ts
Normal file
18
packages/websocket/src/netty/websocket.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
7
packages/websocket/tsconfig.json
Normal file
7
packages/websocket/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": "src",
|
||||||
|
"outDir": "dist"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user