@micromag/recorder 0.3.773 → 0.3.781
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/bin/recorder.js +226 -0
- package/build/asset-manifest.json +4 -4
- package/build/index.html +1 -1
- package/build/static/css/main.ca64b2c9.css +1 -0
- package/build/static/js/main.625b5b04.js +2 -0
- package/build/static/js/main.625b5b04.js.LICENSE.txt +3 -0
- package/package.json +12 -6
- package/build/static/css/main.3498d93a.css +0 -1
- package/build/static/js/main.2764f455.js +0 -2
- package/build/static/js/main.2764f455.js.LICENSE.txt +0 -1
package/bin/recorder.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var puppeteer = require('puppeteer');
|
|
6
|
+
var puppeteerScreenRecorder = require('puppeteer-screen-recorder');
|
|
7
|
+
var express = require('express');
|
|
8
|
+
var net = require('node:net');
|
|
9
|
+
var os = require('node:os');
|
|
10
|
+
|
|
11
|
+
class Locked extends Error {
|
|
12
|
+
constructor(port) {
|
|
13
|
+
super(`${port} is locked`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const lockedPorts = {
|
|
18
|
+
old: new Set(),
|
|
19
|
+
young: new Set(),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// On this interval, the old locked ports are discarded,
|
|
23
|
+
// the young locked ports are moved to old locked ports,
|
|
24
|
+
// and a new young set for locked ports are created.
|
|
25
|
+
const releaseOldLockedPortsIntervalMs = 1000 * 15;
|
|
26
|
+
|
|
27
|
+
// Lazily create timeout on first use
|
|
28
|
+
let timeout;
|
|
29
|
+
|
|
30
|
+
const getLocalHosts = () => {
|
|
31
|
+
const interfaces = os.networkInterfaces();
|
|
32
|
+
|
|
33
|
+
// Add undefined value for createServer function to use default host,
|
|
34
|
+
// and default IPv4 host in case createServer defaults to IPv6.
|
|
35
|
+
const results = new Set([undefined, '0.0.0.0']);
|
|
36
|
+
|
|
37
|
+
for (const _interface of Object.values(interfaces)) {
|
|
38
|
+
for (const config of _interface) {
|
|
39
|
+
results.add(config.address);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return results;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const checkAvailablePort = options =>
|
|
47
|
+
new Promise((resolve, reject) => {
|
|
48
|
+
const server = net.createServer();
|
|
49
|
+
server.unref();
|
|
50
|
+
server.on('error', reject);
|
|
51
|
+
|
|
52
|
+
server.listen(options, () => {
|
|
53
|
+
const {port} = server.address();
|
|
54
|
+
server.close(() => {
|
|
55
|
+
resolve(port);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const getAvailablePort = async (options, hosts) => {
|
|
61
|
+
if (options.host || options.port === 0) {
|
|
62
|
+
return checkAvailablePort(options);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (const host of hosts) {
|
|
66
|
+
try {
|
|
67
|
+
await checkAvailablePort({port: options.port, host}); // eslint-disable-line no-await-in-loop
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (!['EADDRNOTAVAIL', 'EINVAL'].includes(error.code)) {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return options.port;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const portCheckSequence = function * (ports) {
|
|
79
|
+
if (ports) {
|
|
80
|
+
yield * ports;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
yield 0; // Fall back to 0 if anything else failed
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
async function getPorts(options) {
|
|
87
|
+
let ports;
|
|
88
|
+
let exclude = new Set();
|
|
89
|
+
|
|
90
|
+
if (options) {
|
|
91
|
+
if (options.port) {
|
|
92
|
+
ports = typeof options.port === 'number' ? [options.port] : options.port;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (options.exclude) {
|
|
96
|
+
const excludeIterable = options.exclude;
|
|
97
|
+
|
|
98
|
+
if (typeof excludeIterable[Symbol.iterator] !== 'function') {
|
|
99
|
+
throw new TypeError('The `exclude` option must be an iterable.');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for (const element of excludeIterable) {
|
|
103
|
+
if (typeof element !== 'number') {
|
|
104
|
+
throw new TypeError('Each item in the `exclude` option must be a number corresponding to the port you want excluded.');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!Number.isSafeInteger(element)) {
|
|
108
|
+
throw new TypeError(`Number ${element} in the exclude option is not a safe integer and can't be used`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
exclude = new Set(excludeIterable);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (timeout === undefined) {
|
|
117
|
+
timeout = setTimeout(() => {
|
|
118
|
+
timeout = undefined;
|
|
119
|
+
|
|
120
|
+
lockedPorts.old = lockedPorts.young;
|
|
121
|
+
lockedPorts.young = new Set();
|
|
122
|
+
}, releaseOldLockedPortsIntervalMs);
|
|
123
|
+
|
|
124
|
+
// Does not exist in some environments (Electron, Jest jsdom env, browser, etc).
|
|
125
|
+
if (timeout.unref) {
|
|
126
|
+
timeout.unref();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const hosts = getLocalHosts();
|
|
131
|
+
|
|
132
|
+
for (const port of portCheckSequence(ports)) {
|
|
133
|
+
try {
|
|
134
|
+
if (exclude.has(port)) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let availablePort = await getAvailablePort({...options, port}, hosts); // eslint-disable-line no-await-in-loop
|
|
139
|
+
while (lockedPorts.old.has(availablePort) || lockedPorts.young.has(availablePort)) {
|
|
140
|
+
if (port !== 0) {
|
|
141
|
+
throw new Locked(port);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
availablePort = await getAvailablePort({...options, port}, hosts); // eslint-disable-line no-await-in-loop
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
lockedPorts.young.add(availablePort);
|
|
148
|
+
|
|
149
|
+
return availablePort;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (!['EADDRINUSE', 'EACCES'].includes(error.code) && !(error instanceof Locked)) {
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
throw new Error('No available ports found');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function portNumbers(from, to) {
|
|
161
|
+
if (!Number.isInteger(from) || !Number.isInteger(to)) {
|
|
162
|
+
throw new TypeError('`from` and `to` must be integer numbers');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const generator = function * (from, to) {
|
|
166
|
+
for (let port = from; port <= to; port++) {
|
|
167
|
+
yield port;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
return generator(from, to);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const startServer = async (path, port = null) => {
|
|
175
|
+
const finalPort =
|
|
176
|
+
port ||
|
|
177
|
+
(await getPorts({
|
|
178
|
+
port: portNumbers(3050, 3100),
|
|
179
|
+
}));
|
|
180
|
+
return new Promise((resolve) => {
|
|
181
|
+
const app = express();
|
|
182
|
+
app.use(express.static(path));
|
|
183
|
+
const server = app.listen(finalPort, () => resolve(server));
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
async function wait(ms) {
|
|
188
|
+
return new Promise((resolve) => {
|
|
189
|
+
setTimeout(() => resolve(), ms);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async function startRecorder({ fileOutput = './exports/micromag.mp4' } = {}) {
|
|
194
|
+
const server = await startServer(path.join(__dirname, '../build/'));
|
|
195
|
+
const serverPort = server.address().port;
|
|
196
|
+
console.log(`Server started at http://localhost:${serverPort}`);
|
|
197
|
+
|
|
198
|
+
const browser = await puppeteer.launch({
|
|
199
|
+
defaultViewport: {
|
|
200
|
+
width: 540,
|
|
201
|
+
height: 860,
|
|
202
|
+
deviceScaleFactor: 2,
|
|
203
|
+
isMobile: true,
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
const page = await browser.newPage();
|
|
207
|
+
const recorder = new puppeteerScreenRecorder.PuppeteerScreenRecorder(page, {
|
|
208
|
+
videoFrame: {
|
|
209
|
+
width: 1080,
|
|
210
|
+
height: 1920,
|
|
211
|
+
},
|
|
212
|
+
fps: 30,
|
|
213
|
+
aspectRatio: '9:16',
|
|
214
|
+
});
|
|
215
|
+
await page.goto(`http://localhost:${serverPort}`);
|
|
216
|
+
await page.waitForSelector('[data-screen-ready="true"]', {
|
|
217
|
+
timeout: 10000,
|
|
218
|
+
});
|
|
219
|
+
await recorder.start(fileOutput); // supports extension - mp4, avi, webm and mov
|
|
220
|
+
await wait(5000);
|
|
221
|
+
await recorder.stop();
|
|
222
|
+
await browser.close();
|
|
223
|
+
await server.close();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
startRecorder();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": {
|
|
3
|
-
"main.css": "/static/css/main.
|
|
4
|
-
"main.js": "/static/js/main.
|
|
3
|
+
"main.css": "/static/css/main.ca64b2c9.css",
|
|
4
|
+
"main.js": "/static/js/main.625b5b04.js",
|
|
5
5
|
"runtime~main.js": "/static/js/runtime~main.0244fc2b.js",
|
|
6
6
|
"static/js/66.b625dcf2.chunk.js": "/static/js/66.b625dcf2.chunk.js",
|
|
7
7
|
"static/js/490.c32acdcb.chunk.js": "/static/js/490.c32acdcb.chunk.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"entrypoints": [
|
|
14
14
|
"static/js/runtime~main.0244fc2b.js",
|
|
15
15
|
"static/js/31.4440a2ab.js",
|
|
16
|
-
"static/css/main.
|
|
17
|
-
"static/js/main.
|
|
16
|
+
"static/css/main.ca64b2c9.css",
|
|
17
|
+
"static/js/main.625b5b04.js"
|
|
18
18
|
]
|
|
19
19
|
}
|
package/build/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Micromag</title><script defer="defer" src="/static/js/runtime~main.0244fc2b.js"></script><script defer="defer" src="/static/js/31.4440a2ab.js"></script><script defer="defer" src="/static/js/main.
|
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Micromag</title><style>#root,body,html{margin:0;padding:0;height:100%;width:100%}body{background:#000}.micromag{position:fixed;top:0;left:0;width:100%;height:100%}</style><script defer="defer" src="/static/js/runtime~main.0244fc2b.js"></script><script defer="defer" src="/static/js/31.4440a2ab.js"></script><script defer="defer" src="/static/js/main.625b5b04.js"></script><link href="/static/css/main.ca64b2c9.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
|