@midscene/android-playground 1.9.5-beta-20260611045217.0 → 1.9.5
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/dist/es/bin.mjs +53 -12
- package/dist/es/index.mjs +53 -12
- package/dist/lib/bin.js +60 -19
- package/dist/lib/index.js +60 -19
- package/dist/types/timeout.d.ts +10 -1
- package/package.json +5 -5
- package/static/index.html +1 -1
- package/static/static/js/{index.314454e7.js → index.89a1aec8.js} +63 -60
- package/static/static/js/index.89a1aec8.js.map +1 -0
- package/static/static/js/index.314454e7.js.map +0 -1
- /package/static/static/js/{index.314454e7.js.LICENSE.txt → index.89a1aec8.js.LICENSE.txt} +0 -0
package/dist/es/bin.mjs
CHANGED
|
@@ -12,7 +12,6 @@ import { getDebug } from "@midscene/shared/logger";
|
|
|
12
12
|
import cors from "cors";
|
|
13
13
|
import express from "express";
|
|
14
14
|
import { Server } from "socket.io";
|
|
15
|
-
import { withTimeout } from "@midscene/shared/timeout";
|
|
16
15
|
async function getAdbTargets() {
|
|
17
16
|
const devices = await getConnectedDevicesWithDetails();
|
|
18
17
|
return devices.filter((device)=>'device' === device.state).map((device, index)=>({
|
|
@@ -175,6 +174,48 @@ function _define_property(obj, key, value) {
|
|
|
175
174
|
else obj[key] = value;
|
|
176
175
|
return obj;
|
|
177
176
|
}
|
|
177
|
+
class PromiseTimeoutError extends Error {
|
|
178
|
+
constructor(message, timeoutMs){
|
|
179
|
+
super(message), _define_property(this, "timeoutMs", void 0);
|
|
180
|
+
this.name = 'PromiseTimeoutError';
|
|
181
|
+
this.timeoutMs = timeoutMs;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function runTimeoutCallback(callback, context) {
|
|
185
|
+
if (!callback) return;
|
|
186
|
+
Promise.resolve().then(callback).catch((error)=>{
|
|
187
|
+
console.error(`Failed to run ${context}:`, error);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
function withTimeout(promise, timeoutMs, message, options = {}) {
|
|
191
|
+
return new Promise((resolve, reject)=>{
|
|
192
|
+
let timedOut = false;
|
|
193
|
+
const timer = setTimeout(()=>{
|
|
194
|
+
timedOut = true;
|
|
195
|
+
runTimeoutCallback(options.onTimeout, 'timeout callback');
|
|
196
|
+
reject(new PromiseTimeoutError(message, timeoutMs));
|
|
197
|
+
}, timeoutMs);
|
|
198
|
+
Promise.resolve(promise).then((value)=>{
|
|
199
|
+
clearTimeout(timer);
|
|
200
|
+
if (timedOut) return void runTimeoutCallback(()=>options.onSettledAfterTimeout?.(value), 'post-timeout settle callback');
|
|
201
|
+
resolve(value);
|
|
202
|
+
}, (error)=>{
|
|
203
|
+
clearTimeout(timer);
|
|
204
|
+
if (timedOut) return void runTimeoutCallback(()=>options.onRejectedAfterTimeout?.(error), 'post-timeout rejection callback');
|
|
205
|
+
reject(error);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function scrcpy_server_define_property(obj, key, value) {
|
|
210
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
211
|
+
value: value,
|
|
212
|
+
enumerable: true,
|
|
213
|
+
configurable: true,
|
|
214
|
+
writable: true
|
|
215
|
+
});
|
|
216
|
+
else obj[key] = value;
|
|
217
|
+
return obj;
|
|
218
|
+
}
|
|
178
219
|
const debugPage = getDebug('android:playground');
|
|
179
220
|
const promiseExec = promisify(exec);
|
|
180
221
|
const LOOPBACK_HOSTS = new Set([
|
|
@@ -565,17 +606,17 @@ class ScrcpyServer {
|
|
|
565
606
|
if (this.httpServer?.listening) return this.httpServer.close();
|
|
566
607
|
}
|
|
567
608
|
constructor(options = {}){
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
609
|
+
scrcpy_server_define_property(this, "app", void 0);
|
|
610
|
+
scrcpy_server_define_property(this, "httpServer", void 0);
|
|
611
|
+
scrcpy_server_define_property(this, "io", void 0);
|
|
612
|
+
scrcpy_server_define_property(this, "port", void 0);
|
|
613
|
+
scrcpy_server_define_property(this, "defaultPort", SCRCPY_SERVER_PORT);
|
|
614
|
+
scrcpy_server_define_property(this, "adbClient", null);
|
|
615
|
+
scrcpy_server_define_property(this, "currentDeviceId", null);
|
|
616
|
+
scrcpy_server_define_property(this, "devicePollInterval", null);
|
|
617
|
+
scrcpy_server_define_property(this, "deviceListSource", void 0);
|
|
618
|
+
scrcpy_server_define_property(this, "deviceListSourceUnsubscribe", void 0);
|
|
619
|
+
scrcpy_server_define_property(this, "lastDeviceList", '');
|
|
579
620
|
this.deviceListSource = options.deviceListSource;
|
|
580
621
|
this.app = express();
|
|
581
622
|
this.httpServer = createServer(this.app);
|
package/dist/es/index.mjs
CHANGED
|
@@ -12,7 +12,6 @@ import { getDebug } from "@midscene/shared/logger";
|
|
|
12
12
|
import cors from "cors";
|
|
13
13
|
import express from "express";
|
|
14
14
|
import { Server } from "socket.io";
|
|
15
|
-
import { withTimeout } from "@midscene/shared/timeout";
|
|
16
15
|
async function getAdbTargets() {
|
|
17
16
|
const devices = await getConnectedDevicesWithDetails();
|
|
18
17
|
return devices.filter((device)=>'device' === device.state).map((device, index)=>({
|
|
@@ -175,6 +174,48 @@ function _define_property(obj, key, value) {
|
|
|
175
174
|
else obj[key] = value;
|
|
176
175
|
return obj;
|
|
177
176
|
}
|
|
177
|
+
class PromiseTimeoutError extends Error {
|
|
178
|
+
constructor(message, timeoutMs){
|
|
179
|
+
super(message), _define_property(this, "timeoutMs", void 0);
|
|
180
|
+
this.name = 'PromiseTimeoutError';
|
|
181
|
+
this.timeoutMs = timeoutMs;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function runTimeoutCallback(callback, context) {
|
|
185
|
+
if (!callback) return;
|
|
186
|
+
Promise.resolve().then(callback).catch((error)=>{
|
|
187
|
+
console.error(`Failed to run ${context}:`, error);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
function withTimeout(promise, timeoutMs, message, options = {}) {
|
|
191
|
+
return new Promise((resolve, reject)=>{
|
|
192
|
+
let timedOut = false;
|
|
193
|
+
const timer = setTimeout(()=>{
|
|
194
|
+
timedOut = true;
|
|
195
|
+
runTimeoutCallback(options.onTimeout, 'timeout callback');
|
|
196
|
+
reject(new PromiseTimeoutError(message, timeoutMs));
|
|
197
|
+
}, timeoutMs);
|
|
198
|
+
Promise.resolve(promise).then((value)=>{
|
|
199
|
+
clearTimeout(timer);
|
|
200
|
+
if (timedOut) return void runTimeoutCallback(()=>options.onSettledAfterTimeout?.(value), 'post-timeout settle callback');
|
|
201
|
+
resolve(value);
|
|
202
|
+
}, (error)=>{
|
|
203
|
+
clearTimeout(timer);
|
|
204
|
+
if (timedOut) return void runTimeoutCallback(()=>options.onRejectedAfterTimeout?.(error), 'post-timeout rejection callback');
|
|
205
|
+
reject(error);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function scrcpy_server_define_property(obj, key, value) {
|
|
210
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
211
|
+
value: value,
|
|
212
|
+
enumerable: true,
|
|
213
|
+
configurable: true,
|
|
214
|
+
writable: true
|
|
215
|
+
});
|
|
216
|
+
else obj[key] = value;
|
|
217
|
+
return obj;
|
|
218
|
+
}
|
|
178
219
|
const debugPage = getDebug('android:playground');
|
|
179
220
|
const promiseExec = promisify(exec);
|
|
180
221
|
const LOOPBACK_HOSTS = new Set([
|
|
@@ -565,17 +606,17 @@ class ScrcpyServer {
|
|
|
565
606
|
if (this.httpServer?.listening) return this.httpServer.close();
|
|
566
607
|
}
|
|
567
608
|
constructor(options = {}){
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
609
|
+
scrcpy_server_define_property(this, "app", void 0);
|
|
610
|
+
scrcpy_server_define_property(this, "httpServer", void 0);
|
|
611
|
+
scrcpy_server_define_property(this, "io", void 0);
|
|
612
|
+
scrcpy_server_define_property(this, "port", void 0);
|
|
613
|
+
scrcpy_server_define_property(this, "defaultPort", SCRCPY_SERVER_PORT);
|
|
614
|
+
scrcpy_server_define_property(this, "adbClient", null);
|
|
615
|
+
scrcpy_server_define_property(this, "currentDeviceId", null);
|
|
616
|
+
scrcpy_server_define_property(this, "devicePollInterval", null);
|
|
617
|
+
scrcpy_server_define_property(this, "deviceListSource", void 0);
|
|
618
|
+
scrcpy_server_define_property(this, "deviceListSourceUnsubscribe", void 0);
|
|
619
|
+
scrcpy_server_define_property(this, "lastDeviceList", '');
|
|
579
620
|
this.deviceListSource = options.deviceListSource;
|
|
580
621
|
this.app = express();
|
|
581
622
|
this.httpServer = createServer(this.app);
|
package/dist/lib/bin.js
CHANGED
|
@@ -190,7 +190,6 @@ function buildScrcpyPreviewStatusEvent(phase) {
|
|
|
190
190
|
message: getScrcpyPreviewStatusMessage(phase)
|
|
191
191
|
};
|
|
192
192
|
}
|
|
193
|
-
const timeout_namespaceObject = require("@midscene/shared/timeout");
|
|
194
193
|
function _define_property(obj, key, value) {
|
|
195
194
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
196
195
|
value: value,
|
|
@@ -201,6 +200,48 @@ function _define_property(obj, key, value) {
|
|
|
201
200
|
else obj[key] = value;
|
|
202
201
|
return obj;
|
|
203
202
|
}
|
|
203
|
+
class PromiseTimeoutError extends Error {
|
|
204
|
+
constructor(message, timeoutMs){
|
|
205
|
+
super(message), _define_property(this, "timeoutMs", void 0);
|
|
206
|
+
this.name = 'PromiseTimeoutError';
|
|
207
|
+
this.timeoutMs = timeoutMs;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function runTimeoutCallback(callback, context) {
|
|
211
|
+
if (!callback) return;
|
|
212
|
+
Promise.resolve().then(callback).catch((error)=>{
|
|
213
|
+
console.error(`Failed to run ${context}:`, error);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function withTimeout(promise, timeoutMs, message, options = {}) {
|
|
217
|
+
return new Promise((resolve, reject)=>{
|
|
218
|
+
let timedOut = false;
|
|
219
|
+
const timer = setTimeout(()=>{
|
|
220
|
+
timedOut = true;
|
|
221
|
+
runTimeoutCallback(options.onTimeout, 'timeout callback');
|
|
222
|
+
reject(new PromiseTimeoutError(message, timeoutMs));
|
|
223
|
+
}, timeoutMs);
|
|
224
|
+
Promise.resolve(promise).then((value)=>{
|
|
225
|
+
clearTimeout(timer);
|
|
226
|
+
if (timedOut) return void runTimeoutCallback(()=>options.onSettledAfterTimeout?.(value), 'post-timeout settle callback');
|
|
227
|
+
resolve(value);
|
|
228
|
+
}, (error)=>{
|
|
229
|
+
clearTimeout(timer);
|
|
230
|
+
if (timedOut) return void runTimeoutCallback(()=>options.onRejectedAfterTimeout?.(error), 'post-timeout rejection callback');
|
|
231
|
+
reject(error);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function scrcpy_server_define_property(obj, key, value) {
|
|
236
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
237
|
+
value: value,
|
|
238
|
+
enumerable: true,
|
|
239
|
+
configurable: true,
|
|
240
|
+
writable: true
|
|
241
|
+
});
|
|
242
|
+
else obj[key] = value;
|
|
243
|
+
return obj;
|
|
244
|
+
}
|
|
204
245
|
const debugPage = (0, logger_namespaceObject.getDebug)('android:playground');
|
|
205
246
|
const promiseExec = (0, external_node_util_namespaceObject.promisify)(external_node_child_process_namespaceObject.exec);
|
|
206
247
|
const LOOPBACK_HOSTS = new Set([
|
|
@@ -298,7 +339,7 @@ class ScrcpyServer {
|
|
|
298
339
|
try {
|
|
299
340
|
if (this.adbClient) debugPage('use existing adb client');
|
|
300
341
|
else {
|
|
301
|
-
await
|
|
342
|
+
await withTimeout(promiseExec('adb start-server'), constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS, `Timed out starting adb server after ${Math.round(constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS / 1000)}s`);
|
|
302
343
|
debugPage('adb server started');
|
|
303
344
|
debugPage('initialize adb client');
|
|
304
345
|
this.adbClient = new AdbServerClient(new AdbServerNodeTcpConnector({
|
|
@@ -321,14 +362,14 @@ class ScrcpyServer {
|
|
|
321
362
|
const targetDeviceId = deviceId || this.currentDeviceId;
|
|
322
363
|
if (targetDeviceId) {
|
|
323
364
|
this.currentDeviceId = targetDeviceId;
|
|
324
|
-
return new Adb(await
|
|
365
|
+
return new Adb(await withTimeout(client.createTransport({
|
|
325
366
|
serial: targetDeviceId
|
|
326
367
|
}), constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS, `Timed out connecting to Android device ${targetDeviceId} via ADB after ${Math.round(constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS / 1000)}s`));
|
|
327
368
|
}
|
|
328
|
-
const devices = await
|
|
369
|
+
const devices = await withTimeout(client.getDevices(), constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS, `Timed out listing Android devices via ADB after ${Math.round(constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS / 1000)}s`);
|
|
329
370
|
if (0 === devices.length) return null;
|
|
330
371
|
this.currentDeviceId = devices[0].serial;
|
|
331
|
-
return new Adb(await
|
|
372
|
+
return new Adb(await withTimeout(client.createTransport(devices[0]), constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS, `Timed out connecting to Android device ${devices[0].serial} via ADB after ${Math.round(constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS / 1000)}s`));
|
|
332
373
|
} catch (error) {
|
|
333
374
|
console.error('failed to get adb client:', error);
|
|
334
375
|
throw error;
|
|
@@ -342,7 +383,7 @@ class ScrcpyServer {
|
|
|
342
383
|
const serverBinPath = external_node_path_default().resolve(currentDir, '../../bin/scrcpy-server');
|
|
343
384
|
try {
|
|
344
385
|
onProgress?.('pushing-server');
|
|
345
|
-
await
|
|
386
|
+
await withTimeout(AdbScrcpyClient.pushServer(adb, ReadableStream.from((0, external_node_fs_namespaceObject.createReadStream)(serverBinPath))), constants_namespaceObject.SCRCPY_PUSH_TIMEOUT_MS, `Timed out pushing scrcpy server to device after ${Math.round(constants_namespaceObject.SCRCPY_PUSH_TIMEOUT_MS / 1000)}s`);
|
|
346
387
|
const scrcpyOptions = new AdbScrcpyOptions3_3_3({
|
|
347
388
|
audio: false,
|
|
348
389
|
control: true,
|
|
@@ -353,7 +394,7 @@ class ScrcpyServer {
|
|
|
353
394
|
});
|
|
354
395
|
onProgress?.('starting-service');
|
|
355
396
|
const startPromise = AdbScrcpyClient.start(adb, DefaultServerPath, scrcpyOptions);
|
|
356
|
-
return await
|
|
397
|
+
return await withTimeout(startPromise, constants_namespaceObject.SCRCPY_START_TIMEOUT_MS, `Timed out starting scrcpy service after ${Math.round(constants_namespaceObject.SCRCPY_START_TIMEOUT_MS / 1000)}s`, {
|
|
357
398
|
onSettledAfterTimeout: async (lateClient)=>{
|
|
358
399
|
try {
|
|
359
400
|
await lateClient.close();
|
|
@@ -448,7 +489,7 @@ class ScrcpyServer {
|
|
|
448
489
|
if ('object' == typeof scrcpyClient.videoStream && 'function' == typeof scrcpyClient.videoStream.then) {
|
|
449
490
|
debugPage('videoStream is a Promise, waiting for resolution...');
|
|
450
491
|
emitPreviewStatus('waiting-for-video');
|
|
451
|
-
videoStream = await
|
|
492
|
+
videoStream = await withTimeout(scrcpyClient.videoStream, constants_namespaceObject.SCRCPY_VIDEO_STREAM_TIMEOUT_MS, `Timed out waiting for scrcpy video stream metadata after ${Math.round(constants_namespaceObject.SCRCPY_VIDEO_STREAM_TIMEOUT_MS / 1000)}s`);
|
|
452
493
|
} else {
|
|
453
494
|
debugPage('videoStream is not a Promise, directly use');
|
|
454
495
|
emitPreviewStatus('waiting-for-video');
|
|
@@ -591,17 +632,17 @@ class ScrcpyServer {
|
|
|
591
632
|
if (this.httpServer?.listening) return this.httpServer.close();
|
|
592
633
|
}
|
|
593
634
|
constructor(options = {}){
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
635
|
+
scrcpy_server_define_property(this, "app", void 0);
|
|
636
|
+
scrcpy_server_define_property(this, "httpServer", void 0);
|
|
637
|
+
scrcpy_server_define_property(this, "io", void 0);
|
|
638
|
+
scrcpy_server_define_property(this, "port", void 0);
|
|
639
|
+
scrcpy_server_define_property(this, "defaultPort", constants_namespaceObject.SCRCPY_SERVER_PORT);
|
|
640
|
+
scrcpy_server_define_property(this, "adbClient", null);
|
|
641
|
+
scrcpy_server_define_property(this, "currentDeviceId", null);
|
|
642
|
+
scrcpy_server_define_property(this, "devicePollInterval", null);
|
|
643
|
+
scrcpy_server_define_property(this, "deviceListSource", void 0);
|
|
644
|
+
scrcpy_server_define_property(this, "deviceListSourceUnsubscribe", void 0);
|
|
645
|
+
scrcpy_server_define_property(this, "lastDeviceList", '');
|
|
605
646
|
this.deviceListSource = options.deviceListSource;
|
|
606
647
|
this.app = external_express_default()();
|
|
607
648
|
this.httpServer = (0, external_node_http_namespaceObject.createServer)(this.app);
|
package/dist/lib/index.js
CHANGED
|
@@ -205,7 +205,6 @@ function buildScrcpyPreviewStatusEvent(phase) {
|
|
|
205
205
|
message: getScrcpyPreviewStatusMessage(phase)
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
|
-
const timeout_namespaceObject = require("@midscene/shared/timeout");
|
|
209
208
|
function _define_property(obj, key, value) {
|
|
210
209
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
211
210
|
value: value,
|
|
@@ -216,6 +215,48 @@ function _define_property(obj, key, value) {
|
|
|
216
215
|
else obj[key] = value;
|
|
217
216
|
return obj;
|
|
218
217
|
}
|
|
218
|
+
class PromiseTimeoutError extends Error {
|
|
219
|
+
constructor(message, timeoutMs){
|
|
220
|
+
super(message), _define_property(this, "timeoutMs", void 0);
|
|
221
|
+
this.name = 'PromiseTimeoutError';
|
|
222
|
+
this.timeoutMs = timeoutMs;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function runTimeoutCallback(callback, context) {
|
|
226
|
+
if (!callback) return;
|
|
227
|
+
Promise.resolve().then(callback).catch((error)=>{
|
|
228
|
+
console.error(`Failed to run ${context}:`, error);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function withTimeout(promise, timeoutMs, message, options = {}) {
|
|
232
|
+
return new Promise((resolve, reject)=>{
|
|
233
|
+
let timedOut = false;
|
|
234
|
+
const timer = setTimeout(()=>{
|
|
235
|
+
timedOut = true;
|
|
236
|
+
runTimeoutCallback(options.onTimeout, 'timeout callback');
|
|
237
|
+
reject(new PromiseTimeoutError(message, timeoutMs));
|
|
238
|
+
}, timeoutMs);
|
|
239
|
+
Promise.resolve(promise).then((value)=>{
|
|
240
|
+
clearTimeout(timer);
|
|
241
|
+
if (timedOut) return void runTimeoutCallback(()=>options.onSettledAfterTimeout?.(value), 'post-timeout settle callback');
|
|
242
|
+
resolve(value);
|
|
243
|
+
}, (error)=>{
|
|
244
|
+
clearTimeout(timer);
|
|
245
|
+
if (timedOut) return void runTimeoutCallback(()=>options.onRejectedAfterTimeout?.(error), 'post-timeout rejection callback');
|
|
246
|
+
reject(error);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
function scrcpy_server_define_property(obj, key, value) {
|
|
251
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
252
|
+
value: value,
|
|
253
|
+
enumerable: true,
|
|
254
|
+
configurable: true,
|
|
255
|
+
writable: true
|
|
256
|
+
});
|
|
257
|
+
else obj[key] = value;
|
|
258
|
+
return obj;
|
|
259
|
+
}
|
|
219
260
|
const debugPage = (0, logger_namespaceObject.getDebug)('android:playground');
|
|
220
261
|
const promiseExec = (0, external_node_util_namespaceObject.promisify)(external_node_child_process_namespaceObject.exec);
|
|
221
262
|
const LOOPBACK_HOSTS = new Set([
|
|
@@ -313,7 +354,7 @@ class ScrcpyServer {
|
|
|
313
354
|
try {
|
|
314
355
|
if (this.adbClient) debugPage('use existing adb client');
|
|
315
356
|
else {
|
|
316
|
-
await
|
|
357
|
+
await withTimeout(promiseExec('adb start-server'), constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS, `Timed out starting adb server after ${Math.round(constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS / 1000)}s`);
|
|
317
358
|
debugPage('adb server started');
|
|
318
359
|
debugPage('initialize adb client');
|
|
319
360
|
this.adbClient = new AdbServerClient(new AdbServerNodeTcpConnector({
|
|
@@ -336,14 +377,14 @@ class ScrcpyServer {
|
|
|
336
377
|
const targetDeviceId = deviceId || this.currentDeviceId;
|
|
337
378
|
if (targetDeviceId) {
|
|
338
379
|
this.currentDeviceId = targetDeviceId;
|
|
339
|
-
return new Adb(await
|
|
380
|
+
return new Adb(await withTimeout(client.createTransport({
|
|
340
381
|
serial: targetDeviceId
|
|
341
382
|
}), constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS, `Timed out connecting to Android device ${targetDeviceId} via ADB after ${Math.round(constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS / 1000)}s`));
|
|
342
383
|
}
|
|
343
|
-
const devices = await
|
|
384
|
+
const devices = await withTimeout(client.getDevices(), constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS, `Timed out listing Android devices via ADB after ${Math.round(constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS / 1000)}s`);
|
|
344
385
|
if (0 === devices.length) return null;
|
|
345
386
|
this.currentDeviceId = devices[0].serial;
|
|
346
|
-
return new Adb(await
|
|
387
|
+
return new Adb(await withTimeout(client.createTransport(devices[0]), constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS, `Timed out connecting to Android device ${devices[0].serial} via ADB after ${Math.round(constants_namespaceObject.SCRCPY_ADB_CONNECT_TIMEOUT_MS / 1000)}s`));
|
|
347
388
|
} catch (error) {
|
|
348
389
|
console.error('failed to get adb client:', error);
|
|
349
390
|
throw error;
|
|
@@ -357,7 +398,7 @@ class ScrcpyServer {
|
|
|
357
398
|
const serverBinPath = external_node_path_default().resolve(currentDir, '../../bin/scrcpy-server');
|
|
358
399
|
try {
|
|
359
400
|
onProgress?.('pushing-server');
|
|
360
|
-
await
|
|
401
|
+
await withTimeout(AdbScrcpyClient.pushServer(adb, ReadableStream.from((0, external_node_fs_namespaceObject.createReadStream)(serverBinPath))), constants_namespaceObject.SCRCPY_PUSH_TIMEOUT_MS, `Timed out pushing scrcpy server to device after ${Math.round(constants_namespaceObject.SCRCPY_PUSH_TIMEOUT_MS / 1000)}s`);
|
|
361
402
|
const scrcpyOptions = new AdbScrcpyOptions3_3_3({
|
|
362
403
|
audio: false,
|
|
363
404
|
control: true,
|
|
@@ -368,7 +409,7 @@ class ScrcpyServer {
|
|
|
368
409
|
});
|
|
369
410
|
onProgress?.('starting-service');
|
|
370
411
|
const startPromise = AdbScrcpyClient.start(adb, DefaultServerPath, scrcpyOptions);
|
|
371
|
-
return await
|
|
412
|
+
return await withTimeout(startPromise, constants_namespaceObject.SCRCPY_START_TIMEOUT_MS, `Timed out starting scrcpy service after ${Math.round(constants_namespaceObject.SCRCPY_START_TIMEOUT_MS / 1000)}s`, {
|
|
372
413
|
onSettledAfterTimeout: async (lateClient)=>{
|
|
373
414
|
try {
|
|
374
415
|
await lateClient.close();
|
|
@@ -463,7 +504,7 @@ class ScrcpyServer {
|
|
|
463
504
|
if ('object' == typeof scrcpyClient.videoStream && 'function' == typeof scrcpyClient.videoStream.then) {
|
|
464
505
|
debugPage('videoStream is a Promise, waiting for resolution...');
|
|
465
506
|
emitPreviewStatus('waiting-for-video');
|
|
466
|
-
videoStream = await
|
|
507
|
+
videoStream = await withTimeout(scrcpyClient.videoStream, constants_namespaceObject.SCRCPY_VIDEO_STREAM_TIMEOUT_MS, `Timed out waiting for scrcpy video stream metadata after ${Math.round(constants_namespaceObject.SCRCPY_VIDEO_STREAM_TIMEOUT_MS / 1000)}s`);
|
|
467
508
|
} else {
|
|
468
509
|
debugPage('videoStream is not a Promise, directly use');
|
|
469
510
|
emitPreviewStatus('waiting-for-video');
|
|
@@ -606,17 +647,17 @@ class ScrcpyServer {
|
|
|
606
647
|
if (this.httpServer?.listening) return this.httpServer.close();
|
|
607
648
|
}
|
|
608
649
|
constructor(options = {}){
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
650
|
+
scrcpy_server_define_property(this, "app", void 0);
|
|
651
|
+
scrcpy_server_define_property(this, "httpServer", void 0);
|
|
652
|
+
scrcpy_server_define_property(this, "io", void 0);
|
|
653
|
+
scrcpy_server_define_property(this, "port", void 0);
|
|
654
|
+
scrcpy_server_define_property(this, "defaultPort", constants_namespaceObject.SCRCPY_SERVER_PORT);
|
|
655
|
+
scrcpy_server_define_property(this, "adbClient", null);
|
|
656
|
+
scrcpy_server_define_property(this, "currentDeviceId", null);
|
|
657
|
+
scrcpy_server_define_property(this, "devicePollInterval", null);
|
|
658
|
+
scrcpy_server_define_property(this, "deviceListSource", void 0);
|
|
659
|
+
scrcpy_server_define_property(this, "deviceListSourceUnsubscribe", void 0);
|
|
660
|
+
scrcpy_server_define_property(this, "lastDeviceList", '');
|
|
620
661
|
this.deviceListSource = options.deviceListSource;
|
|
621
662
|
this.app = external_express_default()();
|
|
622
663
|
this.httpServer = (0, external_node_http_namespaceObject.createServer)(this.app);
|
package/dist/types/timeout.d.ts
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare class PromiseTimeoutError extends Error {
|
|
2
|
+
readonly timeoutMs: number;
|
|
3
|
+
constructor(message: string, timeoutMs: number);
|
|
4
|
+
}
|
|
5
|
+
export interface WithTimeoutOptions<T> {
|
|
6
|
+
onTimeout?: () => void | Promise<void>;
|
|
7
|
+
onSettledAfterTimeout?: (value: T) => void | Promise<void>;
|
|
8
|
+
onRejectedAfterTimeout?: (error: unknown) => void | Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare function withTimeout<T>(promise: PromiseLike<T> | T, timeoutMs: number, message: string, options?: WithTimeoutOptions<T>): Promise<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/android-playground",
|
|
3
|
-
"version": "1.9.5
|
|
3
|
+
"version": "1.9.5",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/web-infra-dev/midscene.git",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"express": "^4.21.2",
|
|
40
40
|
"open": "10.1.0",
|
|
41
41
|
"socket.io": "^4.8.1",
|
|
42
|
-
"@midscene/android": "1.9.5
|
|
43
|
-
"@midscene/core": "1.9.5
|
|
44
|
-
"@midscene/playground": "1.9.5
|
|
45
|
-
"@midscene/shared": "1.9.5
|
|
42
|
+
"@midscene/android": "1.9.5",
|
|
43
|
+
"@midscene/core": "1.9.5",
|
|
44
|
+
"@midscene/playground": "1.9.5",
|
|
45
|
+
"@midscene/shared": "1.9.5"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@rslib/core": "^0.18.3",
|
package/static/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html><head><title>Midscene Android Playground</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/lib-react.ed140d90.js"></script><script defer src="/static/js/596.47507087.js"></script><script defer src="/static/js/index.
|
|
1
|
+
<!doctype html><html><head><title>Midscene Android Playground</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/lib-react.ed140d90.js"></script><script defer src="/static/js/596.47507087.js"></script><script defer src="/static/js/index.89a1aec8.js"></script><link href="/static/css/index.f155e03a.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
|