feat: complate socket.io base framework

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-03-21 15:47:42 +08:00
parent 2fb62b26a0
commit 9dae44278d
20 changed files with 1569 additions and 16 deletions

View File

@ -0,0 +1,27 @@
import { EventEmitter } from 'events'
const TextWebSocketFrame = Java.type('io.netty.handler.codec.http.websocketx.TextWebSocketFrame')
export class NettyClient {
private event: EventEmitter
private _id: string;
private channel: any
constructor(channel: any) {
this.channel = channel;
this._id = channel.id();
this.event = new EventEmitter();
}
get id() {
return this._id;
}
on(event: string, callback: (...args: any[]) => void) {
this.event.on(event, callback);
}
emit(event: string, text: string) {
this.event.emit(event, text);
}
send(text: string) {
this.channel.writeAndFlush(new TextWebSocketFrame(text))
}
}