feat: 实现 RemoteApp 类以支持远程连接,添加初始化和重连逻辑;更新用户路由以支持获取用户信息

This commit is contained in:
2025-12-21 02:39:52 +08:00
parent 864766be4a
commit b3c5e7d68d
8 changed files with 300 additions and 166 deletions

View File

@@ -1,22 +1,42 @@
import { logger } from '@/module/logger.ts';
import { assistantConfig, app } from '../app.ts';
import { WebSocket } from 'ws';
import '../routes/index.ts';
import { RemoteApp } from '@/module/assistant/remote-app/remote-app.ts';
import { RemoteApp } from '@/module/remote-app/remote-app.ts';
const main = async () => {
assistantConfig.checkMounted();
const remoteApp = new RemoteApp({
assistantConfig,
app,
});
const connect = await remoteApp.isConnect();
if (connect) {
console.log('Connected to proxy server');
remoteApp.listenProxy();
} else {
console.log('Not connected to proxy server');
const config = assistantConfig?.getConfig();
const share = config?.share;
if (share && share.enabled !== false) {
const token = config?.token;
const url = new URL(share.url || 'https://kevisual.cn/ws/proxy');
const id = config?.app?.id;
if (!id) {
console.error('App ID is required for remote app connection.');
return;
}
if (!token) {
console.error('Token is required for remote app connection.');
return;
}
const remoteApp = new RemoteApp({
url: url.toString(),
token,
id,
app,
});
const connect = await remoteApp.isConnect();
if (connect) {
console.log('Connected to proxy server');
remoteApp.listenProxy();
remoteApp.emitter.on('message', (event) => {
const _msg = event.toString();
console.log('Received message from remote app:', _msg);
});
} else {
console.log('Not connected to proxy server');
}
}
};
// main();
main();