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 23270b8..96cbe21 100644 --- a/assistant/src/module/assistant/local-app-manager/assistant-app.ts +++ b/assistant/src/module/assistant/local-app-manager/assistant-app.ts @@ -105,30 +105,27 @@ export class AssistantApp extends Manager { maxReconnectAttempts: Infinity, // 无限重连 enableBackoff: true, // 启用指数退避 }); - const isConnect = await remoteApp.isConnect(); - if (isConnect) { - remoteApp.listenProxy(); + remoteApp.isConnect(); + + this.remoteIsConnected = true; + // 监听连接成功和关闭事件 + remoteApp.on('open', () => { this.remoteIsConnected = true; - // 监听连接成功和关闭事件 - remoteApp.on('open', () => { - this.remoteIsConnected = true; - logger.debug('链接到了远程应用服务器'); - }); - remoteApp.on('close', () => { - this.remoteIsConnected = false; - console.log('远程连接已关闭,自动重连机制正在处理...'); - }); - remoteApp.on('maxReconnectAttemptsReached', () => { - logger.error('远程应用重连达到最大次数,停止重连'); - }); const appId = id; const username = config?.auth.username || 'unknown'; const url = new URL(`/${username}/v1/${appId}`, config?.registry || 'https://kevisual.cn/'); this.remoteUrl = url.toString(); - console.log('远程地址', this.remoteUrl); - } else { - console.log('Not connected to remote app server'); - } + logger.info('[remote-app] 远程地址', this.remoteUrl); + logger.debug('链接到了远程应用服务器'); + remoteApp.listenProxy() + }); + remoteApp.on('close', () => { + this.remoteIsConnected = false; + logger.info('[remote-app] 远程连接已关闭,自动重连机制正在处理...'); + }); + remoteApp.on('maxReconnectAttemptsReached', () => { + logger.error('远程应用重连达到最大次数,停止重连'); + }); this.remoteApp = remoteApp; } else { if (!token) { diff --git a/assistant/src/module/remote-app/remote-app.ts b/assistant/src/module/remote-app/remote-app.ts index b334910..b640a55 100644 --- a/assistant/src/module/remote-app/remote-app.ts +++ b/assistant/src/module/remote-app/remote-app.ts @@ -85,6 +85,9 @@ export class RemoteApp { } getWsURL(url: string) { const { protocol } = new URL(url); + if (protocol.startsWith('ws')) { + return url.toString() + } const wsProtocol = protocol === 'https:' ? 'wss:' : 'ws:'; const wsURL = url.toString().replace(protocol, wsProtocol); return wsURL; @@ -106,6 +109,7 @@ export class RemoteApp { ws.onopen = function () { that.isConnected = true; that.onOpen(); + console.log('[remote-app] WebSocket connection opened'); }; ws.onclose = function () { that.isConnected = false;