fix:fix reconnect
This commit is contained in:
@@ -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;
|
||||
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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user