@midscene/android-playground 0.30.10 → 1.0.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.
Files changed (65) hide show
  1. package/dist/es/bin.mjs +28 -35
  2. package/dist/lib/bin.js +424 -474
  3. package/package.json +7 -7
  4. package/static/index.html +1 -1
  5. package/static/static/css/index.3784ddf6.css +2 -0
  6. package/static/static/css/index.3784ddf6.css.map +1 -0
  7. package/static/static/js/861.1a36955c.js +641 -0
  8. package/static/static/js/{374.e8fd2f39.js.LICENSE.txt → 861.1a36955c.js.LICENSE.txt} +2 -4
  9. package/static/static/js/861.1a36955c.js.map +1 -0
  10. package/static/static/js/async/195.05312dd9.js +3 -0
  11. package/static/static/js/async/195.05312dd9.js.map +1 -0
  12. package/static/static/js/async/{702.1f38a17e.js → 199.de925865.js} +17 -17
  13. package/static/static/js/async/199.de925865.js.map +1 -0
  14. package/static/static/js/async/221.213edee4.js +21 -0
  15. package/static/static/js/async/221.213edee4.js.map +1 -0
  16. package/static/static/js/async/271.1691b0d2.js +30 -0
  17. package/static/static/js/async/271.1691b0d2.js.map +1 -0
  18. package/static/static/js/async/35.918ea007.js +1 -0
  19. package/static/static/js/async/376.b7913581.js +2 -0
  20. package/static/static/js/async/376.b7913581.js.map +1 -0
  21. package/static/static/js/async/{644.910ce3d0.js → 467.9dc30840.js} +1 -1
  22. package/static/static/js/async/652.af2f1788.js +3 -0
  23. package/static/static/js/async/652.af2f1788.js.map +1 -0
  24. package/static/static/js/async/856.379e0ce3.js +158 -0
  25. package/static/static/js/async/{212.850ade70.js.map → 856.379e0ce3.js.map} +1 -1
  26. package/static/static/js/async/860.baac349b.js +2 -0
  27. package/static/static/js/async/860.baac349b.js.map +1 -0
  28. package/static/static/js/async/990.bb6496cd.js +26 -0
  29. package/static/static/js/async/990.bb6496cd.js.map +1 -0
  30. package/static/static/js/index.d87b642b.js +10 -0
  31. package/static/static/js/index.d87b642b.js.map +1 -0
  32. package/static/static/js/lib-react.574e3de9.js +3 -0
  33. package/static/static/js/lib-react.574e3de9.js.map +1 -0
  34. package/static/static/css/index.ea878c95.css +0 -2
  35. package/static/static/css/index.ea878c95.css.map +0 -1
  36. package/static/static/js/374.e8fd2f39.js +0 -650
  37. package/static/static/js/374.e8fd2f39.js.map +0 -1
  38. package/static/static/js/async/166.834644b5.js +0 -2
  39. package/static/static/js/async/166.834644b5.js.map +0 -1
  40. package/static/static/js/async/173.f2381e64.js +0 -3
  41. package/static/static/js/async/173.f2381e64.js.map +0 -1
  42. package/static/static/js/async/212.850ade70.js +0 -158
  43. package/static/static/js/async/329.261bc4a1.js +0 -26
  44. package/static/static/js/async/329.261bc4a1.js.map +0 -1
  45. package/static/static/js/async/364.d88c3cff.js +0 -30
  46. package/static/static/js/async/364.d88c3cff.js.map +0 -1
  47. package/static/static/js/async/544.18ac9afb.js +0 -2
  48. package/static/static/js/async/544.18ac9afb.js.map +0 -1
  49. package/static/static/js/async/582.8f4b5264.js +0 -21
  50. package/static/static/js/async/582.8f4b5264.js.map +0 -1
  51. package/static/static/js/async/624.8a1fe2e8.js +0 -3
  52. package/static/static/js/async/624.8a1fe2e8.js.map +0 -1
  53. package/static/static/js/async/659.d19e8c15.js +0 -21
  54. package/static/static/js/async/659.d19e8c15.js.map +0 -1
  55. package/static/static/js/async/702.1f38a17e.js.map +0 -1
  56. package/static/static/js/async/920.48d269c8.js +0 -2
  57. package/static/static/js/async/920.48d269c8.js.map +0 -1
  58. package/static/static/js/async/983.b98b40af.js +0 -1
  59. package/static/static/js/index.418b4242.js +0 -10
  60. package/static/static/js/index.418b4242.js.map +0 -1
  61. package/static/static/js/lib-react.c74a0742.js +0 -3
  62. package/static/static/js/lib-react.c74a0742.js.map +0 -1
  63. /package/static/static/js/{index.418b4242.js.LICENSE.txt → index.d87b642b.js.LICENSE.txt} +0 -0
  64. /package/static/static/js/{lib-react.c74a0742.js.LICENSE.txt → lib-react.574e3de9.js.LICENSE.txt} +0 -0
  65. /package/static/static/wasm/{9e906fbf55e08f98.module.wasm → 9e906fbf.module.wasm} +0 -0
package/dist/es/bin.mjs CHANGED
@@ -3,7 +3,7 @@ import { createServer } from "node:net";
3
3
  import node_path from "node:path";
4
4
  import { promisify } from "node:util";
5
5
  import { select as prompts_select } from "@inquirer/prompts";
6
- import { AndroidAgent, AndroidDevice } from "@midscene/android";
6
+ import { AndroidAgent, AndroidDevice, getConnectedDevices } from "@midscene/android";
7
7
  import { PlaygroundServer } from "@midscene/playground";
8
8
  import { PLAYGROUND_SERVER_PORT, SCRCPY_SERVER_PORT } from "@midscene/shared/constants";
9
9
  import { createReadStream } from "node:fs";
@@ -181,7 +181,7 @@ class ScrcpyServer {
181
181
  } catch (error) {
182
182
  console.error('failed to switch device:', error);
183
183
  socket.emit('error', {
184
- message: `Failed to switch device: ${(null == error ? void 0 : error.message) || 'Unknown error'}`
184
+ message: `Failed to switch device: ${error?.message || 'Unknown error'}`
185
185
  });
186
186
  }
187
187
  });
@@ -266,11 +266,11 @@ class ScrcpyServer {
266
266
  message: `Video stream processing error: ${error.message}`
267
267
  });
268
268
  }
269
- if (null == scrcpyClient ? void 0 : scrcpyClient.controller) socket.emit('control-ready');
269
+ if (scrcpyClient?.controller) socket.emit('control-ready');
270
270
  } catch (error) {
271
271
  console.error('failed to connect device:', error);
272
272
  socket.emit('error', {
273
- message: `Failed to connect device: ${(null == error ? void 0 : error.message) || 'Unknown error'}`
273
+ message: `Failed to connect device: ${error?.message || 'Unknown error'}`
274
274
  });
275
275
  }
276
276
  });
@@ -363,7 +363,7 @@ class ScrcpyServer {
363
363
  this.setupApiRoutes();
364
364
  }
365
365
  }
366
- const bin_promiseExec = promisify(exec);
366
+ promisify(exec);
367
367
  async function isPortAvailable(port) {
368
368
  return new Promise((resolve)=>{
369
369
  const server = createServer();
@@ -380,7 +380,7 @@ async function findAvailablePort(startPort) {
380
380
  while(!await isPortAvailable(port)){
381
381
  attempts++;
382
382
  if (attempts >= maxAttempts) {
383
- console.error(`\u{274C} Unable to find available port after ${maxAttempts} attempts starting from ${startPort}`);
383
+ console.error(`❌ Unable to find available port after ${maxAttempts} attempts starting from ${startPort}`);
384
384
  process.exit(1);
385
385
  }
386
386
  port++;
@@ -389,37 +389,30 @@ async function findAvailablePort(startPort) {
389
389
  }
390
390
  async function getAdbDevices() {
391
391
  try {
392
- await bin_promiseExec('adb start-server');
393
- const { stdout } = await bin_promiseExec('adb devices');
394
- const lines = stdout.trim().split('\n').slice(1);
395
- const devices = lines.map((line)=>{
396
- const parts = line.trim().split('\t');
397
- if (parts.length >= 2) return {
398
- id: parts[0],
399
- status: parts[1],
400
- name: parts[0]
401
- };
402
- return null;
403
- }).filter((device)=>null !== device && 'device' === device.status);
404
- return devices;
392
+ const devices = await getConnectedDevices();
393
+ return devices.filter((device)=>'device' === device.state).map((device)=>({
394
+ id: device.udid,
395
+ status: device.state,
396
+ name: device.udid
397
+ }));
405
398
  } catch (error) {
406
399
  console.error('Error getting ADB devices:', error);
407
400
  return [];
408
401
  }
409
402
  }
410
403
  async function selectDevice() {
411
- console.log("\uD83D\uDD0D Scanning for Android devices...");
404
+ console.log('🔍 Scanning for Android devices...');
412
405
  const devices = await getAdbDevices();
413
406
  if (0 === devices.length) {
414
- console.error("\u274C No Android devices found!");
415
- console.log("\uD83D\uDCF1 Please ensure:");
416
- console.log(" \u2022 Your device is connected via USB");
417
- console.log(" \u2022 USB debugging is enabled");
418
- console.log(" \u2022 Device is authorized for debugging");
407
+ console.error('❌ No Android devices found!');
408
+ console.log('📱 Please ensure:');
409
+ console.log(' Your device is connected via USB');
410
+ console.log(' USB debugging is enabled');
411
+ console.log(' Device is authorized for debugging');
419
412
  process.exit(1);
420
413
  }
421
414
  if (1 === devices.length) {
422
- console.log(`\u{1F4F1} Found device: ${devices[0].name} (${devices[0].id})`);
415
+ console.log(`📱 Found device: ${devices[0].name} (${devices[0].id})`);
423
416
  return devices[0].id;
424
417
  }
425
418
  const choices = devices.map((device)=>({
@@ -427,7 +420,7 @@ async function selectDevice() {
427
420
  value: device.id
428
421
  }));
429
422
  const selectedDevice = await prompts_select({
430
- message: "\uD83D\uDCF1 Multiple devices found. Please select one:",
423
+ message: '📱 Multiple devices found. Please select one:',
431
424
  choices
432
425
  });
433
426
  return selectedDevice;
@@ -437,7 +430,7 @@ const main = async ()=>{
437
430
  const { default: open } = await import("open");
438
431
  try {
439
432
  const selectedDeviceId = await selectDevice();
440
- console.log(`\u{2705} Selected device: ${selectedDeviceId}`);
433
+ console.log(`✅ Selected device: ${selectedDeviceId}`);
441
434
  const playgroundServer = new PlaygroundServer(async ()=>{
442
435
  const device = new AndroidDevice(selectedDeviceId);
443
436
  await device.connect();
@@ -445,21 +438,21 @@ const main = async ()=>{
445
438
  }, staticDir);
446
439
  const scrcpyServer = new ScrcpyServer();
447
440
  scrcpyServer.currentDeviceId = selectedDeviceId;
448
- console.log("\uD83D\uDE80 Starting servers...");
441
+ console.log('🚀 Starting servers...');
449
442
  const availablePlaygroundPort = await findAvailablePort(PLAYGROUND_SERVER_PORT);
450
443
  const availableScrcpyPort = await findAvailablePort(SCRCPY_SERVER_PORT);
451
- if (availablePlaygroundPort !== PLAYGROUND_SERVER_PORT) console.log(`\u{26A0}\u{FE0F} Port ${PLAYGROUND_SERVER_PORT} is busy, using port ${availablePlaygroundPort} instead`);
452
- if (availableScrcpyPort !== SCRCPY_SERVER_PORT) console.log(`\u{26A0}\u{FE0F} Port ${SCRCPY_SERVER_PORT} is busy, using port ${availableScrcpyPort} instead`);
444
+ if (availablePlaygroundPort !== PLAYGROUND_SERVER_PORT) console.log(`⚠️ Port ${PLAYGROUND_SERVER_PORT} is busy, using port ${availablePlaygroundPort} instead`);
445
+ if (availableScrcpyPort !== SCRCPY_SERVER_PORT) console.log(`⚠️ Port ${SCRCPY_SERVER_PORT} is busy, using port ${availableScrcpyPort} instead`);
453
446
  await Promise.all([
454
447
  playgroundServer.launch(availablePlaygroundPort),
455
448
  scrcpyServer.launch(availableScrcpyPort)
456
449
  ]);
457
450
  global.scrcpyServerPort = availableScrcpyPort;
458
451
  console.log('');
459
- console.log("\u2728 Midscene Android Playground is ready!");
460
- console.log(`\u{1F3AE} Playground: http://localhost:${playgroundServer.port}`);
461
- console.log(`\u{1F4F1} Device: ${selectedDeviceId}`);
462
- console.log(`\u{1F511} Generated Server ID: ${playgroundServer.id}`);
452
+ console.log('✨ Midscene Android Playground is ready!');
453
+ console.log(`🎮 Playground: http://localhost:${playgroundServer.port}`);
454
+ console.log(`📱 Device: ${selectedDeviceId}`);
455
+ console.log(`🔑 Generated Server ID: ${playgroundServer.id}`);
463
456
  console.log('');
464
457
  open(`http://localhost:${playgroundServer.port}`);
465
458
  } catch (error) {