fix: disable server error
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
ccaa268362
commit
328d93cd3f
@ -4,11 +4,13 @@ export abstract class WebSocketHandlerAdapter {
|
||||
private _Handler;
|
||||
constructor() {
|
||||
let ChannelInboundHandlerAdapterImpl = Java.extend(ChannelInboundHandlerAdapter, {
|
||||
channelRead: this.channelRead.bind(this)
|
||||
channelRead: this.channelRead.bind(this),
|
||||
exceptionCaught: this.exceptionCaught.bind(this)
|
||||
})
|
||||
this._Handler = new ChannelInboundHandlerAdapterImpl()
|
||||
}
|
||||
abstract channelRead(ctx: any, channel: any);
|
||||
abstract exceptionCaught(ctx: any, cause: Error);
|
||||
getHandler() {
|
||||
return this._Handler;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { EventEmitter } from 'events'
|
||||
import { SocketIO } from 'socket-io/interfaces';
|
||||
import { Keys, AttributeKeys } from './constants';
|
||||
import { AttributeKeys } from './constants';
|
||||
|
||||
const TextWebSocketFrame = Java.type('io.netty.handler.codec.http.websocketx.TextWebSocketFrame')
|
||||
|
||||
|
@ -4,7 +4,7 @@ import { ServerEvent, Keys } from './constants'
|
||||
import { WebSocketDetect } from './websocket_detect'
|
||||
import { WebSocketHandler } from './websocket_handler'
|
||||
import { NettyClient } from './client'
|
||||
import { ServerOptions, Server } from '../socket-io'
|
||||
import { ServerOptions } from '../socket-io'
|
||||
|
||||
class NettyWebSocketServer extends EventEmitter {
|
||||
private pipeline: any;
|
||||
|
@ -11,4 +11,7 @@ export class WebSocketDetect extends WebSocketHandlerAdapter {
|
||||
channelRead(ctx: any, channel: any) {
|
||||
this.event.emit(ServerEvent.detect, ctx, channel);
|
||||
}
|
||||
exceptionCaught(ctx: any, cause: Error) {
|
||||
this.event.emit(ServerEvent.error, ctx, cause);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { EventEmitter } from 'events'
|
||||
|
||||
import { Keys } from './constants'
|
||||
import { Keys, ServerEvent } from './constants'
|
||||
import { WebSocketHandlerAdapter } from "../netty"
|
||||
import { HttpRequestHandler } from './httprequest'
|
||||
import { TextWebSocketFrameHandler } from './text_websocket_frame'
|
||||
@ -40,4 +40,7 @@ export class WebSocketHandler extends WebSocketHandlerAdapter {
|
||||
msg.resetReaderIndex()
|
||||
ctx.fireChannelRead(msg)
|
||||
}
|
||||
exceptionCaught(ctx: any, cause: Error) {
|
||||
this.options.event.emit(ServerEvent.error, ctx, cause)
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +17,6 @@ interface ServerOptions extends SocketIO.ServerOptions {
|
||||
root?: string;
|
||||
}
|
||||
|
||||
const defaultOptions: ServerOptions = {
|
||||
event: new EventEmitter(),
|
||||
path: '/socket.io',
|
||||
root: root + '/wwwroot'
|
||||
}
|
||||
|
||||
class Server implements SocketIO.Server {
|
||||
private nettyServer: NettyWebSocketServer;
|
||||
private allClients: { [key: string]: Client };
|
||||
@ -43,7 +37,11 @@ class Server implements SocketIO.Server {
|
||||
this.nsps = {};
|
||||
this.sockets = new Namespace('/', this);
|
||||
this.nsps['/'] = this.sockets;
|
||||
this.initNettyServer(pipeline, Object.assign(defaultOptions, options));
|
||||
this.initNettyServer(pipeline, Object.assign({
|
||||
event: new EventEmitter(),
|
||||
path: '/socket.io',
|
||||
root: root + '/wwwroot'
|
||||
}, options));
|
||||
}
|
||||
|
||||
checkRequest(req: any, fn: (err: any, success: boolean) => void): void {
|
||||
|
@ -39,10 +39,10 @@ export class Parser {
|
||||
return '4"encode error"'
|
||||
}
|
||||
}
|
||||
console.debug(`encoded ${origin} as ${str}`);
|
||||
console.trace(`encoded ${origin} as ${str}`);
|
||||
return str;
|
||||
}
|
||||
tryStringify(str) {
|
||||
tryStringify(str: any) {
|
||||
try {
|
||||
return JSON.stringify(str);
|
||||
} catch (e) {
|
||||
@ -136,11 +136,11 @@ export class Parser {
|
||||
}
|
||||
}
|
||||
|
||||
console.debug(`decoded ${str} as ${JSON.stringify(p)}`);
|
||||
console.trace(`decoded ${str} as ${JSON.stringify(p)}`);
|
||||
return p;
|
||||
}
|
||||
|
||||
tryParse(str) {
|
||||
tryParse(str: string) {
|
||||
try {
|
||||
return JSON.parse(str);
|
||||
} catch (e) {
|
||||
|
Loading…
Reference in New Issue
Block a user