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