feat: 增强 RemoteApp 支持用户名;更新 light-code 路由处理逻辑;优化 SyncBase 文件路径检查
This commit is contained in:
@@ -4,6 +4,7 @@ type RemoteAppOptions = {
|
||||
app?: App;
|
||||
url?: string;
|
||||
token?: string;
|
||||
username?: string;
|
||||
emitter?: EventEmitter;
|
||||
id?: string;
|
||||
/** 是否启用自动重连,默认 true */
|
||||
@@ -24,6 +25,7 @@ export class RemoteApp {
|
||||
mainApp: App;
|
||||
url: string;
|
||||
id: string;
|
||||
username: string;
|
||||
emitter: EventEmitter;
|
||||
isConnected: boolean;
|
||||
ws: WebSocket;
|
||||
@@ -43,12 +45,17 @@ export class RemoteApp {
|
||||
const token = opts.token;
|
||||
const url = opts.url;
|
||||
const id = opts.id;
|
||||
const username = opts.username;
|
||||
this.username = username;
|
||||
this.emitter = opts?.emitter || new EventEmitter();
|
||||
const _url = new URL(url);
|
||||
if (token) {
|
||||
_url.searchParams.set('token', token);
|
||||
}
|
||||
_url.searchParams.set('id', id);
|
||||
if (!token && !username) {
|
||||
console.error(`[remote-app] 不存在用户名和token ${id}. 权限认证会失败。`);
|
||||
}
|
||||
this.url = _url.toString();
|
||||
this.id = id;
|
||||
// 初始化重连相关配置
|
||||
@@ -223,6 +230,7 @@ export class RemoteApp {
|
||||
listenProxy() {
|
||||
const remoteApp = this;
|
||||
const app = this.mainApp;
|
||||
const username = this.username;
|
||||
const listenFn = async (event: any) => {
|
||||
try {
|
||||
const data = event.toString();
|
||||
@@ -262,8 +270,10 @@ export class RemoteApp {
|
||||
};
|
||||
remoteApp.json({
|
||||
id: this.id,
|
||||
type: 'registryClient'
|
||||
type: 'registryClient',
|
||||
username: username,
|
||||
});
|
||||
console.log(`远程应用 ${this.id} (${username}) 已注册到主应用,等待消息...`);
|
||||
remoteApp.emitter.on('message', listenFn);
|
||||
const closeMessage = () => {
|
||||
remoteApp.emitter.off('message', listenFn);
|
||||
|
||||
Reference in New Issue
Block a user