@openartifactsai/motion-stage 0.23.0-rc.0 → 0.23.0
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/package.json +4 -3
- package/src/stills.js +24 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openartifactsai/motion-stage",
|
|
3
|
-
"version": "0.23.0
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "The Motion stage runtime: the sandboxed in-frame player that runs a film's code (kit, scenes, score recorder, captions, snapshots, text scan), built into one classic script, with its message protocol, a Vite plugin that gives the page the script, and a standalone player.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -47,8 +47,9 @@
|
|
|
47
47
|
"NOTICE"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@openartifactsai/motion-audio": "0.23.0
|
|
51
|
-
"@openartifactsai/motion-core": "0.23.0
|
|
50
|
+
"@openartifactsai/motion-audio": "0.23.0",
|
|
51
|
+
"@openartifactsai/motion-core": "0.23.0",
|
|
52
|
+
"@openartifactsai/server-sdk": "0.23.0",
|
|
52
53
|
"esbuild": "^0.25.12",
|
|
53
54
|
"vite": "^7.3.8"
|
|
54
55
|
},
|
package/src/stills.js
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
* itself, so it installs nothing. Shared by `scripts/stills.mjs` and the `open-artifacts stills` command.
|
|
6
6
|
*/
|
|
7
7
|
import { spawn } from 'node:child_process';
|
|
8
|
-
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync,
|
|
8
|
+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
9
9
|
import { homedir, tmpdir } from 'node:os';
|
|
10
10
|
import { join, resolve } from 'node:path';
|
|
11
11
|
import { pathToFileURL } from 'node:url';
|
|
12
|
+
import { stopChild } from '@openartifactsai/server-sdk/child';
|
|
13
|
+
import { closeBrowserAt, removeProfile, waitForDevTools } from '@openartifactsai/server-sdk/chrome';
|
|
12
14
|
import { BAND_TRACKS, documentsInViewRatio, filmExtraRatios, FILM_COLLECTIONS, isPlainObject, readFilmVersions, VERSION_COLLECTIONS, versionFilmDocuments } from '@openartifactsai/motion-core';
|
|
13
15
|
/** A stills request that cannot be met: printed as it is, without a stack. */
|
|
14
16
|
export class StillsError extends Error {
|
|
@@ -165,28 +167,20 @@ const CHROMIUM_ARGS = [
|
|
|
165
167
|
'--proxy-server=http://127.0.0.1:9',
|
|
166
168
|
'--proxy-bypass-list=<-loopback>',
|
|
167
169
|
];
|
|
170
|
+
/**
|
|
171
|
+
* Starts Chromium on `profile`; `child` is known at once, `url` (its DevTools address) once it says where it serves.
|
|
172
|
+
* The browser may be a process this one never started (see server-sdk's chrome.ts): it is ended over DevTools.
|
|
173
|
+
*/
|
|
168
174
|
function launch(binary, profile) {
|
|
169
175
|
// Keep this temporary profile independent of the macOS login keychain: under a HOME that has none, Chrome stops to
|
|
170
176
|
// ask the person for one.
|
|
171
177
|
const keychain = process.platform === 'darwin' ? ['--use-mock-keychain'] : [];
|
|
172
178
|
const child = spawn(binary, [...CHROMIUM_ARGS, ...keychain, '--user-data-dir=' + profile, 'about:blank'], { stdio: ['ignore', 'ignore', 'pipe'] });
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
child.stderr?.on('data', (chunk) => {
|
|
177
|
-
said += String(chunk);
|
|
178
|
-
const url = /DevTools listening on (ws:\/\/\S+)/.exec(said)?.[1];
|
|
179
|
-
if (url === undefined)
|
|
180
|
-
return;
|
|
181
|
-
clearTimeout(timer);
|
|
182
|
-
done({ child, url });
|
|
183
|
-
});
|
|
184
|
-
child.on('error', (error) => {
|
|
185
|
-
clearTimeout(timer);
|
|
186
|
-
fail(error);
|
|
187
|
-
});
|
|
188
|
-
child.on('exit', (code) => fail(new Error('Chromium exited (' + String(code) + '):\n' + said.slice(-2000))));
|
|
179
|
+
let said = '';
|
|
180
|
+
child.stderr?.on('data', (chunk) => {
|
|
181
|
+
said += String(chunk);
|
|
189
182
|
});
|
|
183
|
+
return { child, url: waitForDevTools({ child, profile, stderr: () => said, timeoutMs: 30000, name: 'Chromium' }) };
|
|
190
184
|
}
|
|
191
185
|
/** The DevTools protocol over one WebSocket, commands sent to one page's session. */
|
|
192
186
|
async function connect(url) {
|
|
@@ -222,8 +216,7 @@ async function connect(url) {
|
|
|
222
216
|
throw new Error(exceptionDetails.exception?.description ?? exceptionDetails.text);
|
|
223
217
|
return result.value;
|
|
224
218
|
},
|
|
225
|
-
|
|
226
|
-
await send('Browser.close').catch(() => undefined);
|
|
219
|
+
close() {
|
|
227
220
|
socket.close();
|
|
228
221
|
},
|
|
229
222
|
};
|
|
@@ -267,11 +260,13 @@ export async function drawStills(request, toolsPage, say = (line) => console.log
|
|
|
267
260
|
say(text);
|
|
268
261
|
};
|
|
269
262
|
let child = null;
|
|
263
|
+
let url = null;
|
|
270
264
|
let browser = null;
|
|
271
265
|
try {
|
|
272
|
-
const launched =
|
|
266
|
+
const launched = launch(binary, join(work, 'profile'));
|
|
273
267
|
child = launched.child;
|
|
274
|
-
|
|
268
|
+
url = await launched.url;
|
|
269
|
+
browser = await connect(url);
|
|
275
270
|
await browser.navigate(pathToFileURL(page).href);
|
|
276
271
|
for (let i = 0; i < 100 && (await browser.evaluate('typeof window.filmTools')) !== 'object'; i++)
|
|
277
272
|
await new Promise((next) => setTimeout(next, 100));
|
|
@@ -317,13 +312,13 @@ export async function drawStills(request, toolsPage, say = (line) => console.log
|
|
|
317
312
|
return 1;
|
|
318
313
|
}
|
|
319
314
|
finally {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
});
|
|
327
|
-
|
|
315
|
+
// The browser first, over DevTools, then the child started (gone already when the browser started itself again),
|
|
316
|
+
// then the folder its profile is in, which a browser just closed can still hold for a moment.
|
|
317
|
+
browser?.close();
|
|
318
|
+
if (url !== null)
|
|
319
|
+
await closeBrowserAt(url);
|
|
320
|
+
if (child !== null)
|
|
321
|
+
await stopChild(child, { graceMs: 3000 });
|
|
322
|
+
removeProfile(work);
|
|
328
323
|
}
|
|
329
324
|
}
|