feat: complate sockt.io server

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-03-23 18:33:12 +08:00
parent efd1e5bd62
commit b6318cb8c1
8 changed files with 288 additions and 61 deletions

View File

@@ -1,5 +1,6 @@
import { EventEmitter } from 'events'
import { SocketIO } from 'socket-io/interfaces';
import { Keys, AttributeKeys } from './constants';
const TextWebSocketFrame = Java.type('io.netty.handler.codec.http.websocketx.TextWebSocketFrame')
@@ -17,6 +18,12 @@ export class NettyClient extends EventEmitter implements SocketIO.EngineSocket {
constructor(server: any, channel: any) {
super();
this.server = server;
this.readyState = 'open';
this.remoteAddress = channel.remoteAddress() + ''
this.upgraded = true;
this.request = channel.attr(AttributeKeys.Request).get();
this.transport = null;
this.channel = channel;
this._id = channel.id();
}
@@ -27,4 +34,7 @@ export class NettyClient extends EventEmitter implements SocketIO.EngineSocket {
send(text: string) {
this.channel.writeAndFlush(new TextWebSocketFrame(text))
}
close() {
this.channel.close();
}
}