diff --git a/packages/websocket/src/socket-io/client.ts b/packages/websocket/src/socket-io/client.ts index 9ed2fcb4..7a9773ad 100644 --- a/packages/websocket/src/socket-io/client.ts +++ b/packages/websocket/src/socket-io/client.ts @@ -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) }) diff --git a/packages/websocket/src/socket-io/namespace.ts b/packages/websocket/src/socket-io/namespace.ts index 8fa4c8c9..e6e6f59c 100644 --- a/packages/websocket/src/socket-io/namespace.ts +++ b/packages/websocket/src/socket-io/namespace.ts @@ -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)