fix: boardcast error when socket send packet

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-06-30 14:02:18 +08:00
parent f4aa568f0c
commit 678f4ca8a4
3 changed files with 247 additions and 234 deletions

View File

@ -1,44 +1,45 @@
import { EventEmitter } from 'events'
import { SocketIO } from '../socket-io/interfaces';
import { SocketIO } from '../socket-io/interfaces'
export class TomcatClient extends EventEmitter implements SocketIO.EngineSocket {
private _id: string;
private session: any
private _id: string
private session: javax.websocket.Session
server: any;
readyState: string;
remoteAddress: string;
upgraded: boolean;
request: any;
transport: any;
server: any
readyState: string
remoteAddress: string
upgraded: boolean
request: any
transport: any
constructor(server: any, session: any) {
super();
this.server = server;
this.readyState = 'open';
constructor(server: any, session: javax.websocket.Session) {
super()
this.server = server
this.readyState = 'open'
this.remoteAddress = session + ''
this.upgraded = true;
this.upgraded = true
this.request = {
uri: () => {
return session.getRequestURI() + ''
},
headers: () => {
return []
}
};
this.transport = null;
uri: () => `${session.getRequestURI()}`,
headers: () => []
}
this.transport = null
this.session = session;
this._id = session.getId();
this.session = session
this._id = session.getId()
}
get id() {
return this._id;
return this._id
}
send(text: string) {
Java.synchronized(() => this.session.getBasicRemote().sendText(text), this.session)()
if (this.readyState == 'open') {
Java.synchronized(() => this.session.getBasicRemote().sendText(text), this.session)()
}
}
close() {
this.session.close();
if (this.readyState == 'open') {
this.readyState = 'close'
this.session.close()
}
}
}