feat: integrate frpc manager and send dashboard info via WebSocket

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-03-15 11:10:33 +08:00
parent a9a7816e16
commit 516d0d26ee
2 changed files with 189 additions and 2 deletions

View File

@@ -2,8 +2,9 @@
const WebSocket = require('ws');
const config = require('./config');
const { getBoxId } = require('./fingerprint');
const { collect } = require('./metrics');
const { getBoxId } = require('./fingerprint');
const { collect } = require('./metrics');
const { getDashboardInfo, FrpcManager } = require('./frpc');
const MAX_BACKOFF_MS = 60_000;
@@ -15,16 +16,21 @@ class ClawClient {
this._hbTimer = null; // 心跳定时器
this._backoff = 1_000; // 重连等待ms
this._stopped = false;
this._frpc = new FrpcManager();
this._dashInfo = {}; // { dashboard_token, dashboard_port }
}
start() {
console.log(`[clawd] 启动中... 服务器 = ${this._cfg.server}`);
// 启动前提取 openclaw dashboard 信息(耗时操作放后台,不阻塞连接)
this._dashInfo = getDashboardInfo();
this._connect();
}
stop() {
this._stopped = true;
this._clearHeartbeat();
this._frpc.stop();
if (this._ws) this._ws.terminate();
console.log('[clawd] 已停止');
}
@@ -77,6 +83,8 @@ class ClawClient {
box_id: this._boxId,
claw_id: this._cfg.claw_id ?? null,
token: this._cfg.token ?? null,
// dashboard 信息可选openclaw 未安装时为空)
...this._dashInfo,
};
this._send(msg);
}
@@ -139,6 +147,13 @@ class ClawClient {
console.log(`[clawd] 已激活 claw_id = ${msg.claw_id}`);
}
// 启动 frpc如果 VPS 下发了 frp 配置)
if (msg.frp && msg.frp.server && msg.frp.auth_token) {
this._frpc.start(msg.claw_id, msg.frp).catch(e => {
console.error('[frpc] 启动失败:', e.message);
});
}
// 开始心跳
this._startHeartbeat();
}