feat: export server & client

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-12-17 17:01:09 +08:00
parent 48cc6325b8
commit df1646dc15
4 changed files with 7 additions and 6 deletions

View File

@ -45,3 +45,7 @@ let io: SocketStatic = function (pipeline: any, options: Partial<ServerOptions>)
io.Instance = Symbol("@ccms/websocket")
export default io
export * from './socket-io'
export * from './client'
export * from './netty'
export * from './tomcat'
export * from './transport'

View File

@ -65,6 +65,5 @@ class NettyWebSocketServer extends EventEmitter {
export {
NettyWebSocketServer,
ServerEvent,
NettyClient
}

View File

@ -350,7 +350,7 @@ export class Client extends EventEmitter {
*
* @api private
*/
resetPingTimeout(timeout) {
resetPingTimeout(timeout: number) {
clearTimeout(this.pingTimeoutTimer)
this.pingTimeoutTimer = setTimeout(() => {
if (this.conn.readyState === "closed") return

View File

@ -5,9 +5,7 @@ import { ServerEvent } from '../socket-io/constants'
import { ProxyBeanName } from './constants'
import { TomcatClient } from './client'
const WebSocketServerProxy = Java.type("pw.yumc.MiaoScript.websocket.WebSocketProxy")
const ThreadPoolExecutor = Java.type('java.util.concurrent.ThreadPoolExecutor')
const ThreadPoolTaskExecutor = Java.type('org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor')
type TomcatWebSocketSession = javax.websocket.Session
@ -22,7 +20,7 @@ class TomcatWebSocketServer extends EventEmitter {
this.beanFactory = beanFactory
this.initThreadPool()
try { this.beanFactory.destroySingleton(ProxyBeanName) } catch (error) { }
let NashornWebSocketServerProxy = Java.extend(WebSocketServerProxy, {
let NashornWebSocketServerProxy = Java.extend(Java.type("pw.yumc.MiaoScript.websocket.WebSocketProxy"), {
onOpen: (session: TomcatWebSocketSession) => {
let cid = `${session?.getId()}`
let tomcatClient = new TomcatClient(this, session)
@ -58,6 +56,7 @@ class TomcatWebSocketServer extends EventEmitter {
this.beanFactory.registerSingleton(ProxyBeanName, new NashornWebSocketServerProxy())
}
private initThreadPool() {
const ThreadPoolTaskExecutor = Java.type('org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor')
this.executor = new ThreadPoolTaskExecutor()
this.executor.setCorePoolSize(10)
this.executor.setMaxPoolSize(100)
@ -76,6 +75,5 @@ class TomcatWebSocketServer extends EventEmitter {
export {
TomcatWebSocketServer,
ServerEvent,
TomcatClient
}