This commit is contained in:
2026-02-11 23:59:13 +08:00
parent d3a9fec698
commit 34697e07b5
3 changed files with 308 additions and 71 deletions

43
src/command/cnb/index.ts Normal file
View File

@@ -0,0 +1,43 @@
import { createKeepAlive } from '@kevisual/cnb/keep'
import { program, Command } from '@/program.ts';
const cnbCmd = new Command('cnb')
.description('CNB 相关命令')
.action(async (opts) => {
console.log('CNB 命令');
});
const liveCmd = new Command('live')
.description('启动 CNB Keep Alive 服务')
.option('-u, --url <url>', 'WebSocket 服务器地址')
.option('-c, --cookie <cookie>', '认证 Cookie')
.action(async (opts) => {
if (!opts.url || !opts.cookie) {
console.log('请提供 WebSocket 服务器地址和认证 Cookie');
return;
}
const keepAlive = createKeepAlive({
wsUrl: opts.url,
cookie: opts.cookie,
debug: true,
onConnect: () => {
console.log('已连接到 CNB 服务器');
},
onDisconnect: (code) => {
console.log(`与 CNB 服务器断开连接,代码: ${code}`);
},
onError: (error) => {
console.error('CNB 连接错误:', error);
},
onMessage: (data) => {
console.log('收到 CNB 消息:', data.toString());
},
});
keepAlive.connect();
});
cnbCmd.addCommand(liveCmd);
program.addCommand(cnbCmd);