feat: add websocket package

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

View 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"
}

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;
}
}

View File

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist"
}
}