diff --git a/assistant/src/module/assistant/local-app-manager/assistant-app.ts b/assistant/src/module/assistant/local-app-manager/assistant-app.ts index 4182971..2cf59aa 100644 --- a/assistant/src/module/assistant/local-app-manager/assistant-app.ts +++ b/assistant/src/module/assistant/local-app-manager/assistant-app.ts @@ -133,7 +133,7 @@ export class AssistantApp extends Manager { if (url && id) { const remoteApp = new RemoteApp({ url: url.toString(), - token, + // token, username: config?.auth?.username || '', id, app: this.mainApp, diff --git a/assistant/src/module/remote-app/remote-app.ts b/assistant/src/module/remote-app/remote-app.ts index b86293f..4fcb4de 100644 --- a/assistant/src/module/remote-app/remote-app.ts +++ b/assistant/src/module/remote-app/remote-app.ts @@ -28,6 +28,7 @@ export class RemoteApp { username: string; emitter: EventEmitter; isConnected: boolean; + isVerified: boolean; ws: WebSocket; remoteIsConnected: boolean; isError: boolean = false; @@ -85,11 +86,25 @@ export class RemoteApp { clearTimeout(timeout); that.isConnected = true; that.remoteIsConnected = true; + resolve(true); }; that.emitter.once('open', listenOnce); }); } + async waitVerify(): Promise { + if (this.isVerified) { + return true; + } + // 等待验证成功 + return new Promise((resolve) => { + const listenOnce = () => { + this.isVerified = true; + resolve(true); + }; + this.emitter.once('verified', listenOnce); + }); + } getWsURL(url: string) { const { protocol } = new URL(url); if (protocol.startsWith('ws')) { @@ -238,12 +253,18 @@ export class RemoteApp { const bodyData = body?.data as ListenProcessParams; const message = bodyData?.message || {}; const context = bodyData?.context || {}; + console.log('[remote-app] 远程应用收到消息:', body); if (body?.code === 401) { - console.error('远程应用认证失败,请检查 token 是否正确'); + console.error('[remote-app] 远程应用认证失败,请检查 token 是否正确'); this.isError = true; return; } + if (body?.type === 'verified') { + remoteApp.emitter.emit('verified'); + return; + } if (body?.type !== 'proxy') return; + if (!body.id) { remoteApp.json({ id: body.id, @@ -265,7 +286,7 @@ export class RemoteApp { }, }); } catch (error) { - console.error('处理远程代理请求出错:', error); + console.error('[remote-app] 处理远程代理请求出错:', error); } }; remoteApp.json({ @@ -273,7 +294,7 @@ export class RemoteApp { type: 'registryClient', username: username, }); - console.log(`远程应用 ${this.id} (${username}) 已注册到主应用,等待消息...`); + console.log(`[remote-app] 远程应用 ${this.id} (${username}) 已注册到主应用,等待消息...`); remoteApp.emitter.on('message', listenFn); const closeMessage = () => { remoteApp.emitter.off('message', listenFn);