mindexec-ai 0.2.385
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 +354 -0
- package/codex-runtime.js +1339 -0
- package/launch-bridge.cjs +236 -0
- package/package.json +77 -0
- package/port-guard.cjs +232 -0
- package/remote-fast/osx-arm64/mindexec-remote-fast +0 -0
- package/remote-fast/osx-arm64/mindexec-remote-fast.deps.json +24 -0
- package/remote-fast/osx-arm64/mindexec-remote-fast.dll +0 -0
- package/remote-fast/osx-arm64/mindexec-remote-fast.runtimeconfig.json +13 -0
- package/remote-fast/osx-x64/mindexec-remote-fast +0 -0
- package/remote-fast/osx-x64/mindexec-remote-fast.deps.json +24 -0
- package/remote-fast/osx-x64/mindexec-remote-fast.dll +0 -0
- package/remote-fast/osx-x64/mindexec-remote-fast.runtimeconfig.json +13 -0
- package/remote-fast/win-x64/mindexec-remote-fast.deps.json +24 -0
- package/remote-fast/win-x64/mindexec-remote-fast.dll +0 -0
- package/remote-fast/win-x64/mindexec-remote-fast.exe +0 -0
- package/remote-fast/win-x64/mindexec-remote-fast.runtimeconfig.json +20 -0
- package/remote-hub.js +3106 -0
- package/scripts/auth-session-smoke.mjs +262 -0
- package/scripts/remote-agent-managed-smoke.mjs +291 -0
- package/scripts/remote-agent-package-smoke.mjs +64 -0
- package/scripts/remote-agent-ws-smoke.mjs +202 -0
- package/scripts/remote-fast-live-rate-smoke.mjs +355 -0
- package/scripts/remote-fast-mdm-browser-smoke.mjs +476 -0
- package/scripts/remote-fleet-render-smoke.mjs +1491 -0
- package/scripts/remote-frame-ws-smoke.mjs +234 -0
- package/scripts/remote-http-smoke.mjs +592 -0
- package/scripts/remote-hub-identity-smoke.mjs +146 -0
- package/scripts/remote-hub-scale-smoke.mjs +124 -0
- package/scripts/remote-hub-smoke.mjs +631 -0
- package/scripts/remote-input-ws-smoke.mjs +263 -0
- package/scripts/remote-registry-follower-smoke.mjs +752 -0
- package/scripts/setup-tree-sitter-grammars.mjs +80 -0
- package/server.js +15709 -0
- package/start-bridge.bat +32 -0
- package/start-bridge.sh +81 -0
- package/tree-sitter-grammars/README.md +18 -0
- package/tree-sitter-grammars/tree-sitter-c_sharp.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-go.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-java.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-javascript.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-python.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-rust.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-tsx.wasm +0 -0
- package/tree-sitter-grammars/tree-sitter-typescript.wasm +0 -0
- package/wwwroot/_headers +73 -0
- package/wwwroot/_redirects +1 -0
- package/wwwroot/appsettings.json +83 -0
- package/wwwroot/assets/AdminDashboardPage-B2vz2Px9.css +1 -0
- package/wwwroot/assets/AdminDashboardPage-DnuCHywn.js +1 -0
- package/wwwroot/assets/AppSidebar-DU2OgSiv.js +2 -0
- package/wwwroot/assets/AuthPages-BrH6kRcv.css +1 -0
- package/wwwroot/assets/AuthPages-Dgezl7Vj.js +1 -0
- package/wwwroot/assets/CodePage-7kgZlB3O.js +87 -0
- package/wwwroot/assets/CodePage-Bncc352E.css +1 -0
- package/wwwroot/assets/CompanyCorePage-ChBnq1ve.css +1 -0
- package/wwwroot/assets/CompanyCorePage-CzIZIIU_.js +13 -0
- package/wwwroot/assets/ExecutionModePage-B-etp_mc.js +18 -0
- package/wwwroot/assets/ExecutionModePage-TLuld9l3.css +1 -0
- package/wwwroot/assets/LaunchLeadCapture-Bx9LM0IX.js +1 -0
- package/wwwroot/assets/LaunchLeadCapture-CiRI1shz.css +1 -0
- package/wwwroot/assets/MarketingHome-BsyerRpe.js +1 -0
- package/wwwroot/assets/MarketingHome-DPzaYzA_.css +1 -0
- package/wwwroot/assets/MindCanvas-DtqOZnoW.css +1 -0
- package/wwwroot/assets/MindCanvas-zEDXzaxW.js +49 -0
- package/wwwroot/assets/PlanMasterPage-CJ36rep-.css +1 -0
- package/wwwroot/assets/PlanMasterPage-NZ_mPvaE.js +4 -0
- package/wwwroot/assets/PricingPage-Cg_0i_ZR.css +1 -0
- package/wwwroot/assets/PricingPage-Ylrn8l2g.js +1 -0
- package/wwwroot/assets/ToolPages-3M2KqA9k.js +28 -0
- package/wwwroot/assets/ToolPages-DIB187pZ.css +1 -0
- package/wwwroot/assets/YouTubeSearchPage-COv1oAA7.js +4 -0
- package/wwwroot/assets/YouTubeSearchPage-IPPa_BIH.css +1 -0
- package/wwwroot/assets/app-runtime-xD2Z3NdN.js +1 -0
- package/wwwroot/assets/canvas-runtime-BbicBcOj.js +44 -0
- package/wwwroot/assets/code-agent-runtime-B5PPZd1t.js +74 -0
- package/wwwroot/assets/executionModeSettings-NJqurj-o.js +1 -0
- package/wwwroot/assets/index-CQMKCp-t.js +2 -0
- package/wwwroot/assets/index-yNpEK-gp.css +1 -0
- package/wwwroot/assets/marketingTools-DN_rnHeB.js +4 -0
- package/wwwroot/assets/mindCanvasSearchWorker-BzPMsHOB.js +1 -0
- package/wwwroot/assets/mindexecution-mindcanvas.png +0 -0
- package/wwwroot/assets/mindexecution-prod-home-current.png +0 -0
- package/wwwroot/assets/mindexecution-prod-pricing-current.png +0 -0
- package/wwwroot/assets/pricingCheckoutShell-O-DnwmbU.js +1 -0
- package/wwwroot/assets/productionAdapterConfig-C5jfk6oG.js +1 -0
- package/wwwroot/assets/runtimeSettingsPersistenceProjection-BoNWmYjU.js +1 -0
- package/wwwroot/assets/storage-TM3YrWaj.js +1 -0
- package/wwwroot/assets/supabaseAuthAdapter-DA43DeSY.js +44 -0
- package/wwwroot/assets/toolHandoff-D5e5f7t5.js +4 -0
- package/wwwroot/assets/vendor-icons-DE3gIReG.js +681 -0
- package/wwwroot/assets/vendor-msgpack-BE8aAsr3.js +1 -0
- package/wwwroot/assets/vendor-react-BXzpOyCS.js +40 -0
- package/wwwroot/favicon.svg +7 -0
- package/wwwroot/index.html +22 -0
- package/wwwroot/manifest.webmanifest +19 -0
- package/wwwroot/robots.txt +4 -0
- package/wwwroot/service-worker.js +7 -0
- package/wwwroot/sitemap.xml +39 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
6
|
+
import net from 'node:net';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const BRIDGE_TOKEN = 'remote-fast-mdm-browser-smoke-token';
|
|
12
|
+
const PAIR_TOKEN = 'remote-fast-mdm-browser-pair-token';
|
|
13
|
+
const LEASE_ID = 'remote-fast-mdm-browser-lease';
|
|
14
|
+
const LOCAL_BRIDGE_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
15
|
+
const REQUESTED_FPS = Number(process.env.MINDEXEC_REMOTE_MDM_BROWSER_REQUEST_FPS || 12);
|
|
16
|
+
const SAMPLE_MS = Number(process.env.MINDEXEC_REMOTE_MDM_BROWSER_SAMPLE_MS || 1500);
|
|
17
|
+
const MIN_PAINT_FPS = Number(process.env.MINDEXEC_REMOTE_MDM_BROWSER_MIN_PAINT_FPS || 8);
|
|
18
|
+
const MAX_PAINT_DROP_RATIO = Number(process.env.MINDEXEC_REMOTE_MDM_BROWSER_MAX_PAINT_DROP_RATIO || 0.65);
|
|
19
|
+
const MAX_PAINT_SEQ_GAP = Number(process.env.MINDEXEC_REMOTE_MDM_BROWSER_MAX_PAINT_SEQ_GAP || 10);
|
|
20
|
+
|
|
21
|
+
function wait(ms) {
|
|
22
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function findFreePort() {
|
|
26
|
+
return await new Promise((resolve, reject) => {
|
|
27
|
+
const server = net.createServer();
|
|
28
|
+
server.unref();
|
|
29
|
+
server.once('error', reject);
|
|
30
|
+
server.listen(0, '127.0.0.1', () => {
|
|
31
|
+
const address = server.address();
|
|
32
|
+
const port = typeof address === 'object' && address ? address.port : 0;
|
|
33
|
+
server.close(() => resolve(port));
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function fetchJson(url, options = {}) {
|
|
39
|
+
const response = await fetch(url, {
|
|
40
|
+
...options,
|
|
41
|
+
headers: {
|
|
42
|
+
...(options.body ? { 'Content-Type': 'application/json' } : {}),
|
|
43
|
+
'X-Bridge-Token': BRIDGE_TOKEN,
|
|
44
|
+
...(options.headers || {})
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const payload = await response.json().catch(() => null);
|
|
49
|
+
return { status: response.status, ok: response.ok, payload };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function waitFor(predicate, timeoutMs = 30000, label = 'condition') {
|
|
53
|
+
const startedAt = Date.now();
|
|
54
|
+
let lastError = null;
|
|
55
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
56
|
+
try {
|
|
57
|
+
const value = await predicate();
|
|
58
|
+
if (value) {
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
lastError = error;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
await wait(100);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
throw new Error(`Timed out waiting for ${label}${lastError ? `: ${lastError.message}` : ''}.`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function spawnBridge({ bridgePort, remoteHubPort, workspacePath, label, traceFrames = false }) {
|
|
72
|
+
const child = spawn(process.execPath, ['server.js'], {
|
|
73
|
+
cwd: LOCAL_BRIDGE_DIR,
|
|
74
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
75
|
+
windowsHide: true,
|
|
76
|
+
env: {
|
|
77
|
+
...process.env,
|
|
78
|
+
BRIDGE_PORT: String(bridgePort),
|
|
79
|
+
BRIDGE_TOKEN,
|
|
80
|
+
BRIDGE_REQUIRE_TOKEN: '1',
|
|
81
|
+
MINDEXEC_REMOTE_HUB: '1',
|
|
82
|
+
MINDEXEC_REMOTE_TRACE_FRAMES: traceFrames ? '1' : '',
|
|
83
|
+
REMOTE_HUB_HOST: '127.0.0.1',
|
|
84
|
+
REMOTE_HUB_PORT: String(remoteHubPort),
|
|
85
|
+
REMOTE_HUB_PAIR_TOKEN: PAIR_TOKEN,
|
|
86
|
+
WORKSPACE_PATH: workspacePath,
|
|
87
|
+
NO_COLOR: '1'
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
let stdout = '';
|
|
92
|
+
let stderr = '';
|
|
93
|
+
child.stdout.on('data', chunk => {
|
|
94
|
+
stdout += chunk.toString();
|
|
95
|
+
});
|
|
96
|
+
child.stderr.on('data', chunk => {
|
|
97
|
+
stderr += chunk.toString();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const exitPromise = new Promise(resolve => child.once('exit', resolve));
|
|
101
|
+
const details = () => `${label} stdout=${stdout}\n${label} stderr=${stderr}`;
|
|
102
|
+
const stop = async () => {
|
|
103
|
+
if (child.exitCode === null && !child.killed) {
|
|
104
|
+
child.kill('SIGTERM');
|
|
105
|
+
await Promise.race([exitPromise, wait(5000)]);
|
|
106
|
+
if (child.exitCode === null && !child.killed) {
|
|
107
|
+
child.kill('SIGKILL');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
baseUrl: `http://127.0.0.1:${bridgePort}`,
|
|
114
|
+
child,
|
|
115
|
+
details,
|
|
116
|
+
stop
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function waitForBridge(bridge) {
|
|
121
|
+
return await waitFor(async () => {
|
|
122
|
+
const result = await fetchJson(`${bridge.baseUrl}/api/status`);
|
|
123
|
+
return result.ok && result.payload?.status === 'ok' ? result.payload : null;
|
|
124
|
+
}, 30000, `bridge startup\n${bridge.details()}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function loadPlaywrightChromium() {
|
|
128
|
+
const candidates = [
|
|
129
|
+
path.join(LOCAL_BRIDGE_DIR, 'node_modules', 'playwright', 'index.js'),
|
|
130
|
+
path.join(LOCAL_BRIDGE_DIR, 'node_modules', 'playwright-core', 'index.mjs'),
|
|
131
|
+
path.join(LOCAL_BRIDGE_DIR, 'node_modules', 'playwright-core', 'index.js')
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
let lastError = null;
|
|
135
|
+
for (const candidate of candidates) {
|
|
136
|
+
try {
|
|
137
|
+
const mod = await import(pathToFileURL(candidate).href);
|
|
138
|
+
if (mod.chromium) {
|
|
139
|
+
return mod.chromium;
|
|
140
|
+
}
|
|
141
|
+
} catch (error) {
|
|
142
|
+
lastError = error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
throw new Error(`Playwright chromium is unavailable: ${lastError?.message || 'not installed'}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function launchBrowser(chromium) {
|
|
150
|
+
const launchers = [
|
|
151
|
+
() => chromium.launch({ channel: 'chrome', headless: true }),
|
|
152
|
+
() => chromium.launch({ channel: 'msedge', headless: true }),
|
|
153
|
+
() => chromium.launch({ headless: true })
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
let lastError = null;
|
|
157
|
+
for (const launch of launchers) {
|
|
158
|
+
try {
|
|
159
|
+
return await launch();
|
|
160
|
+
} catch (error) {
|
|
161
|
+
lastError = error;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
throw new Error(`Unable to launch a Chromium browser: ${lastError?.message || 'unknown error'}`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function paintRemoteFramesInBrowser(page, wsUrl, deviceId, fps = REQUESTED_FPS) {
|
|
169
|
+
await page.setContent(`
|
|
170
|
+
<!doctype html>
|
|
171
|
+
<meta charset="utf-8">
|
|
172
|
+
<canvas id="screen" width="320" height="180"></canvas>
|
|
173
|
+
`);
|
|
174
|
+
|
|
175
|
+
return await page.evaluate(async ({ wsUrl, deviceId, fps, sampleMs, minPaintFps }) => {
|
|
176
|
+
const canvas = document.getElementById('screen');
|
|
177
|
+
const context = canvas.getContext('2d', { alpha: false, desynchronized: true }) || canvas.getContext('2d');
|
|
178
|
+
if (!context) {
|
|
179
|
+
throw new Error('canvas-2d-context-unavailable');
|
|
180
|
+
}
|
|
181
|
+
if (typeof createImageBitmap !== 'function') {
|
|
182
|
+
throw new Error('createImageBitmap-unavailable');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function parsePacket(buffer) {
|
|
186
|
+
const view = new DataView(buffer);
|
|
187
|
+
const metaLength = view.getUint32(0);
|
|
188
|
+
if (!Number.isFinite(metaLength) || metaLength <= 0 || metaLength > 64 * 1024 || 4 + metaLength >= buffer.byteLength) {
|
|
189
|
+
throw new Error('invalid-frame-packet');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const metadataBytes = new Uint8Array(buffer, 4, metaLength);
|
|
193
|
+
const metadata = JSON.parse(new TextDecoder().decode(metadataBytes));
|
|
194
|
+
const payload = buffer.slice(4 + metaLength);
|
|
195
|
+
return { metadata, payload };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return await new Promise((resolve, reject) => {
|
|
199
|
+
const timeout = setTimeout(() => {
|
|
200
|
+
try {
|
|
201
|
+
ws?.close();
|
|
202
|
+
} catch {
|
|
203
|
+
// ignore close failure
|
|
204
|
+
}
|
|
205
|
+
reject(new Error('timed-out-waiting-for-mdm-frames'));
|
|
206
|
+
}, 20000);
|
|
207
|
+
const ws = new WebSocket(wsUrl);
|
|
208
|
+
const painted = [];
|
|
209
|
+
const receivedSeqs = [];
|
|
210
|
+
let firstPaintAt = 0;
|
|
211
|
+
let lastPaintAt = 0;
|
|
212
|
+
let processing = false;
|
|
213
|
+
let pendingPacket = null;
|
|
214
|
+
let settled = false;
|
|
215
|
+
|
|
216
|
+
function finishIfReady() {
|
|
217
|
+
if (settled || painted.length < 2 || !firstPaintAt || !lastPaintAt) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const elapsedMs = lastPaintAt - firstPaintAt;
|
|
222
|
+
if (elapsedMs < sampleMs) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const paintedSeqs = painted.map(item => item.frameSeq);
|
|
227
|
+
const uniqueSeqs = new Set(paintedSeqs);
|
|
228
|
+
let maxPaintSeqGap = 0;
|
|
229
|
+
for (let index = 1; index < paintedSeqs.length; index += 1) {
|
|
230
|
+
maxPaintSeqGap = Math.max(maxPaintSeqGap, Math.max(0, paintedSeqs[index] - paintedSeqs[index - 1] - 1));
|
|
231
|
+
}
|
|
232
|
+
const receivedUniqueSeqs = new Set(receivedSeqs);
|
|
233
|
+
const firstReceivedSeq = receivedSeqs[0] || 0;
|
|
234
|
+
const lastReceivedSeq = receivedSeqs[receivedSeqs.length - 1] || 0;
|
|
235
|
+
const expectedReceivedSeqs = lastReceivedSeq >= firstReceivedSeq
|
|
236
|
+
? lastReceivedSeq - firstReceivedSeq + 1
|
|
237
|
+
: receivedUniqueSeqs.size;
|
|
238
|
+
const streamDroppedSeqs = Math.max(0, expectedReceivedSeqs - receivedUniqueSeqs.size);
|
|
239
|
+
const paintDroppedSeqs = Math.max(0, receivedUniqueSeqs.size - uniqueSeqs.size);
|
|
240
|
+
const paintDropRatio = receivedUniqueSeqs.size > 0
|
|
241
|
+
? paintDroppedSeqs / receivedUniqueSeqs.size
|
|
242
|
+
: 0;
|
|
243
|
+
const paintFps = painted.length > 1
|
|
244
|
+
? ((painted.length - 1) * 1000) / Math.max(1, elapsedMs)
|
|
245
|
+
: 0;
|
|
246
|
+
if (paintFps < minPaintFps) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
settled = true;
|
|
251
|
+
clearTimeout(timeout);
|
|
252
|
+
ws.onclose = null;
|
|
253
|
+
try {
|
|
254
|
+
ws.close();
|
|
255
|
+
} catch {
|
|
256
|
+
// ignore close failure
|
|
257
|
+
}
|
|
258
|
+
resolve({
|
|
259
|
+
framesReceived: receivedSeqs.length,
|
|
260
|
+
uniqueFramesReceived: receivedUniqueSeqs.size,
|
|
261
|
+
expectedFramesReceived: expectedReceivedSeqs,
|
|
262
|
+
streamDroppedSeqs,
|
|
263
|
+
paintDroppedSeqs,
|
|
264
|
+
paintDropRatio,
|
|
265
|
+
framesPainted: painted.length,
|
|
266
|
+
uniqueSeqs: uniqueSeqs.size,
|
|
267
|
+
maxPaintSeqGap,
|
|
268
|
+
firstSeq: painted[0]?.frameSeq || 0,
|
|
269
|
+
lastSeq: painted[painted.length - 1]?.frameSeq || 0,
|
|
270
|
+
durationMs: elapsedMs,
|
|
271
|
+
paintFps,
|
|
272
|
+
fps: painted[painted.length - 1]?.fps || 0,
|
|
273
|
+
width: painted[painted.length - 1]?.width || 0,
|
|
274
|
+
height: painted[painted.length - 1]?.height || 0,
|
|
275
|
+
minBytes: Math.min(...painted.map(item => item.byteLength).filter(value => value > 0)),
|
|
276
|
+
maxBytes: Math.max(...painted.map(item => item.byteLength).filter(value => value > 0)),
|
|
277
|
+
mimeType: painted[painted.length - 1]?.mimeType || '',
|
|
278
|
+
transport: painted[painted.length - 1]?.transport || ''
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
async function paintPacket(packet) {
|
|
283
|
+
const { metadata, payload } = packet;
|
|
284
|
+
const blob = new Blob([payload], { type: metadata.mimeType || 'image/jpeg' });
|
|
285
|
+
const bitmap = await createImageBitmap(blob);
|
|
286
|
+
context.drawImage(bitmap, 0, 0, canvas.width, canvas.height);
|
|
287
|
+
bitmap.close?.();
|
|
288
|
+
const now = performance.now();
|
|
289
|
+
const frameSeq = Number(metadata.frameSeq || 0);
|
|
290
|
+
if (!firstPaintAt) {
|
|
291
|
+
firstPaintAt = now;
|
|
292
|
+
}
|
|
293
|
+
lastPaintAt = now;
|
|
294
|
+
painted.push({
|
|
295
|
+
frameSeq,
|
|
296
|
+
fps: Number(metadata.fps || 0),
|
|
297
|
+
width: Number(metadata.width || 0),
|
|
298
|
+
height: Number(metadata.height || 0),
|
|
299
|
+
byteLength: Number(metadata.byteLength || payload.byteLength || 0),
|
|
300
|
+
mimeType: String(metadata.mimeType || ''),
|
|
301
|
+
transport: String(metadata.transport || '')
|
|
302
|
+
});
|
|
303
|
+
finishIfReady();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async function processLatest(packet) {
|
|
307
|
+
pendingPacket = packet;
|
|
308
|
+
if (processing) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
processing = true;
|
|
313
|
+
try {
|
|
314
|
+
while (pendingPacket && !settled) {
|
|
315
|
+
const next = pendingPacket;
|
|
316
|
+
pendingPacket = null;
|
|
317
|
+
await paintPacket(next);
|
|
318
|
+
}
|
|
319
|
+
} catch (error) {
|
|
320
|
+
settled = true;
|
|
321
|
+
clearTimeout(timeout);
|
|
322
|
+
try {
|
|
323
|
+
ws.close();
|
|
324
|
+
} catch {
|
|
325
|
+
// ignore close failure
|
|
326
|
+
}
|
|
327
|
+
reject(error);
|
|
328
|
+
} finally {
|
|
329
|
+
processing = false;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
ws.binaryType = 'arraybuffer';
|
|
334
|
+
ws.onopen = () => {
|
|
335
|
+
ws.send(JSON.stringify({
|
|
336
|
+
type: 'subscribe',
|
|
337
|
+
deviceIds: [deviceId],
|
|
338
|
+
autoStartLive: true,
|
|
339
|
+
fps,
|
|
340
|
+
maxWidth: 960,
|
|
341
|
+
maxHeight: 540,
|
|
342
|
+
quality: 60
|
|
343
|
+
}));
|
|
344
|
+
};
|
|
345
|
+
ws.onerror = () => {
|
|
346
|
+
clearTimeout(timeout);
|
|
347
|
+
reject(new Error('remote-frame-websocket-error'));
|
|
348
|
+
};
|
|
349
|
+
ws.onclose = () => {
|
|
350
|
+
clearTimeout(timeout);
|
|
351
|
+
reject(new Error('remote-frame-websocket-closed-before-paint'));
|
|
352
|
+
};
|
|
353
|
+
ws.onmessage = async event => {
|
|
354
|
+
if (typeof event.data === 'string') {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
try {
|
|
359
|
+
const { metadata, payload } = parsePacket(event.data);
|
|
360
|
+
if (String(metadata.type || '').toLowerCase() !== 'remote.frame.binary'
|
|
361
|
+
|| String(metadata.kind || '').toLowerCase() !== 'live'
|
|
362
|
+
|| String(metadata.deviceId || '') !== deviceId) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (metadata.dataUrl || metadata.framePath || metadata.frameUrl) {
|
|
367
|
+
throw new Error('binary-ws-metadata-must-not-carry-frame-url-or-data-url');
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
receivedSeqs.push(Number(metadata.frameSeq || 0));
|
|
371
|
+
await processLatest({ metadata, payload });
|
|
372
|
+
} catch (error) {
|
|
373
|
+
if (!settled) {
|
|
374
|
+
settled = true;
|
|
375
|
+
clearTimeout(timeout);
|
|
376
|
+
try {
|
|
377
|
+
ws.close();
|
|
378
|
+
} catch {
|
|
379
|
+
// ignore close failure
|
|
380
|
+
}
|
|
381
|
+
reject(error);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
});
|
|
386
|
+
}, { wsUrl, deviceId, fps, sampleMs: SAMPLE_MS, minPaintFps: MIN_PAINT_FPS });
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async function main() {
|
|
390
|
+
const tempRoot = await mkdtemp(path.join(os.tmpdir(), 'mindexec-remote-mdm-browser-'));
|
|
391
|
+
const hostWorkspace = path.join(tempRoot, 'host');
|
|
392
|
+
const clientWorkspace = path.join(tempRoot, 'client');
|
|
393
|
+
const hostBridgePort = await findFreePort();
|
|
394
|
+
const hostRemotePort = await findFreePort();
|
|
395
|
+
const clientBridgePort = await findFreePort();
|
|
396
|
+
const clientRemotePort = await findFreePort();
|
|
397
|
+
const managerEndpoint = `127.0.0.1:${hostRemotePort}`;
|
|
398
|
+
let hostBridge = null;
|
|
399
|
+
let clientBridge = null;
|
|
400
|
+
let browser = null;
|
|
401
|
+
|
|
402
|
+
try {
|
|
403
|
+
hostBridge = spawnBridge({
|
|
404
|
+
bridgePort: hostBridgePort,
|
|
405
|
+
remoteHubPort: hostRemotePort,
|
|
406
|
+
workspacePath: hostWorkspace,
|
|
407
|
+
label: 'host'
|
|
408
|
+
});
|
|
409
|
+
await waitForBridge(hostBridge);
|
|
410
|
+
|
|
411
|
+
clientBridge = spawnBridge({
|
|
412
|
+
bridgePort: clientBridgePort,
|
|
413
|
+
remoteHubPort: clientRemotePort,
|
|
414
|
+
workspacePath: clientWorkspace,
|
|
415
|
+
label: 'client',
|
|
416
|
+
traceFrames: true
|
|
417
|
+
});
|
|
418
|
+
await waitForBridge(clientBridge);
|
|
419
|
+
|
|
420
|
+
const connectResult = await fetchJson(`${clientBridge.baseUrl}/api/remote/agent/connect`, {
|
|
421
|
+
method: 'POST',
|
|
422
|
+
body: JSON.stringify({
|
|
423
|
+
managerCandidates: [managerEndpoint],
|
|
424
|
+
pairToken: PAIR_TOKEN,
|
|
425
|
+
leaseId: LEASE_ID,
|
|
426
|
+
nodeId: 'remote-fast-mdm-browser-node',
|
|
427
|
+
engine: 'auto',
|
|
428
|
+
source: 'mdm-browser-smoke'
|
|
429
|
+
})
|
|
430
|
+
});
|
|
431
|
+
assert.equal(connectResult.ok, true, JSON.stringify(connectResult.payload));
|
|
432
|
+
assert.equal(connectResult.payload?.ok, true, JSON.stringify(connectResult.payload));
|
|
433
|
+
assert.equal(connectResult.payload?.agent?.usingNpx, false, JSON.stringify(connectResult.payload?.agent));
|
|
434
|
+
assert.match(String(connectResult.payload?.agent?.launcher || ''), /mindexec-remote-fast/i);
|
|
435
|
+
|
|
436
|
+
const device = await waitFor(async () => {
|
|
437
|
+
const result = await fetchJson(`${hostBridge.baseUrl}/api/remote/devices`);
|
|
438
|
+
return result.payload?.devices?.find(item =>
|
|
439
|
+
item.connected === true
|
|
440
|
+
&& item.capabilities?.liveStream === true
|
|
441
|
+
&& item.capabilities?.binaryFrames === true) || null;
|
|
442
|
+
}, 15000, `RemoteFast device registration\n${hostBridge.details()}\n${clientBridge.details()}`);
|
|
443
|
+
|
|
444
|
+
const chromium = await loadPlaywrightChromium();
|
|
445
|
+
browser = await launchBrowser(chromium);
|
|
446
|
+
const page = await browser.newPage();
|
|
447
|
+
const wsUrl = `${hostBridge.baseUrl.replace(/^http:/, 'ws:')}/api/remote/frames/ws?token=${encodeURIComponent(BRIDGE_TOKEN)}`;
|
|
448
|
+
const painted = await paintRemoteFramesInBrowser(page, wsUrl, device.deviceId, REQUESTED_FPS);
|
|
449
|
+
assert.ok(painted.framesReceived >= painted.framesPainted, JSON.stringify(painted));
|
|
450
|
+
assert.ok(painted.framesPainted >= Math.max(4, Math.floor((SAMPLE_MS / 1000) * MIN_PAINT_FPS)), JSON.stringify(painted));
|
|
451
|
+
assert.ok(painted.uniqueSeqs >= painted.framesPainted - 1, JSON.stringify(painted));
|
|
452
|
+
assert.ok(painted.lastSeq > painted.firstSeq, JSON.stringify(painted));
|
|
453
|
+
assert.ok(painted.paintFps >= MIN_PAINT_FPS, JSON.stringify(painted));
|
|
454
|
+
assert.ok(painted.paintDropRatio <= MAX_PAINT_DROP_RATIO, JSON.stringify(painted));
|
|
455
|
+
assert.ok(painted.maxPaintSeqGap <= MAX_PAINT_SEQ_GAP, JSON.stringify(painted));
|
|
456
|
+
assert.equal(painted.fps, REQUESTED_FPS, JSON.stringify(painted));
|
|
457
|
+
assert.ok(painted.width > 0 && painted.height > 0, JSON.stringify(painted));
|
|
458
|
+
assert.ok(painted.minBytes > 0 && painted.maxBytes >= painted.minBytes, JSON.stringify(painted));
|
|
459
|
+
assert.match(painted.mimeType, /^image\/(jpeg|png|webp)$/i, JSON.stringify(painted));
|
|
460
|
+
|
|
461
|
+
console.log(`RemoteFast MDM browser smoke OK (${painted.framesPainted} paints, ${painted.paintFps.toFixed(1)} fps, paint drop ${(painted.paintDropRatio * 100).toFixed(1)}%, max gap ${painted.maxPaintSeqGap}, seq ${painted.firstSeq}-${painted.lastSeq}, ${painted.width}x${painted.height}, ${painted.minBytes}-${painted.maxBytes} bytes)`);
|
|
462
|
+
} finally {
|
|
463
|
+
if (browser) {
|
|
464
|
+
await browser.close().catch(() => undefined);
|
|
465
|
+
}
|
|
466
|
+
if (clientBridge) {
|
|
467
|
+
await clientBridge.stop();
|
|
468
|
+
}
|
|
469
|
+
if (hostBridge) {
|
|
470
|
+
await hostBridge.stop();
|
|
471
|
+
}
|
|
472
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
await main();
|