feat: integrate frpc manager and send dashboard info via WebSocket
Made-with: Cursor
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user