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,224 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.RuntimeCredentialTokenIssuer = void 0;
37
+ const child_process_1 = require("child_process");
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const util_1 = require("util");
41
+ const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
42
+ function pathExists(filePath) {
43
+ return fs.existsSync(filePath);
44
+ }
45
+ function ensureDir(dirPath) {
46
+ if (!pathExists(dirPath)) {
47
+ fs.mkdirSync(dirPath, { recursive: true });
48
+ }
49
+ }
50
+ function fileMtimeMs(filePath) {
51
+ if (!pathExists(filePath)) {
52
+ return 0;
53
+ }
54
+ return fs.statSync(filePath).mtimeMs;
55
+ }
56
+ function parseExecError(error) {
57
+ if (!error || typeof error !== 'object') {
58
+ return String(error);
59
+ }
60
+ const typed = error;
61
+ const stderr = typeof typed.stderr === 'string' ? typed.stderr.trim() : typed.stderr?.toString('utf8').trim();
62
+ const stdout = typeof typed.stdout === 'string' ? typed.stdout.trim() : typed.stdout?.toString('utf8').trim();
63
+ if (stderr && stderr.length > 0) {
64
+ return stderr;
65
+ }
66
+ if (stdout && stdout.length > 0) {
67
+ return stdout;
68
+ }
69
+ if (typed.message) {
70
+ return typed.message;
71
+ }
72
+ if (typed.code !== undefined) {
73
+ return 'process exited with code ' + String(typed.code);
74
+ }
75
+ return 'process failed';
76
+ }
77
+ class RuntimeCredentialTokenIssuer {
78
+ repoRoot;
79
+ platform;
80
+ runtimeBundleRoot;
81
+ binding;
82
+ constructor(options) {
83
+ this.repoRoot = options.repoRoot;
84
+ this.platform = options.platform;
85
+ this.runtimeBundleRoot = options.runtimeBundleRoot;
86
+ }
87
+ resolveSourcePath() {
88
+ const sourcePath = path.join(this.repoRoot, 'app-server/host/native/credential_napi.cc');
89
+ if (!pathExists(sourcePath)) {
90
+ throw new Error('credential source missing: ' + sourcePath);
91
+ }
92
+ return sourcePath;
93
+ }
94
+ resolveBuildOutputPath() {
95
+ return path.join(this.repoRoot, `.build/app-server/runtime-backed/credential_issue_token/${this.platform}/credential_napi.node`);
96
+ }
97
+ resolveRuntimeLibDir() {
98
+ const libDir = path.join(this.runtimeBundleRoot, 'lib');
99
+ if (!pathExists(libDir)) {
100
+ throw new Error('runtime-backed sdk libs are missing for platform ' + this.platform + ': ' + libDir);
101
+ }
102
+ return libDir;
103
+ }
104
+ resolveRuntimeIncludeDir() {
105
+ const includeDir = path.join(this.runtimeBundleRoot, 'include');
106
+ if (!pathExists(includeDir)) {
107
+ throw new Error('runtime-backed sdk headers are missing for platform ' + this.platform + ': ' + includeDir);
108
+ }
109
+ return includeDir;
110
+ }
111
+ resolveNodeHeadersDir() {
112
+ const configured = process.env.TIRTC_NODE_HEADERS_DIR;
113
+ const candidates = [
114
+ configured,
115
+ path.join(this.repoRoot, '.tmp/node-headers'),
116
+ path.join(this.repoRoot, '.tmp/node_headers'),
117
+ ].filter((v) => typeof v === 'string' && v.trim().length > 0);
118
+ for (const candidate of candidates) {
119
+ const normalized = path.resolve(candidate);
120
+ if (pathExists(path.join(normalized, 'node_api.h'))) {
121
+ return normalized;
122
+ }
123
+ }
124
+ throw new Error('node_api.h not found; set TIRTC_NODE_HEADERS_DIR to Node headers include dir');
125
+ }
126
+ async ensureCredentialAddon() {
127
+ const sourcePath = this.resolveSourcePath();
128
+ const outputPath = this.resolveBuildOutputPath();
129
+ ensureDir(path.dirname(outputPath));
130
+ const runtimeManifestPath = path.join(this.runtimeBundleRoot, 'manifest.txt');
131
+ const dependencyStampMs = Math.max(fileMtimeMs(sourcePath), fileMtimeMs(runtimeManifestPath));
132
+ const stale = fileMtimeMs(outputPath) < dependencyStampMs;
133
+ if (pathExists(outputPath) && !stale) {
134
+ return outputPath;
135
+ }
136
+ const runtimeLibDir = this.resolveRuntimeLibDir();
137
+ const runtimeIncludeDir = this.resolveRuntimeIncludeDir();
138
+ const nodeHeadersDir = this.resolveNodeHeadersDir();
139
+ const requiredRuntimeLibs = [
140
+ 'libmatrix_runtime_credential.a',
141
+ 'libmatrix_runtime_foundation_http.a',
142
+ 'libmatrix_runtime_foundation_logging.a',
143
+ 'libxlog.a',
144
+ 'libssl.a',
145
+ 'libcrypto.a',
146
+ ].map((name) => path.join(runtimeLibDir, name));
147
+ for (const libPath of requiredRuntimeLibs) {
148
+ if (!pathExists(libPath)) {
149
+ throw new Error('credential dependency missing: ' + libPath);
150
+ }
151
+ }
152
+ const args = [
153
+ '-O2',
154
+ '-std=c++17',
155
+ '-shared',
156
+ '-undefined',
157
+ 'dynamic_lookup',
158
+ sourcePath,
159
+ '-o',
160
+ outputPath,
161
+ '-I',
162
+ runtimeIncludeDir,
163
+ '-I',
164
+ nodeHeadersDir,
165
+ ...requiredRuntimeLibs,
166
+ '-lpthread',
167
+ '-lm',
168
+ ];
169
+ if (this.platform === 'macos-arm64') {
170
+ args.push('-framework', 'Foundation', '-framework', 'CoreFoundation', '-lobjc', '-lz');
171
+ }
172
+ try {
173
+ await execFileAsync('c++', args, {
174
+ cwd: this.repoRoot,
175
+ env: process.env,
176
+ maxBuffer: 10 * 1024 * 1024,
177
+ });
178
+ }
179
+ catch (error) {
180
+ throw new Error('failed to build credential napi addon: ' + parseExecError(error));
181
+ }
182
+ if (!pathExists(outputPath)) {
183
+ throw new Error('credential napi addon was not produced: ' + outputPath);
184
+ }
185
+ return outputPath;
186
+ }
187
+ async ensureBinding() {
188
+ if (this.binding) {
189
+ return this.binding;
190
+ }
191
+ const addonPath = await this.ensureCredentialAddon();
192
+ const loaded = require(addonPath);
193
+ if (!loaded || typeof loaded.issueToken !== 'function') {
194
+ throw new Error('credential addon missing issueToken() export');
195
+ }
196
+ this.binding = loaded;
197
+ return loaded;
198
+ }
199
+ async issueToken(options) {
200
+ const binding = await this.ensureBinding();
201
+ let token;
202
+ try {
203
+ token = binding.issueToken({
204
+ openapiEntry: options.openapiEntry,
205
+ accessId: options.accessId,
206
+ secretKey: options.secretKey,
207
+ localId: options.localId,
208
+ peerId: options.peerId,
209
+ userTtlSeconds: options.userTtlSeconds,
210
+ channelTtlSeconds: options.channelTtlSeconds,
211
+ });
212
+ }
213
+ catch (error) {
214
+ const message = error instanceof Error ? error.message : String(error);
215
+ throw new Error('issue token failed: ' + message);
216
+ }
217
+ const normalized = token.trim();
218
+ if (normalized.length === 0) {
219
+ throw new Error('issue token failed: empty token');
220
+ }
221
+ return normalized;
222
+ }
223
+ }
224
+ exports.RuntimeCredentialTokenIssuer = RuntimeCredentialTokenIssuer;
@@ -0,0 +1,37 @@
1
+ type ReceiveWorkerManagerOptions = {
2
+ repoRoot: string;
3
+ platform: string;
4
+ onLogLine?: (payload: {
5
+ source: 'downlink';
6
+ stream: 'stdout' | 'stderr';
7
+ line: string;
8
+ pid?: number;
9
+ }) => void;
10
+ };
11
+ type ReceiveWorkerStartOptions = {
12
+ key: string;
13
+ serviceEntry: string;
14
+ peerId: string;
15
+ token: string;
16
+ streamId: number;
17
+ media: 'audio' | 'video';
18
+ targetPath: string;
19
+ framed: boolean;
20
+ };
21
+ export declare class RuntimeReceiveWorkerManager {
22
+ private readonly bindings;
23
+ private readonly onLogLine?;
24
+ private readonly bridge;
25
+ private sharedSession?;
26
+ constructor(options: ReceiveWorkerManagerOptions);
27
+ private emitLog;
28
+ private buildDesiredConfig;
29
+ private stopSharedSession;
30
+ private ensureSharedSession;
31
+ syncBindings(bindings: ReceiveWorkerStartOptions[]): Promise<{
32
+ started: boolean;
33
+ pid?: number;
34
+ }>;
35
+ stopAll(): Promise<void>;
36
+ }
37
+ export {};
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.RuntimeReceiveWorkerManager = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const RuntimeHostBridge_1 = require("./native/RuntimeHostBridge");
40
+ function ensureDir(dirPath) {
41
+ if (!fs.existsSync(dirPath)) {
42
+ fs.mkdirSync(dirPath, { recursive: true });
43
+ }
44
+ }
45
+ function nowIsoString() {
46
+ return new Date().toISOString();
47
+ }
48
+ function sameDesiredConfig(left, right) {
49
+ return left.serviceEntry === right.serviceEntry &&
50
+ left.peerId === right.peerId &&
51
+ left.token === right.token &&
52
+ left.audioEnabled === right.audioEnabled &&
53
+ left.videoEnabled === right.videoEnabled &&
54
+ left.audioStreamId === right.audioStreamId &&
55
+ left.videoStreamId === right.videoStreamId &&
56
+ left.audioOutputPath === right.audioOutputPath &&
57
+ left.videoOutputPath === right.videoOutputPath &&
58
+ left.audioFramed === right.audioFramed &&
59
+ left.videoFramed === right.videoFramed;
60
+ }
61
+ class RuntimeReceiveWorkerManager {
62
+ bindings = new Map();
63
+ onLogLine;
64
+ bridge;
65
+ sharedSession;
66
+ constructor(options) {
67
+ this.onLogLine = options.onLogLine;
68
+ this.bridge = new RuntimeHostBridge_1.RuntimeHostBridge({
69
+ repoRoot: options.repoRoot,
70
+ platform: options.platform,
71
+ });
72
+ }
73
+ emitLog(stream, line) {
74
+ const normalized = line.trim();
75
+ if (!this.onLogLine || normalized.length === 0) {
76
+ return;
77
+ }
78
+ this.onLogLine({ source: 'downlink', stream, line: normalized });
79
+ }
80
+ buildDesiredConfig(serviceEntry, peerId, token) {
81
+ const desired = {
82
+ serviceEntry,
83
+ peerId,
84
+ token,
85
+ audioEnabled: false,
86
+ videoEnabled: false,
87
+ };
88
+ for (const binding of this.bindings.values()) {
89
+ if (binding.serviceEntry !== serviceEntry || binding.peerId !== peerId || binding.token !== token) {
90
+ continue;
91
+ }
92
+ if (binding.media === 'audio') {
93
+ desired.audioEnabled = true;
94
+ desired.audioStreamId = binding.streamId;
95
+ desired.audioOutputPath = binding.targetPath;
96
+ desired.audioFramed = binding.framed;
97
+ }
98
+ else if (binding.media === 'video') {
99
+ desired.videoEnabled = true;
100
+ desired.videoStreamId = binding.streamId;
101
+ desired.videoOutputPath = binding.targetPath;
102
+ desired.videoFramed = binding.framed;
103
+ }
104
+ }
105
+ return desired;
106
+ }
107
+ async stopSharedSession() {
108
+ if (!this.sharedSession) {
109
+ return;
110
+ }
111
+ this.bridge.stopDownlink();
112
+ this.sharedSession = undefined;
113
+ this.emitLog('stdout', '[runtime-backed receiver] session stopped');
114
+ }
115
+ async ensureSharedSession(serviceEntry, peerId, token) {
116
+ const desired = this.buildDesiredConfig(serviceEntry, peerId, token);
117
+ if (!desired.audioEnabled && !desired.videoEnabled) {
118
+ await this.stopSharedSession();
119
+ return { started: false };
120
+ }
121
+ const current = this.sharedSession;
122
+ if (current && sameDesiredConfig(current.config, desired)) {
123
+ return { started: false, pid: current.sessionId };
124
+ }
125
+ await this.stopSharedSession();
126
+ if (desired.audioOutputPath) {
127
+ ensureDir(path.dirname(desired.audioOutputPath));
128
+ }
129
+ if (desired.videoOutputPath) {
130
+ ensureDir(path.dirname(desired.videoOutputPath));
131
+ }
132
+ const args = [
133
+ '--service-entry=' + desired.serviceEntry,
134
+ '--peer-id=' + desired.peerId,
135
+ '--token=' + desired.token,
136
+ ];
137
+ if (desired.audioEnabled && desired.audioStreamId !== undefined && desired.audioOutputPath) {
138
+ args.push('--audio-stream-id=' + String(desired.audioStreamId));
139
+ args.push('--audio-output=' + desired.audioOutputPath);
140
+ if (desired.audioFramed) {
141
+ args.push('--audio-framed=1');
142
+ }
143
+ }
144
+ if (desired.videoEnabled && desired.videoStreamId !== undefined && desired.videoOutputPath) {
145
+ args.push('--video-stream-id=' + String(desired.videoStreamId));
146
+ args.push('--video-output=' + desired.videoOutputPath);
147
+ if (desired.videoFramed) {
148
+ args.push('--video-framed=1');
149
+ }
150
+ }
151
+ const sessionId = this.bridge.startDownlink(args);
152
+ this.sharedSession = {
153
+ startedAt: nowIsoString(),
154
+ config: desired,
155
+ sessionId,
156
+ };
157
+ this.emitLog('stdout', '[runtime-backed receiver] session started sessionId=' + String(sessionId));
158
+ return { started: true, pid: sessionId };
159
+ }
160
+ async syncBindings(bindings) {
161
+ this.bindings.clear();
162
+ for (const binding of bindings) {
163
+ this.bindings.set(binding.key, {
164
+ key: binding.key,
165
+ serviceEntry: binding.serviceEntry,
166
+ peerId: binding.peerId,
167
+ token: binding.token,
168
+ streamId: binding.streamId,
169
+ media: binding.media,
170
+ targetPath: binding.targetPath,
171
+ framed: binding.framed,
172
+ });
173
+ }
174
+ if (bindings.length === 0) {
175
+ await this.stopSharedSession();
176
+ return { started: false };
177
+ }
178
+ const first = bindings[0];
179
+ return await this.ensureSharedSession(first.serviceEntry, first.peerId, first.token);
180
+ }
181
+ async stopAll() {
182
+ this.bindings.clear();
183
+ await this.stopSharedSession();
184
+ }
185
+ }
186
+ exports.RuntimeReceiveWorkerManager = RuntimeReceiveWorkerManager;
@@ -0,0 +1,42 @@
1
+ type SendWorkerManagerOptions = {
2
+ repoRoot: string;
3
+ platform: string;
4
+ onLogLine?: (payload: {
5
+ source: 'uplink';
6
+ stream: 'stdout' | 'stderr';
7
+ line: string;
8
+ pid?: number;
9
+ }) => void;
10
+ };
11
+ type SendWorkerStartOptions = {
12
+ key: string;
13
+ serviceEntry: string;
14
+ license: string;
15
+ assetsDir: string;
16
+ streamId: number;
17
+ media: 'audio' | 'video';
18
+ };
19
+ export declare class RuntimeSendWorkerManager {
20
+ private readonly repoRoot;
21
+ private readonly bindings;
22
+ private readonly onLogLine?;
23
+ private readonly bridge;
24
+ private sharedSession?;
25
+ constructor(options: SendWorkerManagerOptions);
26
+ private emitLog;
27
+ private resolveFixtureAssetsDir;
28
+ private buildDesiredConfig;
29
+ private stopSharedSession;
30
+ private ensureSharedSession;
31
+ ensureServiceSession(serviceEntry: string, license: string): Promise<{
32
+ started: boolean;
33
+ pid?: number;
34
+ }>;
35
+ startDeviceStream(options: SendWorkerStartOptions): Promise<{
36
+ started: boolean;
37
+ pid?: number;
38
+ }>;
39
+ stopStream(key: string): Promise<void>;
40
+ stopAll(): Promise<void>;
41
+ }
42
+ export {};