diff --git a/packages/core/server/src/gateway/ws-server.ts b/packages/core/server/src/gateway/ws-server.ts index 87ded7963c..bddef1bc21 100644 --- a/packages/core/server/src/gateway/ws-server.ts +++ b/packages/core/server/src/gateway/ws-server.ts @@ -187,6 +187,10 @@ export class WSServer extends EventEmitter { ); }); + app.on('ws:sendToClient', ({ clientId, message }) => { + this.sendToClient(clientId, message); + }); + app.on('ws:sendToCurrentApp', ({ message }) => { this.sendToConnectionsByTag('app', app.name, message); }); @@ -196,13 +200,7 @@ export class WSServer extends EventEmitter { }); app.on('ws:authorized', ({ clientId, userId }) => { - this.sendToConnectionsByTags( - [ - { tagName: 'userId', tagValue: userId }, - { tagName: 'app', tagValue: app.name }, - ], - { type: 'authorized' }, - ); + this.sendToClient(clientId, { type: 'authorized' }); }); } @@ -288,6 +286,13 @@ export class WSServer extends EventEmitter { }); } + sendToClient(clientId: string, sendMessage: object) { + const client = this.webSocketClients.get(clientId); + if (client) { + this.sendMessageToConnection(client, sendMessage); + } + } + loopThroughConnections(callback: (client: WebSocketClient) => void) { this.webSocketClients.forEach((client) => { callback(client); diff --git a/packages/plugins/@nocobase/plugin-async-task-manager/src/server/plugin.ts b/packages/plugins/@nocobase/plugin-async-task-manager/src/server/plugin.ts index 812ac6c9bd..494d826848 100644 --- a/packages/plugins/@nocobase/plugin-async-task-manager/src/server/plugin.ts +++ b/packages/plugins/@nocobase/plugin-async-task-manager/src/server/plugin.ts @@ -54,7 +54,7 @@ export class PluginAsyncExportServer extends Plugin { const asyncTaskManager = this.app.container.get('AsyncTaskManager'); this.app.on(`ws:message:request:async-tasks:list`, async (message) => { - const { tags } = message; + const { tags, clientId } = message; this.app.logger.info(`Received request for async tasks with tags: ${JSON.stringify(tags)}`); @@ -68,9 +68,8 @@ export class PluginAsyncExportServer extends Plugin { this.app.logger.info(`Found ${tasks.length} tasks for userId: ${userId}`); - this.app.emit('ws:sendToTag', { - tagKey: 'userId', - tagValue: userId, + this.app.emit('ws:sendToClient', { + clientId, message: { type: 'async-tasks', payload: tasks.map((task) => task.toJSON()), diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/plugin.ts b/packages/plugins/@nocobase/plugin-auth/src/server/plugin.ts index 28b13033c5..39e68d33b8 100644 --- a/packages/plugins/@nocobase/plugin-auth/src/server/plugin.ts +++ b/packages/plugins/@nocobase/plugin-auth/src/server/plugin.ts @@ -153,6 +153,7 @@ export class PluginAuthServer extends Plugin { userId: user.id, }); }); + this.app.auditManager.registerActions([ { name: 'auth:signIn',