fix: java thread need direct callback socket

Signed-off-by: MiaoWoo <admin@yumc.pw>
backup
MiaoWoo 2020-12-07 11:13:30 +08:00
parent ad85c3bc9b
commit 8a15a5398f
2 changed files with 4 additions and 3 deletions

View File

@ -111,7 +111,7 @@ export class Client extends EventEmitter {
}
const nsp = this.server.of(name)
const socket = nsp._add(this, auth, () => {
nsp._add(this, auth, (socket: Socket) => {
this.sockets.set(socket.id, socket)
this.nsps.set(nsp.name, socket)
})

View File

@ -94,7 +94,7 @@ export class Namespace extends EventEmitter {
in(name: string): Namespace {
return this.to(name)
}
_add(client: Client, query?: any, fn?: () => void) {
_add(client: Client, query?: any, fn?: (socket: Socket) => void) {
const socket = new Socket(this, client, query || {})
console.debug(`client ${client.id} adding socket ${socket.id} to nsp ${this.name}`)
this.run(socket, err => {
@ -114,7 +114,8 @@ export class Namespace extends EventEmitter {
// violations (such as a disconnection before the connection
// logic is complete)
socket._onconnect()
if (fn) fn()
// !!! at java multi thread need direct callback socket
if (fn) fn(socket)
// fire user-set events
super.emit(ServerEvent.connect, socket)