@ -4,6 +4,7 @@ import { Keys } from './constants'
|
||||
import { WebSocketHandlerAdapter } from "../netty"
|
||||
import { HttpRequestHandler } from './httprequest'
|
||||
import { TextWebSocketFrameHandler } from './text_websocket_frame'
|
||||
import { NettyWebSocketServerOptions } from './config'
|
||||
|
||||
const CharsetUtil = Java.type('io.netty.util.CharsetUtil')
|
||||
|
||||
@ -13,10 +14,10 @@ const HttpObjectAggregator = Java.type('io.netty.handler.codec.http.HttpObjectAg
|
||||
const WebSocketServerProtocolHandler = Java.type('io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler')
|
||||
|
||||
export class WebSocketHandler extends WebSocketHandlerAdapter {
|
||||
private event: EventEmitter;
|
||||
constructor(event: EventEmitter) {
|
||||
private options: NettyWebSocketServerOptions;
|
||||
constructor(options: NettyWebSocketServerOptions) {
|
||||
super()
|
||||
this.event = event;
|
||||
this.options = options;
|
||||
}
|
||||
channelRead(ctx: any, msg: any) {
|
||||
msg.markReaderIndex()
|
||||
@ -32,8 +33,8 @@ export class WebSocketHandler extends WebSocketHandlerAdapter {
|
||||
pipeline.addLast('chunk', new ChunkedWriteHandler())
|
||||
pipeline.addLast('httpobj', new HttpObjectAggregator(64 * 1024))
|
||||
pipeline.addLast('http_request', new HttpRequestHandler().getHandler())
|
||||
pipeline.addLast('websocket', new WebSocketServerProtocolHandler("/ws", true))
|
||||
pipeline.addLast('websocket_handler', new TextWebSocketFrameHandler(this.event).getHandler())
|
||||
pipeline.addLast('websocket', new WebSocketServerProtocolHandler(this.options.path, true))
|
||||
pipeline.addLast('websocket_handler', new TextWebSocketFrameHandler(this.options).getHandler())
|
||||
}
|
||||
pipeline.remove(Keys.Handler)
|
||||
msg.resetReaderIndex()
|
||||
|
Reference in New Issue
Block a user