feat: add 1.8.8 reflect & export io namespace

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-04-07 13:31:20 +08:00
parent d22b72f10a
commit 1c29a059d9
5 changed files with 53 additions and 5 deletions

View File

@ -1,3 +1,46 @@
/// <reference types="@ms/nashorn" />
export * from './socket-io'
import { Server, ServerOptions } from './socket-io'
interface SocketIOStatic {
/**
* Default Server constructor
*/
(): Server;
/**
* Creates a new Server
* @param srv The HTTP server that we're going to bind to
* @param opts An optional parameters object
*/
(srv: any, opts?: ServerOptions): Server;
/**
* Creates a new Server
* @param port A port to bind to, as a number, or a string
* @param An optional parameters object
*/
(port: string | number, opts?: ServerOptions): Server;
/**
* Creates a new Server
* @param A parameters object
*/
(opts: ServerOptions): Server;
/**
* Backwards compatibility
* @see io().listen()
*/
listen?: SocketIOStatic;
}
type SocketStatic = SocketIOStatic & { Instance?: symbol }
// @ts-ignore
let io: SocketStatic = function (pipeline: any, options: ServerOptions) {
return new Server(pipeline, options)
}
io.Instance = Symbol("@ms/websocket")
export default io
export * from './socket-io'

View File

@ -15,6 +15,8 @@ export enum Keys {
Default = "DefaultChannelPipeline"
}
let RequestAttributeKey: any
try { RequestAttributeKey = AttributeKey.valueOf('request') } catch (error) { }
export enum AttributeKeys {
Request = AttributeKey.valueOf('request')
}
Request = RequestAttributeKey
}

View File

@ -22,6 +22,7 @@ class NettyWebSocketServer extends EventEmitter {
ctx.fireChannelRead(channel)
})
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());
this.allClients[nettyClient.id] = nettyClient;
this.emit(ServerEvent.connect, nettyClient);