feat: 更新 RemoteApp 类以支持 token 和 app ID,增强 WebSocket URL 生成逻辑;添加 ws-app 测试文件
This commit is contained in:
@@ -20,11 +20,20 @@ export class RemoteApp {
|
||||
constructor(opts?: RemoteAppOptions) {
|
||||
this.mainApp = opts?.app;
|
||||
this.assistantConfig = opts?.assistantConfig;
|
||||
const share = this.assistantConfig?.getConfig()?.share;
|
||||
const config = this.assistantConfig?.getConfig();
|
||||
const share = config?.share;
|
||||
const token = config?.token;
|
||||
const app = config?.app || {};
|
||||
const name = app.id;
|
||||
this.emitter = opts?.emitter || new EventEmitter();
|
||||
if (share) {
|
||||
const { url, name, enabled } = share;
|
||||
this.url = url;
|
||||
const { url, enabled } = share;
|
||||
const _url = new URL(url);
|
||||
if (token) {
|
||||
_url.searchParams.set('token', token);
|
||||
}
|
||||
_url.searchParams.set('id', app.id);
|
||||
this.url = _url.toString();
|
||||
this.name = name;
|
||||
this.enabled = enabled ?? false;
|
||||
if (this.enabled) {
|
||||
@@ -84,6 +93,7 @@ export class RemoteApp {
|
||||
this.emitter.emit('close', this.name);
|
||||
}
|
||||
onMessage(data: any) {
|
||||
console.log('Message from remote app:', this.name, data.toString());
|
||||
this.emitter.emit('message', data);
|
||||
}
|
||||
onError(error: any) {
|
||||
@@ -97,7 +107,7 @@ export class RemoteApp {
|
||||
};
|
||||
}
|
||||
|
||||
sendData(data: any) {}
|
||||
sendData(data: any) { }
|
||||
json(data: any) {
|
||||
this.ws.send(JSON.stringify(data));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import http from 'http';
|
||||
import http from 'node:http';
|
||||
export const error = (msg: string, code = 500) => {
|
||||
return JSON.stringify({ code, message: msg });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user