feat: update plugin & websocket

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-04-24 16:42:36 +08:00
parent e9c13e44b4
commit 1431ce0a6e
2 changed files with 7 additions and 8 deletions

View File

@ -1,10 +1,10 @@
import { EventEmitter } from 'events' import { EventEmitter } from 'events'
import { NettyClient } from './client'
import { ServerOptions } from '../socket-io'
import { ServerEvent, Keys } from './constants' import { ServerEvent, Keys } from './constants'
import { WebSocketDetect } from './websocket_detect' import { WebSocketDetect } from './websocket_detect'
import { WebSocketHandler } from './websocket_handler' import { WebSocketHandler } from './websocket_handler'
import { NettyClient } from './client'
import { ServerOptions } from '../socket-io'
class NettyWebSocketServer extends EventEmitter { class NettyWebSocketServer extends EventEmitter {
private pipeline: any; private pipeline: any;
@ -22,10 +22,9 @@ class NettyWebSocketServer extends EventEmitter {
ctx.fireChannelRead(channel) ctx.fireChannelRead(channel)
}) })
connectEvent.on(ServerEvent.connect, (ctx) => { connectEvent.on(ServerEvent.connect, (ctx) => {
console.log('NettyWebSocketServer ServerEvent.connect', ctx, ctx.channel().id(), ctx.channel().class.name) let nettyClient = new NettyClient(this, ctx.channel())
let nettyClient = new NettyClient(this, ctx.channel()); this.allClients[nettyClient.id] = nettyClient
this.allClients[nettyClient.id] = nettyClient; this.emit(ServerEvent.connect, nettyClient)
this.emit(ServerEvent.connect, nettyClient);
}) })
connectEvent.on(ServerEvent.message, (ctx, msg) => { connectEvent.on(ServerEvent.message, (ctx, msg) => {
this.emit(ServerEvent.message, this.allClients[ctx.channel().id()], msg.text()) this.emit(ServerEvent.message, this.allClients[ctx.channel().id()], msg.text())
@ -46,4 +45,4 @@ export {
NettyWebSocketServer, NettyWebSocketServer,
ServerEvent, ServerEvent,
NettyClient NettyClient
}; }

View File

@ -1,7 +1,7 @@
import { TextWebSocketFrameHandlerAdapter } from '../netty'
import { EventEmitter } from 'events' import { EventEmitter } from 'events'
import { ServerEvent } from './constants' import { ServerEvent } from './constants'
import { ServerOptions } from '../socket-io'; import { ServerOptions } from '../socket-io';
import { TextWebSocketFrameHandlerAdapter } from '../netty'
export class TextWebSocketFrameHandler extends TextWebSocketFrameHandlerAdapter { export class TextWebSocketFrameHandler extends TextWebSocketFrameHandlerAdapter {
private event: EventEmitter; private event: EventEmitter;