temp
This commit is contained in:
43
src/command/cnb/index.ts
Normal file
43
src/command/cnb/index.ts
Normal 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);
|
||||
Reference in New Issue
Block a user