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.
Files changed (156) hide show
  1. package/README.md +52 -0
  2. package/USAGE.md +417 -0
  3. package/bin/tirtc-devtool.js +2 -0
  4. package/dist/app-server/protocol-client/index.d.ts +25 -0
  5. package/dist/app-server/protocol-client/index.js +114 -0
  6. package/dist/devtools/cli/src/config.d.ts +46 -0
  7. package/dist/devtools/cli/src/config.js +98 -0
  8. package/dist/devtools/cli/src/dummy.d.ts +0 -0
  9. package/dist/devtools/cli/src/dummy.js +1 -0
  10. package/dist/devtools/cli/src/embedded_paths.d.ts +7 -0
  11. package/dist/devtools/cli/src/embedded_paths.js +85 -0
  12. package/dist/devtools/cli/src/facade.d.ts +723 -0
  13. package/dist/devtools/cli/src/facade.js +194 -0
  14. package/dist/devtools/cli/src/ffmpeg_tool.d.ts +6 -0
  15. package/dist/devtools/cli/src/ffmpeg_tool.js +146 -0
  16. package/dist/devtools/cli/src/guide.d.ts +1 -0
  17. package/dist/devtools/cli/src/guide.js +49 -0
  18. package/dist/devtools/cli/src/index.d.ts +1 -0
  19. package/dist/devtools/cli/src/index.js +753 -0
  20. package/dist/devtools/cli/src/media_assets.d.ts +25 -0
  21. package/dist/devtools/cli/src/media_assets.js +121 -0
  22. package/dist/devtools/cli/src/session_manager.d.ts +25 -0
  23. package/dist/devtools/cli/src/session_manager.js +393 -0
  24. package/dist/devtools/cli/src/token_tool.d.ts +33 -0
  25. package/dist/devtools/cli/src/token_tool.js +217 -0
  26. package/dist/devtools/cli/src/transport.d.ts +30 -0
  27. package/dist/devtools/cli/src/transport.js +84 -0
  28. package/dist/dummy.d.ts +0 -0
  29. package/dist/dummy.js +1 -0
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.js +48 -0
  32. package/package.json +54 -0
  33. package/script/ensure_ffmpeg.sh +22 -0
  34. package/vendor/app-server/bin/native/macos-arm64/credential_napi.node +0 -0
  35. package/vendor/app-server/bin/native/macos-arm64/libcrypto.dylib +0 -0
  36. package/vendor/app-server/bin/native/macos-arm64/libssl.dylib +0 -0
  37. package/vendor/app-server/bin/native/macos-arm64/libtgrtc.dylib +0 -0
  38. package/vendor/app-server/bin/native/macos-arm64/runtime_host_napi.node +0 -0
  39. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_codec.h +23 -0
  40. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_frame.h +36 -0
  41. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io.h +56 -0
  42. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io_android.h +19 -0
  43. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io_apple.h +19 -0
  44. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io_harmony.h +19 -0
  45. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io_windows.h +19 -0
  46. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_processing.h +56 -0
  47. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_sample_rate.h +18 -0
  48. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/error.h +20 -0
  49. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/logging.h +53 -0
  50. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/media_codec.h +21 -0
  51. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/media_downlink.h +89 -0
  52. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/media_uplink.h +115 -0
  53. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/runtime.h +236 -0
  54. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_codec.h +57 -0
  55. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_frame.h +55 -0
  56. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io.h +46 -0
  57. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io_android.h +32 -0
  58. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io_apple.h +34 -0
  59. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io_harmony.h +32 -0
  60. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io_windows.h +26 -0
  61. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_processing.h +34 -0
  62. package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_audio.a +0 -0
  63. package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_facade.a +0 -0
  64. package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_foundation_logging.a +0 -0
  65. package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_media.a +0 -0
  66. package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_video.a +0 -0
  67. package/vendor/app-server/bin/runtime/linux-x64/lib/libwebrtc_apm.a +0 -0
  68. package/vendor/app-server/bin/runtime/linux-x64/lib/libxlog.a +0 -0
  69. package/vendor/app-server/bin/runtime/linux-x64/manifest.txt +34 -0
  70. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio.h +398 -0
  71. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_codec.h +23 -0
  72. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_frame.h +36 -0
  73. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io.h +56 -0
  74. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io_android.h +19 -0
  75. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io_apple.h +19 -0
  76. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io_harmony.h +19 -0
  77. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io_windows.h +19 -0
  78. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_processing.h +56 -0
  79. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_sample_rate.h +18 -0
  80. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/av.h +452 -0
  81. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/credential.h +34 -0
  82. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/error.h +30 -0
  83. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/foundation/build_info.h +27 -0
  84. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/http.h +57 -0
  85. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/logging.h +55 -0
  86. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_codec.h +21 -0
  87. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_downlink.h +95 -0
  88. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_fixture_av_sync.h +61 -0
  89. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_fixture_source.h +77 -0
  90. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_live_source.h +71 -0
  91. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_uplink.h +116 -0
  92. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/transport.h +481 -0
  93. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/trp.h +541 -0
  94. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_codec.h +58 -0
  95. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_frame.h +55 -0
  96. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io.h +46 -0
  97. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io_android.h +32 -0
  98. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io_apple.h +47 -0
  99. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io_harmony.h +32 -0
  100. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io_windows.h +26 -0
  101. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_processing.h +34 -0
  102. package/vendor/app-server/bin/runtime/macos-arm64/lib/libcrypto.a +0 -0
  103. package/vendor/app-server/bin/runtime/macos-arm64/lib/libcrypto.dylib +0 -0
  104. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_audio.a +0 -0
  105. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_credential.a +0 -0
  106. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_facade.a +0 -0
  107. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_foundation_http.a +0 -0
  108. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_foundation_logging.a +0 -0
  109. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_media.a +0 -0
  110. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_transport.a +0 -0
  111. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_video.a +0 -0
  112. package/vendor/app-server/bin/runtime/macos-arm64/lib/libssl.a +0 -0
  113. package/vendor/app-server/bin/runtime/macos-arm64/lib/libssl.dylib +0 -0
  114. package/vendor/app-server/bin/runtime/macos-arm64/lib/libwebrtc_apm.a +0 -0
  115. package/vendor/app-server/bin/runtime/macos-arm64/lib/libxlog.a +0 -0
  116. package/vendor/app-server/bin/runtime/macos-arm64/manifest.txt +50 -0
  117. package/vendor/app-server/bin/tirtc-devtool-host.js +2 -0
  118. package/vendor/app-server/dist/host/ArtifactManager.d.ts +18 -0
  119. package/vendor/app-server/dist/host/ArtifactManager.js +83 -0
  120. package/vendor/app-server/dist/host/HostProtocol.d.ts +107 -0
  121. package/vendor/app-server/dist/host/HostProtocol.js +256 -0
  122. package/vendor/app-server/dist/host/HostServer.d.ts +49 -0
  123. package/vendor/app-server/dist/host/HostServer.js +635 -0
  124. package/vendor/app-server/dist/host/HostState.d.ts +60 -0
  125. package/vendor/app-server/dist/host/HostState.js +19 -0
  126. package/vendor/app-server/dist/host/RuntimeAdapter.d.ts +81 -0
  127. package/vendor/app-server/dist/host/RuntimeAdapter.js +559 -0
  128. package/vendor/app-server/dist/host/RuntimeCredentialTokenIssuer.d.ts +30 -0
  129. package/vendor/app-server/dist/host/RuntimeCredentialTokenIssuer.js +224 -0
  130. package/vendor/app-server/dist/host/RuntimeReceiveWorker.d.ts +37 -0
  131. package/vendor/app-server/dist/host/RuntimeReceiveWorker.js +186 -0
  132. package/vendor/app-server/dist/host/RuntimeSendWorker.d.ts +42 -0
  133. package/vendor/app-server/dist/host/RuntimeSendWorker.js +274 -0
  134. package/vendor/app-server/dist/host/TokenTool.d.ts +15 -0
  135. package/vendor/app-server/dist/host/TokenTool.js +84 -0
  136. package/vendor/app-server/dist/host/WebPreviewGateway.d.ts +28 -0
  137. package/vendor/app-server/dist/host/WebPreviewGateway.js +815 -0
  138. package/vendor/app-server/dist/host/native/RuntimeCredentialTokenIssuer.d.ts +26 -0
  139. package/vendor/app-server/dist/host/native/RuntimeCredentialTokenIssuer.js +118 -0
  140. package/vendor/app-server/dist/host/native/RuntimeHostBridge.d.ts +19 -0
  141. package/vendor/app-server/dist/host/native/RuntimeHostBridge.js +141 -0
  142. package/vendor/app-server/dist/host/runtime_backed_preflight.d.ts +10 -0
  143. package/vendor/app-server/dist/host/runtime_backed_preflight.js +78 -0
  144. package/vendor/app-server/dist/host/tests/helpers/host_socket_client.d.ts +28 -0
  145. package/vendor/app-server/dist/host/tests/helpers/host_socket_client.js +85 -0
  146. package/vendor/app-server/dist/host/tests/helpers/runtime_e2e_local_config.d.ts +10 -0
  147. package/vendor/app-server/dist/host/tests/helpers/runtime_e2e_local_config.js +41 -0
  148. package/vendor/app-server/dist/host/tests/helpers/runtime_test_env.d.ts +11 -0
  149. package/vendor/app-server/dist/host/tests/helpers/runtime_test_env.js +32 -0
  150. package/vendor/app-server/dist/protocol/contract.d.ts +983 -0
  151. package/vendor/app-server/dist/protocol/contract.js +198 -0
  152. package/vendor/app-server/dist/protocol-client/index.d.ts +25 -0
  153. package/vendor/app-server/dist/protocol-client/index.js +114 -0
  154. package/vendor/app-server/dist/src/index.d.ts +1 -0
  155. package/vendor/app-server/dist/src/index.js +294 -0
  156. package/vendor/runtime/script/prepare_runtime_media_dataset.sh +427 -0
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.issueToken = issueToken;
7
+ exports.buildIssuedTokenPayload = buildIssuedTokenPayload;
8
+ exports.writePngQrcode = writePngQrcode;
9
+ exports.issueTokenWithQrcode = issueTokenWithQrcode;
10
+ exports.formatTokenIssueConsoleOutput = formatTokenIssueConsoleOutput;
11
+ const module_1 = require("module");
12
+ const fs_1 = __importDefault(require("fs"));
13
+ const path_1 = __importDefault(require("path"));
14
+ const qrcode_1 = __importDefault(require("qrcode"));
15
+ const embedded_paths_1 = require("./embedded_paths");
16
+ const runtimeRequire = (0, module_1.createRequire)(__filename);
17
+ const kDefaultOpenapiEntry = 'http://api-test-tirtc.tange365.com';
18
+ const kDefaultUserTtlSeconds = 86400;
19
+ const kDefaultChannelTtlSeconds = 300;
20
+ function pathExists(filePath) {
21
+ return fs_1.default.existsSync(filePath);
22
+ }
23
+ function ensureDirectory(dirPath) {
24
+ fs_1.default.mkdirSync(dirPath, { recursive: true });
25
+ }
26
+ function sanitizePathSegment(text) {
27
+ return text.replace(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-+|-+$/g, '') || 'value';
28
+ }
29
+ function resolveQrCodeOutputDir() {
30
+ return path_1.default.resolve(process.cwd(), '.tmp/tirtc-devtool/qrcode');
31
+ }
32
+ function buildQrCodePngPath(payload) {
33
+ const fileName = [
34
+ 'token',
35
+ sanitizePathSegment(payload.local_id),
36
+ sanitizePathSegment(payload.peer_id),
37
+ Date.now().toString(),
38
+ ].join('-') + '.png';
39
+ return path_1.default.join(resolveQrCodeOutputDir(), fileName);
40
+ }
41
+ function resolveRuntimePlatform() {
42
+ const raw = process.env.TIRTC_RUNTIME_PLATFORM;
43
+ if (raw && raw.trim().length > 0) {
44
+ return raw.trim();
45
+ }
46
+ if (process.platform === 'darwin' && process.arch === 'arm64') {
47
+ return 'macos-arm64';
48
+ }
49
+ return 'linux-x64';
50
+ }
51
+ function resolveRuntimeBundleRoot(runtimePlatform) {
52
+ const explicit = process.env.TIRTC_RUNTIME_BUNDLE_ROOT;
53
+ if (explicit && explicit.trim().length > 0) {
54
+ return explicit.trim();
55
+ }
56
+ const embedded = (0, embedded_paths_1.resolveEmbeddedRuntimeBundleRoot)(__dirname, runtimePlatform);
57
+ if (embedded) {
58
+ return embedded;
59
+ }
60
+ const execDir = path_1.default.dirname(process.execPath);
61
+ const candidates = [
62
+ path_1.default.resolve(execDir, 'runtime', runtimePlatform),
63
+ path_1.default.resolve(execDir, '../runtime', runtimePlatform),
64
+ path_1.default.resolve(__dirname, '../bin/runtime', runtimePlatform),
65
+ path_1.default.resolve(__dirname, '../../../../bin/runtime', runtimePlatform),
66
+ path_1.default.resolve(process.cwd(), 'devtools/cli/bin/runtime', runtimePlatform),
67
+ path_1.default.resolve(process.cwd(), 'bin/runtime', runtimePlatform),
68
+ path_1.default.resolve(process.cwd(), '../bin/runtime', runtimePlatform),
69
+ ];
70
+ for (const candidate of candidates) {
71
+ if (pathExists(path_1.default.join(candidate, 'manifest.txt'))) {
72
+ return candidate;
73
+ }
74
+ }
75
+ return candidates[0];
76
+ }
77
+ function resolveRepoRoot() {
78
+ const embeddedAppServerRoot = (0, embedded_paths_1.resolveEmbeddedAppServerRoot)(__dirname);
79
+ if (embeddedAppServerRoot) {
80
+ return path_1.default.resolve(embeddedAppServerRoot, '..');
81
+ }
82
+ const candidates = [
83
+ path_1.default.resolve(__dirname, '../../../../../../'),
84
+ path_1.default.resolve(__dirname, '../../../../../'),
85
+ path_1.default.resolve(__dirname, '../../../..'),
86
+ path_1.default.resolve(process.cwd()),
87
+ ];
88
+ for (const candidate of candidates) {
89
+ if (pathExists(path_1.default.join(candidate, 'app-server')) && pathExists(path_1.default.join(candidate, 'devtools'))) {
90
+ return candidate;
91
+ }
92
+ }
93
+ return candidates[0];
94
+ }
95
+ function ensureRuntimeBundleReady(runtimeBundleRoot) {
96
+ const includeDir = path_1.default.join(runtimeBundleRoot, 'include');
97
+ const libDir = path_1.default.join(runtimeBundleRoot, 'lib');
98
+ if (!pathExists(includeDir) || !pathExists(libDir)) {
99
+ throw new Error('runtime-backed sdk bundle is missing: ' + runtimeBundleRoot);
100
+ }
101
+ }
102
+ function resolveAddonPath(repoRoot, runtimePlatform) {
103
+ const explicit = process.env.TIRTC_CREDENTIAL_ADDON_PATH;
104
+ const candidates = [
105
+ explicit,
106
+ path_1.default.join(repoRoot, `app-server/bin/native/${runtimePlatform}/credential_napi.node`),
107
+ path_1.default.join(repoRoot, `app-server/.build/app-server/native/${runtimePlatform}/credential_napi.node`),
108
+ path_1.default.resolve(process.cwd(), `app-server/bin/native/${runtimePlatform}/credential_napi.node`),
109
+ path_1.default.resolve(process.cwd(), `.build/app-server/native/${runtimePlatform}/credential_napi.node`),
110
+ ].filter((entry) => typeof entry === 'string' && entry.trim().length > 0);
111
+ for (const candidate of candidates) {
112
+ const normalized = path_1.default.resolve(candidate);
113
+ if (pathExists(normalized)) {
114
+ return normalized;
115
+ }
116
+ }
117
+ throw new Error('credential addon missing for platform ' + runtimePlatform +
118
+ '; run: npm --prefix app-server run build:native');
119
+ }
120
+ function loadCredentialBinding() {
121
+ const runtimePlatform = resolveRuntimePlatform();
122
+ const runtimeBundleRoot = resolveRuntimeBundleRoot(runtimePlatform);
123
+ const repoRoot = resolveRepoRoot();
124
+ ensureRuntimeBundleReady(runtimeBundleRoot);
125
+ const addonPath = resolveAddonPath(repoRoot, runtimePlatform);
126
+ const loaded = runtimeRequire(addonPath);
127
+ if (!loaded || typeof loaded.issueToken !== 'function') {
128
+ throw new Error('credential addon missing issueToken() export: ' + addonPath);
129
+ }
130
+ return loaded;
131
+ }
132
+ function normalizeIssuedToken(token) {
133
+ const normalized = token.trim();
134
+ if (normalized.length === 0) {
135
+ throw new Error('issue token failed: empty token');
136
+ }
137
+ return normalized;
138
+ }
139
+ async function issueToken(input) {
140
+ const binding = loadCredentialBinding();
141
+ let token;
142
+ try {
143
+ token = binding.issueToken({
144
+ openapiEntry: input.openapiEntry,
145
+ accessId: input.accessId,
146
+ secretKey: input.secretKey,
147
+ localId: input.localId,
148
+ peerId: input.peerId,
149
+ userTtlSeconds: input.userTtlSeconds,
150
+ channelTtlSeconds: input.channelTtlSeconds,
151
+ });
152
+ }
153
+ catch (error) {
154
+ const message = error instanceof Error ? error.message : String(error);
155
+ throw new Error('issue token failed: ' + message);
156
+ }
157
+ return normalizeIssuedToken(token);
158
+ }
159
+ function buildIssuedTokenPayload(input, token) {
160
+ return {
161
+ version: 1,
162
+ type: 'tirtc-connect-token',
163
+ peer_id: input.peerId,
164
+ local_id: input.localId,
165
+ service_entry: input.serviceEntry ?? '',
166
+ token,
167
+ openapi_entry: input.openapiEntry?.trim() || kDefaultOpenapiEntry,
168
+ user_ttl_seconds: input.userTtlSeconds ?? kDefaultUserTtlSeconds,
169
+ channel_ttl_seconds: input.channelTtlSeconds ?? kDefaultChannelTtlSeconds,
170
+ generated_at: new Date().toISOString(),
171
+ };
172
+ }
173
+ async function writePngQrcode(payloadJson, outputPath) {
174
+ const resolvedPath = path_1.default.resolve(outputPath);
175
+ ensureDirectory(path_1.default.dirname(resolvedPath));
176
+ await qrcode_1.default.toFile(resolvedPath, payloadJson, {
177
+ errorCorrectionLevel: 'M',
178
+ margin: 2,
179
+ type: 'png',
180
+ width: 960,
181
+ });
182
+ return resolvedPath;
183
+ }
184
+ async function issueTokenWithQrcode(input) {
185
+ const token = await issueToken(input);
186
+ const payload = buildIssuedTokenPayload(input, token);
187
+ const payloadJson = JSON.stringify(payload);
188
+ const qrCodePngPath = await writePngQrcode(payloadJson, buildQrCodePngPath(payload));
189
+ return {
190
+ payload,
191
+ payloadJson,
192
+ token,
193
+ qrCodePngPath,
194
+ };
195
+ }
196
+ function formatTokenIssueConsoleOutput(output) {
197
+ const summaryLines = [
198
+ 'Issued Token Summary:',
199
+ ' local_id: ' + output.payload.local_id,
200
+ ' peer_id: ' + output.payload.peer_id,
201
+ ' service_entry: ' + (output.payload.service_entry || '(empty)'),
202
+ ' openapi_entry: ' + output.payload.openapi_entry,
203
+ ' user_ttl_seconds: ' + output.payload.user_ttl_seconds,
204
+ ' channel_ttl_seconds: ' + output.payload.channel_ttl_seconds,
205
+ ' generated_at: ' + output.payload.generated_at,
206
+ '',
207
+ 'Token:',
208
+ output.token,
209
+ '',
210
+ 'Payload JSON:',
211
+ JSON.stringify(output.payload, null, 2),
212
+ '',
213
+ 'QR Code PNG:',
214
+ output.qrCodePngPath,
215
+ ];
216
+ return summaryLines.join('\n');
217
+ }
@@ -0,0 +1,30 @@
1
+ import { Transport } from '../../../app-server/protocol-client';
2
+ type ProcessTransportOptions = {
3
+ env?: NodeJS.ProcessEnv;
4
+ };
5
+ export declare class ProcessTransport implements Transport {
6
+ private child;
7
+ private messageHandler;
8
+ private closeHandler;
9
+ private errorHandler;
10
+ constructor(command: string, args: string[], options?: ProcessTransportOptions);
11
+ send(data: string): void;
12
+ onMessage(handler: (data: string) => void): void;
13
+ onClose(handler: () => void): void;
14
+ onError(handler: (error: Error) => void): void;
15
+ stop(): void;
16
+ getPid(): number;
17
+ }
18
+ export declare class SocketTransport implements Transport {
19
+ private socket;
20
+ private messageHandler;
21
+ private closeHandler;
22
+ private errorHandler;
23
+ constructor(socketPath: string);
24
+ send(data: string): void;
25
+ onMessage(handler: (data: string) => void): void;
26
+ onClose(handler: () => void): void;
27
+ onError(handler: (error: Error) => void): void;
28
+ stop(): void;
29
+ }
30
+ export {};
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SocketTransport = exports.ProcessTransport = void 0;
7
+ const net_1 = __importDefault(require("net"));
8
+ const child_process_1 = require("child_process");
9
+ class ProcessTransport {
10
+ child;
11
+ messageHandler = () => { };
12
+ closeHandler = () => { };
13
+ errorHandler = () => { };
14
+ constructor(command, args, options) {
15
+ const env = options?.env ? { ...process.env, ...options.env } : process.env;
16
+ this.child = (0, child_process_1.spawn)(command, args, {
17
+ stdio: ['pipe', 'pipe', 'inherit'],
18
+ env,
19
+ });
20
+ this.child.stdout?.on('data', (data) => {
21
+ this.messageHandler(data.toString());
22
+ });
23
+ this.child.on('error', (err) => {
24
+ this.errorHandler(err);
25
+ });
26
+ this.child.on('close', () => {
27
+ this.closeHandler();
28
+ });
29
+ }
30
+ send(data) {
31
+ this.child.stdin?.write(data);
32
+ }
33
+ onMessage(handler) {
34
+ this.messageHandler = handler;
35
+ }
36
+ onClose(handler) {
37
+ this.closeHandler = handler;
38
+ }
39
+ onError(handler) {
40
+ this.errorHandler = handler;
41
+ }
42
+ stop() {
43
+ this.child.kill();
44
+ }
45
+ getPid() {
46
+ return this.child.pid ?? -1;
47
+ }
48
+ }
49
+ exports.ProcessTransport = ProcessTransport;
50
+ class SocketTransport {
51
+ socket;
52
+ messageHandler = () => { };
53
+ closeHandler = () => { };
54
+ errorHandler = () => { };
55
+ constructor(socketPath) {
56
+ this.socket = net_1.default.createConnection(socketPath);
57
+ this.socket.on('data', (data) => {
58
+ this.messageHandler(data.toString());
59
+ });
60
+ this.socket.on('close', () => {
61
+ this.closeHandler();
62
+ });
63
+ this.socket.on('error', (error) => {
64
+ this.errorHandler(error);
65
+ });
66
+ }
67
+ send(data) {
68
+ this.socket.write(data);
69
+ }
70
+ onMessage(handler) {
71
+ this.messageHandler = handler;
72
+ }
73
+ onClose(handler) {
74
+ this.closeHandler = handler;
75
+ }
76
+ onError(handler) {
77
+ this.errorHandler = handler;
78
+ }
79
+ stop() {
80
+ this.socket.end();
81
+ this.socket.destroy();
82
+ }
83
+ }
84
+ exports.SocketTransport = SocketTransport;
File without changes
package/dist/dummy.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const commander_1 = require("commander");
7
+ const child_process_1 = require("child_process");
8
+ const path_1 = __importDefault(require("path"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const program = new commander_1.Command();
11
+ const CLI_VERSION = '1.0.0';
12
+ function getHostBinaryPath() {
13
+ // Local development path relative to dist/index.js
14
+ const localDevPath = path_1.default.resolve(__dirname, '../../../app-server/bin/tirtc-devtool-host.js');
15
+ if (fs_1.default.existsSync(localDevPath)) {
16
+ return localDevPath;
17
+ }
18
+ // Fallback to globally installed or in PATH
19
+ return 'tirtc-devtool-host';
20
+ }
21
+ program
22
+ .name('tirtc-devtool')
23
+ .description('TiRTC Developer Tool CLI')
24
+ .option('-v, --version', 'output the version number')
25
+ .action((options) => {
26
+ if (options.version) {
27
+ console.log(`CLI Version: ${CLI_VERSION}`);
28
+ const hostPath = getHostBinaryPath();
29
+ let hostCmdPath = hostPath;
30
+ let hostArgs = ['--version'];
31
+ if (hostPath.endsWith('.js')) {
32
+ hostArgs = [hostPath, '--version'];
33
+ hostCmdPath = process.execPath;
34
+ }
35
+ try {
36
+ const result = (0, child_process_1.spawnSync)(hostCmdPath, hostArgs, { encoding: 'utf-8' });
37
+ if (result.stdout) {
38
+ process.stdout.write(result.stdout);
39
+ }
40
+ }
41
+ catch (e) {
42
+ console.log('Host Version: unknown');
43
+ console.log('Protocol Version: unknown');
44
+ }
45
+ process.exit(0);
46
+ }
47
+ });
48
+ program.parse(process.argv);
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "tirtc-devtools-cli",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "tirtc-devtool": "./bin/tirtc-devtool.js"
8
+ },
9
+ "files": [
10
+ "README.md",
11
+ "USAGE.md",
12
+ "bin/tirtc-devtool.js",
13
+ "dist",
14
+ "script/ensure_ffmpeg.sh",
15
+ "vendor"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "test": "jest",
20
+ "test:owner": "./script/test.sh owner",
21
+ "test:publish": "./script/test.sh publish",
22
+ "test:real-transport": "./script/test.sh real-transport",
23
+ "test:e2e": "./script/test.sh e2e",
24
+ "test:two-endpoints": "./script/test.sh two-endpoints",
25
+ "test:acceptance": "./script/test.sh acceptance",
26
+ "lint": "eslint . --ext .ts --max-warnings=0",
27
+ "lint:fix": "eslint . --ext .ts --fix",
28
+ "package": "./script/package.sh",
29
+ "release:npm": "./script/release-npm.sh"
30
+ },
31
+ "pkg": {
32
+ "assets": [
33
+ "dist/**/*"
34
+ ]
35
+ },
36
+ "devDependencies": {
37
+ "@types/jest": "^29.5.0",
38
+ "@types/node": "^20.0.0",
39
+ "@types/qrcode": "^1.5.5",
40
+ "@typescript-eslint/eslint-plugin": "^7.18.0",
41
+ "@typescript-eslint/parser": "^7.18.0",
42
+ "eslint": "^8.57.0",
43
+ "jest": "^29.5.0",
44
+ "pkg": "^5.8.1",
45
+ "ts-jest": "^29.1.0",
46
+ "typescript": "^5.0.0"
47
+ },
48
+ "dependencies": {
49
+ "@iarna/toml": "^2.2.5",
50
+ "commander": "^11.0.0",
51
+ "qrcode": "^1.5.4",
52
+ "zod": "^3.22.4"
53
+ }
54
+ }
@@ -0,0 +1,22 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+
4
+ SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
5
+ CLI_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)
6
+ CLI_DIST="$CLI_ROOT/dist/devtools/cli/src/ffmpeg_tool.js"
7
+
8
+ if [[ ! -f "$CLI_DIST" ]]; then
9
+ echo "[ensure_ffmpeg] compiled helper missing: $CLI_DIST" >&2
10
+ echo "[ensure_ffmpeg] run: npm --prefix $CLI_ROOT run build" >&2
11
+ exit 1
12
+ fi
13
+
14
+ CLI_DIST="$CLI_DIST" node <<'NODE'
15
+ const helperPath = process.env.CLI_DIST;
16
+ if (!helperPath) {
17
+ throw new Error('missing CLI_DIST');
18
+ }
19
+ const {ensureFfmpegTools} = require(helperPath);
20
+ const tools = ensureFfmpegTools();
21
+ process.stdout.write(JSON.stringify(tools));
22
+ NODE
@@ -0,0 +1,23 @@
1
+ #ifndef TIRTC_AUDIO_CODEC_H_
2
+ #define TIRTC_AUDIO_CODEC_H_
3
+
4
+ #include <stddef.h>
5
+
6
+ #include "tirtc/audio_frame.h"
7
+ #include "tirtc/error.h"
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ TirtcError tirtc_audio_g711a_encode(const TirtcAudioPcmFrame* pcm_frame, void* out_buffer,
14
+ size_t out_buffer_capacity, TirtcAudioEncodedFrame* out_frame);
15
+
16
+ TirtcError tirtc_audio_g711a_decode(const TirtcAudioEncodedFrame* in_frame, void* out_buffer,
17
+ size_t out_buffer_capacity, TirtcAudioPcmFrame* out_frame);
18
+
19
+ #ifdef __cplusplus
20
+ }
21
+ #endif
22
+
23
+ #endif // TIRTC_AUDIO_CODEC_H_
@@ -0,0 +1,36 @@
1
+ #ifndef TIRTC_AUDIO_FRAME_H_
2
+ #define TIRTC_AUDIO_FRAME_H_
3
+
4
+ #include <stddef.h>
5
+ #include <stdint.h>
6
+
7
+ #include "tirtc/audio_sample_rate.h"
8
+ #include "tirtc/media_codec.h"
9
+
10
+ #ifdef __cplusplus
11
+ extern "C" {
12
+ #endif
13
+
14
+ typedef struct TirtcAudioPcmFrame {
15
+ TirtcAudioSampleRate sample_rate;
16
+ uint32_t samples_per_channel;
17
+ int64_t pts_us;
18
+ /* Mutable PCM payload for capture, processing, and render-fill paths. */
19
+ void* data;
20
+ size_t data_bytes;
21
+ } TirtcAudioPcmFrame;
22
+
23
+ typedef struct TirtcAudioEncodedFrame {
24
+ TirtcMediaCodec codec;
25
+ TirtcAudioSampleRate sample_rate;
26
+ uint32_t samples_per_channel;
27
+ int64_t pts_us;
28
+ const void* data;
29
+ size_t data_bytes;
30
+ } TirtcAudioEncodedFrame;
31
+
32
+ #ifdef __cplusplus
33
+ }
34
+ #endif
35
+
36
+ #endif // TIRTC_AUDIO_FRAME_H_
@@ -0,0 +1,56 @@
1
+ #ifndef TIRTC_AUDIO_IO_H_
2
+ #define TIRTC_AUDIO_IO_H_
3
+
4
+ #include <stdint.h>
5
+
6
+ #include "tirtc/audio_frame.h"
7
+ #include "tirtc/error.h"
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ typedef struct TirtcAudioAin TirtcAudioAin;
14
+ typedef struct TirtcAudioAout TirtcAudioAout;
15
+
16
+ typedef struct TirtcAudioIoConfig {
17
+ TirtcAudioSampleRate sample_rate;
18
+ /* v1 uses fixed 10 ms mono blocks: 8K -> 80 samples, 16K -> 160 samples. */
19
+ uint32_t samples_per_buffer;
20
+ } TirtcAudioIoConfig;
21
+
22
+ typedef void (*TirtcAudioAinOnFrameFn)(TirtcAudioAin* ain, const TirtcAudioPcmFrame* frame,
23
+ void* user_data);
24
+
25
+ /*
26
+ * AOUT pre-fills sample_rate, samples_per_channel, data, and data_bytes before
27
+ * calling render. The callback contract expects a non-negative rendered PCM
28
+ * byte count. Backends defensively clamp negative returns to zero and zero-fill
29
+ * any remaining buffer space.
30
+ *
31
+ * The render callback and user_data supplied at open-time must stay valid until
32
+ * close completes. Backends may invoke render without holding backend locks.
33
+ */
34
+ typedef int (*TirtcAudioAoutRenderFn)(TirtcAudioAout* aout, TirtcAudioPcmFrame* frame,
35
+ void* user_data);
36
+
37
+ TirtcError tirtc_audio_ain_open(TirtcAudioAin* ain, const TirtcAudioIoConfig* config,
38
+ TirtcAudioAinOnFrameFn on_frame, void* user_data);
39
+
40
+ TirtcError tirtc_audio_ain_close(TirtcAudioAin* ain);
41
+ void tirtc_audio_ain_destroy(TirtcAudioAin* ain);
42
+
43
+ TirtcError tirtc_audio_aout_open(TirtcAudioAout* aout, const TirtcAudioIoConfig* config,
44
+ TirtcAudioAoutRenderFn render, void* user_data);
45
+
46
+ TirtcError tirtc_audio_aout_set_volume(TirtcAudioAout* aout, uint32_t volume_percent);
47
+ TirtcError tirtc_audio_aout_pause(TirtcAudioAout* aout, int pause_on);
48
+ TirtcError tirtc_audio_aout_flush(TirtcAudioAout* aout);
49
+ TirtcError tirtc_audio_aout_close(TirtcAudioAout* aout);
50
+ void tirtc_audio_aout_destroy(TirtcAudioAout* aout);
51
+
52
+ #ifdef __cplusplus
53
+ }
54
+ #endif
55
+
56
+ #endif // TIRTC_AUDIO_IO_H_
@@ -0,0 +1,19 @@
1
+ #ifndef TIRTC_AUDIO_IO_ANDROID_H_
2
+ #define TIRTC_AUDIO_IO_ANDROID_H_
3
+
4
+ #include "tirtc/audio_io.h"
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ #if defined(__ANDROID__)
11
+ TirtcError tirtc_audio_android_create_open_sl_ain(TirtcAudioAin** out_ain);
12
+ TirtcError tirtc_audio_android_create_open_sl_aout(TirtcAudioAout** out_aout);
13
+ #endif
14
+
15
+ #ifdef __cplusplus
16
+ }
17
+ #endif
18
+
19
+ #endif // TIRTC_AUDIO_IO_ANDROID_H_
@@ -0,0 +1,19 @@
1
+ #ifndef TIRTC_AUDIO_IO_APPLE_H_
2
+ #define TIRTC_AUDIO_IO_APPLE_H_
3
+
4
+ #include "tirtc/audio_io.h"
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ #if defined(__APPLE__)
11
+ TirtcError tirtc_audio_apple_create_audio_toolbox_ain(TirtcAudioAin** out_ain);
12
+ TirtcError tirtc_audio_apple_create_audio_queue_aout(TirtcAudioAout** out_aout);
13
+ #endif
14
+
15
+ #ifdef __cplusplus
16
+ }
17
+ #endif
18
+
19
+ #endif // TIRTC_AUDIO_IO_APPLE_H_
@@ -0,0 +1,19 @@
1
+ #ifndef TIRTC_AUDIO_IO_HARMONY_H_
2
+ #define TIRTC_AUDIO_IO_HARMONY_H_
3
+
4
+ #include "tirtc/audio_io.h"
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ #if defined(__OHOS__)
11
+ TirtcError tirtc_audio_harmony_create_open_sl_ain(TirtcAudioAin** out_ain);
12
+ TirtcError tirtc_audio_harmony_create_audio_render_aout(TirtcAudioAout** out_aout);
13
+ #endif
14
+
15
+ #ifdef __cplusplus
16
+ }
17
+ #endif
18
+
19
+ #endif // TIRTC_AUDIO_IO_HARMONY_H_
@@ -0,0 +1,19 @@
1
+ #ifndef TIRTC_AUDIO_IO_WINDOWS_H_
2
+ #define TIRTC_AUDIO_IO_WINDOWS_H_
3
+
4
+ #include "tirtc/audio_io.h"
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ #if defined(_WIN32)
11
+ TirtcError tirtc_audio_windows_create_wasapi_ain(TirtcAudioAin** out_ain);
12
+ TirtcError tirtc_audio_windows_create_wave_out_aout(TirtcAudioAout** out_aout);
13
+ #endif
14
+
15
+ #ifdef __cplusplus
16
+ }
17
+ #endif
18
+
19
+ #endif // TIRTC_AUDIO_IO_WINDOWS_H_