tirtc-devtools-cli 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/USAGE.md +417 -0
- package/bin/tirtc-devtool.js +2 -0
- package/dist/app-server/protocol-client/index.d.ts +25 -0
- package/dist/app-server/protocol-client/index.js +114 -0
- package/dist/devtools/cli/src/config.d.ts +46 -0
- package/dist/devtools/cli/src/config.js +98 -0
- package/dist/devtools/cli/src/dummy.d.ts +0 -0
- package/dist/devtools/cli/src/dummy.js +1 -0
- package/dist/devtools/cli/src/embedded_paths.d.ts +7 -0
- package/dist/devtools/cli/src/embedded_paths.js +85 -0
- package/dist/devtools/cli/src/facade.d.ts +723 -0
- package/dist/devtools/cli/src/facade.js +194 -0
- package/dist/devtools/cli/src/ffmpeg_tool.d.ts +6 -0
- package/dist/devtools/cli/src/ffmpeg_tool.js +146 -0
- package/dist/devtools/cli/src/guide.d.ts +1 -0
- package/dist/devtools/cli/src/guide.js +49 -0
- package/dist/devtools/cli/src/index.d.ts +1 -0
- package/dist/devtools/cli/src/index.js +753 -0
- package/dist/devtools/cli/src/media_assets.d.ts +25 -0
- package/dist/devtools/cli/src/media_assets.js +121 -0
- package/dist/devtools/cli/src/session_manager.d.ts +25 -0
- package/dist/devtools/cli/src/session_manager.js +393 -0
- package/dist/devtools/cli/src/token_tool.d.ts +33 -0
- package/dist/devtools/cli/src/token_tool.js +217 -0
- package/dist/devtools/cli/src/transport.d.ts +30 -0
- package/dist/devtools/cli/src/transport.js +84 -0
- package/dist/dummy.d.ts +0 -0
- package/dist/dummy.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +48 -0
- package/package.json +54 -0
- package/script/ensure_ffmpeg.sh +22 -0
- package/vendor/app-server/bin/native/macos-arm64/credential_napi.node +0 -0
- package/vendor/app-server/bin/native/macos-arm64/libcrypto.dylib +0 -0
- package/vendor/app-server/bin/native/macos-arm64/libssl.dylib +0 -0
- package/vendor/app-server/bin/native/macos-arm64/libtgrtc.dylib +0 -0
- package/vendor/app-server/bin/native/macos-arm64/runtime_host_napi.node +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_codec.h +23 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_frame.h +36 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io.h +56 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io_android.h +19 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io_apple.h +19 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io_harmony.h +19 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io_windows.h +19 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_processing.h +56 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_sample_rate.h +18 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/error.h +20 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/logging.h +53 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/media_codec.h +21 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/media_downlink.h +89 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/media_uplink.h +115 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/runtime.h +236 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_codec.h +57 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_frame.h +55 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io.h +46 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io_android.h +32 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io_apple.h +34 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io_harmony.h +32 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io_windows.h +26 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_processing.h +34 -0
- package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_audio.a +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_facade.a +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_foundation_logging.a +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_media.a +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_video.a +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/lib/libwebrtc_apm.a +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/lib/libxlog.a +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/manifest.txt +34 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio.h +398 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_codec.h +23 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_frame.h +36 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io.h +56 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io_android.h +19 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io_apple.h +19 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io_harmony.h +19 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io_windows.h +19 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_processing.h +56 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_sample_rate.h +18 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/av.h +452 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/credential.h +34 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/error.h +30 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/foundation/build_info.h +27 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/http.h +57 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/logging.h +55 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_codec.h +21 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_downlink.h +95 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_fixture_av_sync.h +61 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_fixture_source.h +77 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_live_source.h +71 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_uplink.h +116 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/transport.h +481 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/trp.h +541 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_codec.h +58 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_frame.h +55 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io.h +46 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io_android.h +32 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io_apple.h +47 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io_harmony.h +32 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io_windows.h +26 -0
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_processing.h +34 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libcrypto.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libcrypto.dylib +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_audio.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_credential.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_facade.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_foundation_http.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_foundation_logging.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_media.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_transport.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_video.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libssl.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libssl.dylib +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libwebrtc_apm.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libxlog.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/manifest.txt +50 -0
- package/vendor/app-server/bin/tirtc-devtool-host.js +2 -0
- package/vendor/app-server/dist/host/ArtifactManager.d.ts +18 -0
- package/vendor/app-server/dist/host/ArtifactManager.js +83 -0
- package/vendor/app-server/dist/host/HostProtocol.d.ts +107 -0
- package/vendor/app-server/dist/host/HostProtocol.js +256 -0
- package/vendor/app-server/dist/host/HostServer.d.ts +49 -0
- package/vendor/app-server/dist/host/HostServer.js +635 -0
- package/vendor/app-server/dist/host/HostState.d.ts +60 -0
- package/vendor/app-server/dist/host/HostState.js +19 -0
- package/vendor/app-server/dist/host/RuntimeAdapter.d.ts +81 -0
- package/vendor/app-server/dist/host/RuntimeAdapter.js +559 -0
- package/vendor/app-server/dist/host/RuntimeCredentialTokenIssuer.d.ts +30 -0
- package/vendor/app-server/dist/host/RuntimeCredentialTokenIssuer.js +224 -0
- package/vendor/app-server/dist/host/RuntimeReceiveWorker.d.ts +37 -0
- package/vendor/app-server/dist/host/RuntimeReceiveWorker.js +186 -0
- package/vendor/app-server/dist/host/RuntimeSendWorker.d.ts +42 -0
- package/vendor/app-server/dist/host/RuntimeSendWorker.js +274 -0
- package/vendor/app-server/dist/host/TokenTool.d.ts +15 -0
- package/vendor/app-server/dist/host/TokenTool.js +84 -0
- package/vendor/app-server/dist/host/WebPreviewGateway.d.ts +28 -0
- package/vendor/app-server/dist/host/WebPreviewGateway.js +815 -0
- package/vendor/app-server/dist/host/native/RuntimeCredentialTokenIssuer.d.ts +26 -0
- package/vendor/app-server/dist/host/native/RuntimeCredentialTokenIssuer.js +118 -0
- package/vendor/app-server/dist/host/native/RuntimeHostBridge.d.ts +19 -0
- package/vendor/app-server/dist/host/native/RuntimeHostBridge.js +141 -0
- package/vendor/app-server/dist/host/runtime_backed_preflight.d.ts +10 -0
- package/vendor/app-server/dist/host/runtime_backed_preflight.js +78 -0
- package/vendor/app-server/dist/host/tests/helpers/host_socket_client.d.ts +28 -0
- package/vendor/app-server/dist/host/tests/helpers/host_socket_client.js +85 -0
- package/vendor/app-server/dist/host/tests/helpers/runtime_e2e_local_config.d.ts +10 -0
- package/vendor/app-server/dist/host/tests/helpers/runtime_e2e_local_config.js +41 -0
- package/vendor/app-server/dist/host/tests/helpers/runtime_test_env.d.ts +11 -0
- package/vendor/app-server/dist/host/tests/helpers/runtime_test_env.js +32 -0
- package/vendor/app-server/dist/protocol/contract.d.ts +983 -0
- package/vendor/app-server/dist/protocol/contract.js +198 -0
- package/vendor/app-server/dist/protocol-client/index.d.ts +25 -0
- package/vendor/app-server/dist/protocol-client/index.js +114 -0
- package/vendor/app-server/dist/src/index.d.ts +1 -0
- package/vendor/app-server/dist/src/index.js +294 -0
- package/vendor/runtime/script/prepare_runtime_media_dataset.sh +427 -0
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# TiRTC DevTool CLI
|
|
2
|
+
|
|
3
|
+
`devtools/cli/` 承接 `TiRTC DevTool CLI`。它是当前唯一用户界面的产品门面 (command client),为用户提供了一套操作 `Matrix Host` 控制面的终端工具。
|
|
4
|
+
|
|
5
|
+
## 使用说明 (C-Lite)
|
|
6
|
+
|
|
7
|
+
关于 `tirtc-devtool` 命令的详细使用方法、参数说明与示例,请参考 [USAGE.md](./USAGE.md)。
|
|
8
|
+
|
|
9
|
+
## 负责什么
|
|
10
|
+
|
|
11
|
+
- **唯一用户产品门面**:提供 `tirtc-devtool` 命令族,覆盖常见的 RTC 测试操作,让内部研发、外部开发者和 AI agent 脚本无需手写底层协议。
|
|
12
|
+
- **配置解析与翻译**:负责解析用户传入的 CLI 参数和 TOML 配置文件,进行本地必填校验、脱敏,并翻译为 App Server 协议的 request。
|
|
13
|
+
- **产品级 Observability**:将底层的运行时事件和状态翻译为结构化输出 (JSON) 或友好的终端日志输出。
|
|
14
|
+
- **调试期工具内聚**:承接调试期必要工具(如 token bootstrap、二维码与媒体预处理)的产品化入口,避免把调试流程散落在 runtime 或外部手工步骤中。
|
|
15
|
+
- **本地 token 工具**:提供直接签发 token、打印组合 JSON、单独 token 与本地二维码 PNG 路径的公开 CLI 能力,服务本地联调与体验验证。
|
|
16
|
+
|
|
17
|
+
## 不负责什么
|
|
18
|
+
|
|
19
|
+
- **不拥有底层 RTC 能力**:它只是一个客户端门面,它自己不负责跑 RTC 媒体栈,所有的执行能力均交由底层的 `Matrix Host` 进程完成。
|
|
20
|
+
- **不重新定义协议**:不私自发明 undocumented control path;CLI 命令到 Host method 的映射必须与协议文档保持一一对应。
|
|
21
|
+
- **不把 App Server 变成业务服务**:鉴权签发等能力仅用于本地联调 bootstrap,不替代正式业务系统。
|
|
22
|
+
|
|
23
|
+
## 依赖方向
|
|
24
|
+
|
|
25
|
+
- **依赖 `app-server/protocol-client/`**:通过可复用的第一方协议客户端与 `Matrix Host` 进程通信。
|
|
26
|
+
- **绝不依赖 `runtime/` 代码实现**:CLI 不直接链接 runtime 模块,只消费 app-server 打包好的运行时产物与 Host 协议。
|
|
27
|
+
|
|
28
|
+
## 这里应该放什么
|
|
29
|
+
|
|
30
|
+
- CLI 命令行入口、命令树 (Commands) 的注册与参数解析逻辑。
|
|
31
|
+
- 配置文件 (TOML) 的读取与校验逻辑。
|
|
32
|
+
- 终端交互、控制台进度打印、结构化输出等 UI 面板逻辑。
|
|
33
|
+
- 与 `protocol-client/` 交互并把业务结果展示给用户的封装逻辑。
|
|
34
|
+
|
|
35
|
+
## 代码规范与 lint
|
|
36
|
+
|
|
37
|
+
- TypeScript 代码规范通过 `eslint` 承接,配置文件位于 `devtools/cli/.eslintrc.cjs`。
|
|
38
|
+
- 本目录作者侧收口命令:`npm run lint`、`npm test`、`npm run build`。
|
|
39
|
+
- 仓库级 gate 会通过 `./script/lint_node_products.sh` 在 `pre-commit` 与 `./script/check.sh` 中统一执行 Node 产品 lint。
|
|
40
|
+
|
|
41
|
+
## 开发与构建
|
|
42
|
+
|
|
43
|
+
- `npm run build`:执行 TypeScript 编译。
|
|
44
|
+
- `npm test`:运行 CLI 门面与 Smoke 测试。
|
|
45
|
+
- `npm run package`:执行 `./script/package.sh`,构建 CLI 本体并同步 npm 发布所需的 app-server/runtime vendor 资产。
|
|
46
|
+
- 运行 `media assets prepare` 时,CLI 会优先复用系统 `ffmpeg/ffprobe`;若本机不存在,则首次使用时自动下载到用户缓存目录。
|
|
47
|
+
|
|
48
|
+
## Runtime E2E Tester Config
|
|
49
|
+
|
|
50
|
+
- 本地测试配置文件路径:`devtools/cli/tests/.local/runtime-backed.e2e.local.json`(必需,已在 `.gitignore` 忽略)。
|
|
51
|
+
- 示例模板:`devtools/cli/tests/runtime-backed.e2e.config.example.json`。
|
|
52
|
+
- 推荐先运行 `tirtc-devtool media assets prepare --source .refers/simple.mp4 --output-root ./.tmp/tirtc-devtool/assets`,再把 `assetsDir` 指向返回的 `assets_dir`。
|
package/USAGE.md
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
# TiRTC DevTool CLI(用户手册)
|
|
2
|
+
|
|
3
|
+
`tirtc-devtool` 是基于 `app-server/host` 的命令行门面,用来控制会话、服务、连接、流、命令通道与调试工具。
|
|
4
|
+
|
|
5
|
+
## 一、先说清楚关系
|
|
6
|
+
|
|
7
|
+
- Runtime:底层内核能力(transport/audio/video/media/facade)。
|
|
8
|
+
- App Server:把 Runtime 组织成稳定控制面协议(Host 进程)。
|
|
9
|
+
- CLI(`devtools/cli`):面向用户的命令行门面,通过协议控制 App Server。
|
|
10
|
+
|
|
11
|
+
也就是说:CLI 不是独立重做一套 RTC 能力,而是消费 App Server;App Server 再消费 Runtime。
|
|
12
|
+
|
|
13
|
+
## 二、如何编译“最新”CLI
|
|
14
|
+
|
|
15
|
+
你提到的重点是对的:不仅要“安装”,还要能拿到**最新源码构建产物**。
|
|
16
|
+
|
|
17
|
+
### 1) 开发态构建(最快)
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm --prefix app-server ci && \
|
|
21
|
+
npm --prefix devtools/cli ci && \
|
|
22
|
+
npm --prefix app-server run build && \
|
|
23
|
+
npm --prefix devtools/cli run build
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
构建后可直接运行:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
node devtools/cli/bin/tirtc-devtool.js --help
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### 2) 发布态打包(可分发二进制)
|
|
33
|
+
|
|
34
|
+
按统一链路执行(先准备 runtime,再打包产品):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
./runtime/script/prepare_product_runtime.sh --platform macos-arm64 --consumer both
|
|
38
|
+
./app-server/script/package.sh
|
|
39
|
+
./devtools/cli/script/package.sh
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
产物位置:
|
|
43
|
+
|
|
44
|
+
- App Server:`app-server/bin/dist/`
|
|
45
|
+
- CLI:`devtools/cli/bin/dist/`
|
|
46
|
+
|
|
47
|
+
### 3) 一键验收(推荐)
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
./script/acceptance_app_server_devtools.sh
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 三、全局参数
|
|
54
|
+
|
|
55
|
+
- `--config <path>`:TOML 配置文件路径。
|
|
56
|
+
- `--json`:结构化 JSON 输出。
|
|
57
|
+
- `--session <sessionId>`:指定会话(除 `service start` / `connection connect` 外必须显式传)。
|
|
58
|
+
|
|
59
|
+
## 四、会话模型
|
|
60
|
+
|
|
61
|
+
一个 session = 一个常驻 Host 进程 + 一个 endpoint runtime 实例。
|
|
62
|
+
|
|
63
|
+
- `tirtc-devtool host session start`:创建会话,返回 `sessionId`
|
|
64
|
+
- `tirtc-devtool host session list`:查看会话
|
|
65
|
+
- `tirtc-devtool host session stop <sessionId>`:停止会话
|
|
66
|
+
|
|
67
|
+
设计约束:
|
|
68
|
+
|
|
69
|
+
- 单机同一时刻只允许一个 `service` 会话;再次 `service start` 会直接失败并提示先停止已有服务会话。
|
|
70
|
+
- `service start`:自动创建一个 session(也可通过 `--session` 绑定已有 session)。
|
|
71
|
+
- `connection connect`:总是创建新的 session(不支持复用已有 session),允许多个 client 会话并行。
|
|
72
|
+
- 除上述两条入口命令外,其他业务命令都必须显式传 `--session <sessionId>`。
|
|
73
|
+
|
|
74
|
+
## 五、命令总览
|
|
75
|
+
|
|
76
|
+
### Config
|
|
77
|
+
|
|
78
|
+
用途:初始化 CLI 配置文件,作为后续 `service/debug/logging` 等命令的参数来源。
|
|
79
|
+
|
|
80
|
+
- `tirtc-devtool init [outputPath]`:生成配置模板;不传路径时默认写入 `./.tmp/tirtc-devtool/config.toml`。
|
|
81
|
+
|
|
82
|
+
### Host
|
|
83
|
+
|
|
84
|
+
用途:管理 Host 进程生命周期与会话健康状态。
|
|
85
|
+
|
|
86
|
+
- `tirtc-devtool host status`:查看当前 Host/service/connection/artifact 状态。
|
|
87
|
+
- `tirtc-devtool host stop`:停止当前 `--session` 对应的 Host 进程。
|
|
88
|
+
- `tirtc-devtool host stop --all`:停止全部 session 对应 Host,并清理本机 orphan host 进程。
|
|
89
|
+
|
|
90
|
+
### Service
|
|
91
|
+
|
|
92
|
+
用途:控制服务端角色(等待远端连接的一侧)。
|
|
93
|
+
|
|
94
|
+
- `tirtc-devtool service start [serviceEntry] [license]`:启动服务并进入等待连接状态。
|
|
95
|
+
- `tirtc-devtool service stop`:停止服务。
|
|
96
|
+
|
|
97
|
+
说明:`license` 必填;`serviceEntry` 可省略,省略时走 runtime/core/transport 默认值。
|
|
98
|
+
|
|
99
|
+
`debug bootstrap qrcode` / `debug bootstrap qrcode-from-config` 默认复用当前唯一活跃 session;多 session 时请显式传 `--session`。
|
|
100
|
+
|
|
101
|
+
### Connection
|
|
102
|
+
|
|
103
|
+
用途:控制客户端侧连接动作(主动连接/断开)。
|
|
104
|
+
|
|
105
|
+
- `tirtc-devtool connection show`:查看当前连接状态。
|
|
106
|
+
- `tirtc-devtool connection connect [serviceEntry] <peerId> [token]`:主动发起连接(不传 token 时自动签发)。
|
|
107
|
+
- `tirtc-devtool connection disconnect`:主动断开连接。
|
|
108
|
+
|
|
109
|
+
说明:`connect` 每次都会新建一个 session;省略 `serviceEntry` 时,Host 回退到 runtime 配置默认值。
|
|
110
|
+
|
|
111
|
+
自动签发补充:
|
|
112
|
+
|
|
113
|
+
- 若命令行和 `[connection].token` 都为空,且 TOML 提供 `[connection.auto_token]` 的 `access_id/secret_key`,CLI 会传 `tokenMode=auto`,由 App Server 在连接前实时签发新 token。
|
|
114
|
+
- `local_id` 可选;缺省时 App Server 侧回退为本次连接使用的 `peer_id`。
|
|
115
|
+
- 若手动 token 与自动签发配置都缺失,命令会失败。
|
|
116
|
+
|
|
117
|
+
### Token
|
|
118
|
+
|
|
119
|
+
用途:直接签发 token,并把调试所需的核心信息一次性输出到控制台,同时在本地生成二维码 PNG。
|
|
120
|
+
|
|
121
|
+
- `tirtc-devtool token issue <accessId> <secretKey> <localId> <peerId>`:签发 token。
|
|
122
|
+
|
|
123
|
+
可选参数:
|
|
124
|
+
|
|
125
|
+
- `--openapi-entry <url>`:覆盖默认 openapi entry。
|
|
126
|
+
- `--service-entry <entry>`:附加到组合 payload,便于扫码后直接连到目标服务。
|
|
127
|
+
- `--user-ttl-seconds <seconds>`:覆盖 user token ttl。
|
|
128
|
+
- `--channel-ttl-seconds <seconds>`:覆盖 channel token ttl。
|
|
129
|
+
|
|
130
|
+
默认输出四部分:
|
|
131
|
+
|
|
132
|
+
- `Issued Token Summary`:面向人类阅读的摘要,快速确认 local/peer/entry/ttl。
|
|
133
|
+
- `Token`:单独罗列 token 字符串,便于复制粘贴。
|
|
134
|
+
- `Payload JSON`:组合 JSON,对方或 Agent 可直接复制使用。
|
|
135
|
+
- `QR Code PNG`:基于组合 JSON 生成的本地 PNG 文件绝对路径。适合人工打开图片后扫码。
|
|
136
|
+
|
|
137
|
+
说明:
|
|
138
|
+
|
|
139
|
+
- 组合 JSON 的 `type` 固定为 `tirtc-connect-token`。
|
|
140
|
+
- PNG 二维码承载的是组合 JSON,不再暴露 `secret_key`。
|
|
141
|
+
- `--json` 模式下会输出 `payload`、`payloadJson`、`token` 和 `qrCodePngPath`。
|
|
142
|
+
|
|
143
|
+
### Stream
|
|
144
|
+
|
|
145
|
+
用途:管理音视频流的发送/接收与远端请求策略。
|
|
146
|
+
|
|
147
|
+
- `tirtc-devtool stream list`:列出当前流状态。
|
|
148
|
+
- `tirtc-devtool media assets prepare --source <mp4> --output-root <dir>`:把 MP4 prepare 为 local assets。
|
|
149
|
+
- `tirtc-devtool stream send start <streamId> <media> <assets_dir>`:启动发送流并绑定 prepared local assets。
|
|
150
|
+
- `tirtc-devtool stream send stop <streamId>`:停止发送流。
|
|
151
|
+
- `tirtc-devtool stream receive start <streamId> <media>`:启动接收流。
|
|
152
|
+
- `tirtc-devtool stream receive stop <streamId>`:停止接收流。
|
|
153
|
+
- `tirtc-devtool stream request-policy get`:查看远端请求策略。
|
|
154
|
+
- `tirtc-devtool stream request-policy set <manual|auto-if-bound>`:设置远端请求策略。
|
|
155
|
+
|
|
156
|
+
`request-policy` 行为:
|
|
157
|
+
|
|
158
|
+
- `manual`:只上报远端请求事件,由上层显式决定是否发流。
|
|
159
|
+
- `auto-if-bound`:如果本地已通过 `stream send start` 绑定 `(streamId, media, assets_dir)`,远端请求到达后自动启动发送。
|
|
160
|
+
|
|
161
|
+
发送链路说明:
|
|
162
|
+
|
|
163
|
+
- `stream/sendStart` 走 runtime-backed 真实发送路径。
|
|
164
|
+
- 实际链路:`prepared local assets -> A/V PTS 对齐 -> 真实 uplink (runtime-backed transport)`。
|
|
165
|
+
- 返回字段中的 `source.local_assets.assets_dir` 可用于验收与排障。
|
|
166
|
+
|
|
167
|
+
### Output
|
|
168
|
+
|
|
169
|
+
用途:把流内容挂到具体消费端(文件、预览页等)。
|
|
170
|
+
|
|
171
|
+
- `tirtc-devtool output attach <streamId> <consumer> <mediaView> <format> <delivery> [targetPath] [maxFiles]`:附加输出消费。
|
|
172
|
+
- `tirtc-devtool output detach <outputId>`:移除输出消费。
|
|
173
|
+
|
|
174
|
+
`output attach` 当前最小稳定组合(CLI 前置校验):
|
|
175
|
+
|
|
176
|
+
- `consumer=web_preview`:`delivery` 必须是 `artifact_path`,`format` 推荐 `jpeg`/`pcm`(兼容旧值 `h264`/`g711a`)。
|
|
177
|
+
- `consumer=file_sink`:`delivery` 必须是 `file`,`format` 必须是 `mp4`。
|
|
178
|
+
|
|
179
|
+
`web_preview` 用法(音视频一起预览):
|
|
180
|
+
|
|
181
|
+
- 先在客户端会话中启动接收(必须两路都起):
|
|
182
|
+
- `tirtc-devtool stream receive start <videoStreamId> video`
|
|
183
|
+
- `tirtc-devtool stream receive start <audioStreamId> audio`
|
|
184
|
+
- 再挂接两路输出到同一个预览页:
|
|
185
|
+
- `tirtc-devtool output attach <videoStreamId> web_preview encoded jpeg artifact_path [videoTargetPath]`
|
|
186
|
+
- `tirtc-devtool output attach <audioStreamId> web_preview encoded pcm artifact_path [audioTargetPath]`
|
|
187
|
+
- 两次 `output attach` 返回的 `result.preview.url` 应一致;用该 URL 在 Chrome 打开本地预览。
|
|
188
|
+
- 页面打开后会自动触发 `GET /preview/start?token=...`;若浏览器拦截自动播放音频,请手动点击 `Start Stream` 解锁。
|
|
189
|
+
- 可通过 `GET /preview/status?token=...` 查看 audio/video source 启动状态与 frame 计数。
|
|
190
|
+
|
|
191
|
+
### Command
|
|
192
|
+
|
|
193
|
+
用途:发送业务命令与实时观察命令事件。
|
|
194
|
+
|
|
195
|
+
- `tirtc-devtool command send <commandId> <kind> <payloadEncoding> <payload>`:发送命令。
|
|
196
|
+
- `tirtc-devtool command send-json <commandId> <kind> <payloadJson>`:以 JSON-first 形态发送命令。
|
|
197
|
+
- `tirtc-devtool command tail`:持续监听命令相关事件。
|
|
198
|
+
|
|
199
|
+
`command send-json` 约束:
|
|
200
|
+
|
|
201
|
+
- `payloadJson` 必须是合法 JSON 文本。
|
|
202
|
+
- CLI 固定按 `payloadEncoding=json` 下发给 Host。
|
|
203
|
+
|
|
204
|
+
### Debug Bootstrap 二维码
|
|
205
|
+
|
|
206
|
+
用途:生成客户端扫码连接所需的 bootstrap 二维码(只包含连接信息,不签发 token)。
|
|
207
|
+
|
|
208
|
+
- `tirtc-devtool debug bootstrap qrcode <accessId> <secretKey> <peerId> [serviceEntry]`:按命令参数生成二维码。
|
|
209
|
+
- `tirtc-devtool debug bootstrap qrcode-from-config`:按 `[debug.connect_bootstrap]` 配置生成二维码。
|
|
210
|
+
|
|
211
|
+
二维码产物会落到 Host artifact 的 `debug/` 目录。
|
|
212
|
+
|
|
213
|
+
### 观测与报告
|
|
214
|
+
|
|
215
|
+
用途:做运行观测与验收证据导出。
|
|
216
|
+
|
|
217
|
+
- `tirtc-devtool events tail`:实时查看事件流。
|
|
218
|
+
- `tirtc-devtool logs export <outputPath>`:导出日志。
|
|
219
|
+
- `tirtc-devtool report show`:查看报告。
|
|
220
|
+
- `tirtc-devtool report export <outputPath>`:导出报告。
|
|
221
|
+
|
|
222
|
+
## 六、服务端操作指引(对接安卓扫码)
|
|
223
|
+
|
|
224
|
+
目标:只操作 CLI 服务端,启动后自动待推流;安卓端扫码拿到 bootstrap 信息,自行签发 token 后连接并观看音视频。
|
|
225
|
+
|
|
226
|
+
### 1) 启动服务端
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
node devtools/cli/bin/tirtc-devtool.js service start "" "runtime-license"
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
记下返回里的 `sessionId`。
|
|
233
|
+
|
|
234
|
+
### 2) 让服务端进入“自动按需发流”
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
编辑 `--config` 指向的 TOML:
|
|
238
|
+
[stream.request_policy]
|
|
239
|
+
mode = "auto-if-bound"
|
|
240
|
+
|
|
241
|
+
[streams.send]
|
|
242
|
+
assets_dir = "./.tmp/tirtc-devtool/assets/<prepared-assets-id>"
|
|
243
|
+
audio_stream_id = 10
|
|
244
|
+
video_stream_id = 11
|
|
245
|
+
|
|
246
|
+
再执行 service start(CLI 会自动应用 request_policy + send 绑定)。
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
说明:
|
|
250
|
+
- `auto-if-bound` 表示远端请求到达后,若本地已配置并应用发送绑定,服务端会自动开始对应发送。
|
|
251
|
+
- `[streams.send]` 只配置一次 prepared assets 目录;音视频都从同一个 local assets 输入读取。
|
|
252
|
+
- `audio_stream_id` 与 `video_stream_id` 必须与客户端请求的 stream id 一致。
|
|
253
|
+
|
|
254
|
+
### 3) 生成给安卓扫码的 bootstrap 二维码
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
node devtools/cli/bin/tirtc-devtool.js --session <SESSION_ID> debug bootstrap qrcode \
|
|
258
|
+
"<access-id>" "<secret-key>" "<peer-id>" "<service-entry>"
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
命令会在 Host artifact 的 `debug/` 目录下生成:
|
|
262
|
+
- `*.qr.png`(扫码图)
|
|
263
|
+
|
|
264
|
+
### 4) 安卓端扫码后的预期流程(安卓实现不在本仓库)
|
|
265
|
+
|
|
266
|
+
- 安卓扫描二维码,解析出 bootstrap JSON。
|
|
267
|
+
- 使用 `access_id + secret_key` 在客户端侧(或你们外部签发服务)签发连接 token。
|
|
268
|
+
- 使用签发后的 token + `peer_id`(必要时加 `service_entry`)建立连接。
|
|
269
|
+
- 连接成功后请求接收对应流(例如 `10/video`、`11/audio`),即可看到服务端已绑定的媒体内容。
|
|
270
|
+
|
|
271
|
+
### 4.1) 本地直接签发 token(公开调试入口)
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
node devtools/cli/bin/tirtc-devtool.js token issue \
|
|
275
|
+
"<access-id>" "<secret-key>" "<local-id>" "<peer-id>" \
|
|
276
|
+
--service-entry "<service-entry>"
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
输出包含:
|
|
280
|
+
|
|
281
|
+
- 一份可直接复制的组合 JSON
|
|
282
|
+
- 单独的 token 字符串
|
|
283
|
+
- 同一份组合 JSON 对应的本地二维码 PNG 路径
|
|
284
|
+
|
|
285
|
+
二维码内容示例:
|
|
286
|
+
|
|
287
|
+
```json
|
|
288
|
+
{
|
|
289
|
+
"version": 1,
|
|
290
|
+
"type": "tirtc-connect-token",
|
|
291
|
+
"peer_id": "<peer-id>",
|
|
292
|
+
"local_id": "<local-id>",
|
|
293
|
+
"service_entry": "<service-entry>",
|
|
294
|
+
"token": "<issued-token>",
|
|
295
|
+
"openapi_entry": "http://api-test-tirtc.tange365.com",
|
|
296
|
+
"user_ttl_seconds": 86400,
|
|
297
|
+
"channel_ttl_seconds": 300,
|
|
298
|
+
"generated_at": "<iso8601>"
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### 5) Web Preview 手动控制(建议验收路径)
|
|
303
|
+
|
|
304
|
+
- 在客户端会话 attach 两路 `web_preview` 后,打开返回的 `preview.url`。
|
|
305
|
+
- 页面默认只建立事件连接,不会自动起流。
|
|
306
|
+
- 点击 `Start Stream`:触发服务端开始推送音视频。
|
|
307
|
+
- 点击 `Stop Stream`:触发服务端停止推送。
|
|
308
|
+
- 关闭页面:会自动触发一次 stop 请求(作为兜底)。
|
|
309
|
+
|
|
310
|
+
## 六点四、二维码内容协议(安卓对齐)
|
|
311
|
+
|
|
312
|
+
`debug bootstrap qrcode*` 生成的 payload 是一个 JSON 字符串,字段如下:
|
|
313
|
+
|
|
314
|
+
```json
|
|
315
|
+
{
|
|
316
|
+
"version": 1,
|
|
317
|
+
"type": "tirtc-connect-bootstrap",
|
|
318
|
+
"access_id": "<access-id>",
|
|
319
|
+
"secret_key": "<secret-key>",
|
|
320
|
+
"peer_id": "<peer-id>",
|
|
321
|
+
"service_entry": "<service-entry>"
|
|
322
|
+
}
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
字段约束:
|
|
326
|
+
- `version`: 固定 `1`。
|
|
327
|
+
- `type`: 固定 `tirtc-connect-bootstrap`。
|
|
328
|
+
- `access_id`: 客户端签发 token 所需。
|
|
329
|
+
- `secret_key`: 客户端签发 token 所需。
|
|
330
|
+
- `peer_id`: 目标服务端 peer 标识。
|
|
331
|
+
- `service_entry`: 可选;为空或缺失时,客户端按自身默认 entry 策略处理。
|
|
332
|
+
|
|
333
|
+
注意:
|
|
334
|
+
- 该二维码不包含 token,也不在 App Server 侧签发 token。
|
|
335
|
+
- token 签发职责在客户端或外部系统。
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
## 六点五、日志配置与实时观测
|
|
339
|
+
|
|
340
|
+
`[logging]` 段默认已在模板里生成:
|
|
341
|
+
|
|
342
|
+
- `root_dir`:会话日志根目录(默认 `./.tmp/tirtc-devtool/logging`)
|
|
343
|
+
- `console_mirror`:是否把 Host 关键日志镜像到当前命令终端
|
|
344
|
+
- `level`:日志级别预留位(当前 Host 以统一关键路径日志为主)
|
|
345
|
+
|
|
346
|
+
日志目录结构:
|
|
347
|
+
|
|
348
|
+
- `<root_dir>/<session_id>/host.process.log`(Host 进程 stdio)
|
|
349
|
+
- `<root_dir>/<session_id>/runtime.host.log`(Host 侧结构化运行日志)
|
|
350
|
+
- `<root_dir>/<session_id>/uplink/*.transport-uplink.log`(发送 worker 日志)
|
|
351
|
+
|
|
352
|
+
实时观察:
|
|
353
|
+
|
|
354
|
+
- `node devtools/cli/bin/tirtc-devtool.js --session <SESSION_ID> events tail`
|
|
355
|
+
- 输出中包含 `family=logs` / `kind=host.line` 的实时日志事件
|
|
356
|
+
|
|
357
|
+
## 六点六、配置格式说明
|
|
358
|
+
|
|
359
|
+
- 推荐使用 TOML(支持注释,便于人工维护)
|
|
360
|
+
- `init` 默认生成 TOML 模板:`.tmp/tirtc-devtool/config.toml`
|
|
361
|
+
|
|
362
|
+
## 七、本地 E2E 配置(必需)
|
|
363
|
+
|
|
364
|
+
创建本地测试配置(已被 git ignore):
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
mkdir -p devtools/cli/tests/.local
|
|
368
|
+
cp devtools/cli/tests/runtime-backed.e2e.config.example.json devtools/cli/tests/.local/runtime-backed.e2e.local.json
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
推荐输入(客户端自行签发 token):
|
|
372
|
+
|
|
373
|
+
```json
|
|
374
|
+
{
|
|
375
|
+
"assetsDir": "./.tmp/tirtc-devtool/assets/<prepared-assets-id>",
|
|
376
|
+
"license": "<license>",
|
|
377
|
+
"peerId": "<peer-id>",
|
|
378
|
+
"useFakeToken": false,
|
|
379
|
+
"accessId": "<access-id>",
|
|
380
|
+
"secretKey": "<secret-key>",
|
|
381
|
+
"e2eToken": "<externally-issued-token>"
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
说明:
|
|
386
|
+
- `useFakeToken=true` 时会走本地 fake token(不依赖 token 签发服务)。
|
|
387
|
+
- `useFakeToken=false` 时必须提供外部签发 token(优先 `e2eToken`,否则读取环境变量 `TIRTC_E2E_TOKEN`)。
|
|
388
|
+
- `debug bootstrap qrcode*` 仅生成客户端连接信息二维码(`access_id` / `secret_key` / `peer_id` / 可选 `service_entry`),不负责签发 token。
|
|
389
|
+
|
|
390
|
+
## 八、FFmpeg 说明
|
|
391
|
+
|
|
392
|
+
- FFmpeg 不入库(不纳入 git 版本管理)。
|
|
393
|
+
- 打包时自动准备并放入:
|
|
394
|
+
- `devtools/cli/bin/tools/<platform>/`
|
|
395
|
+
- `devtools/cli/bin/dist/tools/<platform>/`
|
|
396
|
+
|
|
397
|
+
## 九、新手入口
|
|
398
|
+
|
|
399
|
+
- `node devtools/cli/bin/tirtc-devtool.js guide quickstart`
|
|
400
|
+
|
|
401
|
+
会直接打印“服务端启动 -> 绑定自动发流 -> 生成 bootstrap 二维码 -> 客户端扫码签发 token 并连接 -> 打开 Web Preview 后手动 Start/Stop -> 观测报告”的最小闭环步骤。
|
|
402
|
+
|
|
403
|
+
## 十、常用验收命令
|
|
404
|
+
|
|
405
|
+
- App Server:`./app-server/script/test.sh acceptance`
|
|
406
|
+
- CLI:`./devtools/cli/script/test.sh acceptance`
|
|
407
|
+
- 联合一键:`./script/acceptance_app_server_devtools.sh`
|
|
408
|
+
|
|
409
|
+
## 十一、退出码
|
|
410
|
+
|
|
411
|
+
- `0`:成功
|
|
412
|
+
- `1`:内部错误
|
|
413
|
+
- `2`:协议版本不匹配
|
|
414
|
+
- `3`:未初始化
|
|
415
|
+
- `4`:请求/参数错误
|
|
416
|
+
- `7`:连接失败
|
|
417
|
+
- `8`:流不存在
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
export interface Transport {
|
|
3
|
+
send(data: string): void;
|
|
4
|
+
onMessage(handler: (data: string) => void): void;
|
|
5
|
+
onClose(handler: () => void): void;
|
|
6
|
+
onError(handler: (error: Error) => void): void;
|
|
7
|
+
}
|
|
8
|
+
export declare class AppServerClient extends EventEmitter {
|
|
9
|
+
private transport;
|
|
10
|
+
private pendingRequests;
|
|
11
|
+
initialized: boolean;
|
|
12
|
+
private buffer;
|
|
13
|
+
constructor(transport: Transport);
|
|
14
|
+
private rejectAllPending;
|
|
15
|
+
private handleData;
|
|
16
|
+
private handleMessage;
|
|
17
|
+
sendRequest(method: string, params?: unknown, timeoutMs?: number): Promise<unknown>;
|
|
18
|
+
sendNotification(method: string, params?: unknown): void;
|
|
19
|
+
initialize(clientInfo: {
|
|
20
|
+
name: string;
|
|
21
|
+
version: string;
|
|
22
|
+
title?: string;
|
|
23
|
+
}, capabilities?: unknown): Promise<unknown>;
|
|
24
|
+
subscribeEvents(families: string[]): Promise<unknown>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppServerClient = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
class AppServerClient extends events_1.EventEmitter {
|
|
7
|
+
transport;
|
|
8
|
+
pendingRequests;
|
|
9
|
+
initialized = false;
|
|
10
|
+
buffer = '';
|
|
11
|
+
constructor(transport) {
|
|
12
|
+
super();
|
|
13
|
+
this.transport = transport;
|
|
14
|
+
this.pendingRequests = new Map();
|
|
15
|
+
this.transport.onMessage((data) => this.handleData(data));
|
|
16
|
+
this.transport.onError((error) => {
|
|
17
|
+
this.emit('error', error);
|
|
18
|
+
this.rejectAllPending(error);
|
|
19
|
+
});
|
|
20
|
+
this.transport.onClose(() => {
|
|
21
|
+
const error = new Error('transport closed');
|
|
22
|
+
this.emit('close');
|
|
23
|
+
this.rejectAllPending(error);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
rejectAllPending(error) {
|
|
27
|
+
for (const [id, req] of this.pendingRequests.entries()) {
|
|
28
|
+
this.pendingRequests.delete(id);
|
|
29
|
+
if (req.timeoutTimer) {
|
|
30
|
+
clearTimeout(req.timeoutTimer);
|
|
31
|
+
}
|
|
32
|
+
req.reject(error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
handleData(chunk) {
|
|
36
|
+
this.buffer += chunk;
|
|
37
|
+
const lines = this.buffer.split('\n');
|
|
38
|
+
this.buffer = lines.pop() || '';
|
|
39
|
+
for (const line of lines) {
|
|
40
|
+
if (!line.trim()) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const msg = JSON.parse(line);
|
|
45
|
+
this.handleMessage(msg);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
this.emit('error', new Error(`Failed to parse message: ${line}`));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
handleMessage(msg) {
|
|
53
|
+
if (msg.id !== undefined && (msg.result !== undefined || msg.error !== undefined)) {
|
|
54
|
+
const req = this.pendingRequests.get(msg.id);
|
|
55
|
+
if (req) {
|
|
56
|
+
this.pendingRequests.delete(msg.id);
|
|
57
|
+
if (req.timeoutTimer) {
|
|
58
|
+
clearTimeout(req.timeoutTimer);
|
|
59
|
+
}
|
|
60
|
+
if (msg.error !== undefined) {
|
|
61
|
+
req.reject(msg.error);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
req.resolve(msg.result);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (msg.method !== undefined && msg.id === undefined) {
|
|
70
|
+
this.emit('notification', msg.method, msg.params);
|
|
71
|
+
if (msg.method === 'events/event') {
|
|
72
|
+
this.emit('event', msg.params);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async sendRequest(method, params, timeoutMs = 30_000) {
|
|
77
|
+
const id = (0, crypto_1.randomUUID)();
|
|
78
|
+
return await new Promise((resolve, reject) => {
|
|
79
|
+
const pending = { resolve, reject };
|
|
80
|
+
pending.timeoutTimer = setTimeout(() => {
|
|
81
|
+
this.pendingRequests.delete(id);
|
|
82
|
+
reject(new Error(`request timeout after ${timeoutMs}ms: ${method}`));
|
|
83
|
+
}, timeoutMs);
|
|
84
|
+
this.pendingRequests.set(id, pending);
|
|
85
|
+
const payload = JSON.stringify({
|
|
86
|
+
id,
|
|
87
|
+
method,
|
|
88
|
+
params,
|
|
89
|
+
});
|
|
90
|
+
this.transport.send(`${payload}\n`);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
sendNotification(method, params) {
|
|
94
|
+
const payload = JSON.stringify({
|
|
95
|
+
method,
|
|
96
|
+
params
|
|
97
|
+
});
|
|
98
|
+
this.transport.send(`${payload}\n`);
|
|
99
|
+
}
|
|
100
|
+
async initialize(clientInfo, capabilities) {
|
|
101
|
+
const result = await this.sendRequest('initialize', {
|
|
102
|
+
protocolVersion: '1.0.0',
|
|
103
|
+
clientInfo,
|
|
104
|
+
capabilities
|
|
105
|
+
});
|
|
106
|
+
this.sendNotification('initialized');
|
|
107
|
+
this.initialized = true;
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
async subscribeEvents(families) {
|
|
111
|
+
return await this.sendRequest('events/subscribe', { families });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.AppServerClient = AppServerClient;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export type CliConfig = {
|
|
2
|
+
service?: {
|
|
3
|
+
service_entry?: string;
|
|
4
|
+
license?: string;
|
|
5
|
+
};
|
|
6
|
+
connection?: {
|
|
7
|
+
service_entry?: string;
|
|
8
|
+
peer_id?: string;
|
|
9
|
+
token?: string;
|
|
10
|
+
auto_token?: {
|
|
11
|
+
openapi_entry?: string;
|
|
12
|
+
access_id?: string;
|
|
13
|
+
secret_key?: string;
|
|
14
|
+
local_id?: string;
|
|
15
|
+
user_ttl_seconds?: number;
|
|
16
|
+
channel_ttl_seconds?: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
stream?: {
|
|
20
|
+
request_policy?: {
|
|
21
|
+
mode?: 'manual' | 'auto-if-bound';
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
streams?: {
|
|
25
|
+
send?: {
|
|
26
|
+
assets_dir?: string;
|
|
27
|
+
audio_stream_id?: number;
|
|
28
|
+
video_stream_id?: number;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
logging?: {
|
|
32
|
+
root_dir?: string;
|
|
33
|
+
console_mirror?: boolean;
|
|
34
|
+
level?: 'verbose' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
35
|
+
};
|
|
36
|
+
debug?: {
|
|
37
|
+
connect_bootstrap?: {
|
|
38
|
+
access_id?: string;
|
|
39
|
+
secret_key?: string;
|
|
40
|
+
peer_id?: string;
|
|
41
|
+
service_entry?: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export declare function loadConfig(configPath?: string): CliConfig;
|
|
46
|
+
export declare function writeConfigTemplate(outputPath?: string): string;
|