@mcesystems/usbmuxd-instance-manager 1.0.72
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 +245 -0
- package/dist/cli.js +750 -0
- package/dist/cli.js.map +7 -0
- package/dist/cli.mjs +727 -0
- package/dist/cli.mjs.map +7 -0
- package/dist/index.js +680 -0
- package/dist/index.js.map +7 -0
- package/dist/index.mjs +642 -0
- package/dist/index.mjs.map +7 -0
- package/dist/types/InstanceManager.d.ts +114 -0
- package/dist/types/InstanceManager.d.ts.map +1 -0
- package/dist/types/UsbmuxdService.d.ts +59 -0
- package/dist/types/UsbmuxdService.d.ts.map +1 -0
- package/dist/types/cli.d.ts +3 -0
- package/dist/types/cli.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +125 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/package.json +61 -0
- package/prebuilt/alpine-usbmuxd.tar.gz +0 -0
- package/scripts/README.md +191 -0
- package/scripts/attach-device.ps1 +192 -0
- package/scripts/install-windows.ps1 +254 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/UsbmuxdService.ts", "../src/InstanceManager.ts"],
|
|
4
|
+
"sourcesContent": ["import { EventEmitter } from \"node:events\";\nimport { createLoggers } from \"@mcesystems/tool-debug-g4\";\nimport UsbDeviceListener from \"@mcesystems/usb-device-listener\";\nimport type { DeviceInfo } from \"@mcesystems/usb-device-listener\";\nimport { InstanceManager } from \"./InstanceManager.js\";\nimport type { DeviceMapping, InstanceManagerConfig, UsbmuxdInstance } from \"./types/index.js\";\n\nconst { logInfo, logError } = createLoggers(\"usbmuxd-instance-manager\");\n\n/**\n * Main service that integrates usb-device-listener with InstanceManager\n * Monitors iOS devices and manages usbmuxd instances automatically.\n * Extends EventEmitter: forwards instance-started, instance-stopped, device-assigned,\n * device-removed, instance-log, instance-exited from the underlying manager.\n */\nexport class UsbmuxdService extends EventEmitter {\n\tprivate manager: InstanceManager;\n\tprivate usbListener: UsbDeviceListener;\n\tprivate isListening = false;\n\n\tconstructor(config: Partial<InstanceManagerConfig> = {}) {\n\t\tsuper();\n\t\tthis.manager = new InstanceManager(config);\n\t\tthis.usbListener = new UsbDeviceListener();\n\t\tthis.setupEventHandlers();\n\t}\n\n\t/**\n\t * Forward manager events to service subscribers (no logging; CLI/examples handle logging).\n\t */\n\tprivate setupEventHandlers(): void {\n\t\tthis.manager.on(\"instance-started\", (instance: UsbmuxdInstance) => {\n\t\t\tthis.emit(\"instance-started\", instance);\n\t\t});\n\n\t\tthis.manager.on(\"instance-stopped\", (instance: UsbmuxdInstance) => {\n\t\t\tthis.emit(\"instance-stopped\", instance);\n\t\t});\n\n\t\tthis.manager.on(\n\t\t\t\"device-assigned\",\n\t\t\t(payload: { device: DeviceInfo; instance: UsbmuxdInstance; mapping: DeviceMapping }) => {\n\t\t\t\tthis.emit(\"device-assigned\", payload);\n\t\t\t}\n\t\t);\n\n\t\tthis.manager.on(\n\t\t\t\"device-removed\",\n\t\t\t(payload: { device: DeviceInfo; instance: UsbmuxdInstance }) => {\n\t\t\t\tthis.emit(\"device-removed\", payload);\n\t\t\t}\n\t\t);\n\n\t\tthis.manager.on(\n\t\t\t\"instance-log\",\n\t\t\t(payload: { instanceId: number; level: string; message: string }) => {\n\t\t\t\tthis.emit(\"instance-log\", payload);\n\t\t\t}\n\t\t);\n\n\t\tthis.manager.on(\n\t\t\t\"instance-exited\",\n\t\t\t(payload: { instanceId: number; code: number | null; signal: string | null }) => {\n\t\t\t\tthis.emit(\"instance-exited\", payload);\n\t\t\t}\n\t\t);\n\n\t\tthis.manager.on(\"device-paired\", (payload: { udid: string; mapping: DeviceMapping }) => {\n\t\t\tthis.emit(\"device-paired\", payload);\n\t\t});\n\t}\n\n\t/**\n\t * Start the service\n\t * Begins monitoring for iOS devices\n\t */\n\tpublic start(): void {\n\t\tif (this.isListening) {\n\t\t\tthrow new Error(\"Service is already running\");\n\t\t}\n\n\t\tconst config = this.manager.getConfig();\n\n\t\t// Convert Apple VID from hex to decimal for comparison\n\t\tconst appleVid = Number.parseInt(config.appleVendorId, 16);\n\n\t\tlogInfo(\"Starting service...\");\n\t\tlogInfo(`Batch size: ${config.batchSize} devices per instance`);\n\t\tlogInfo(`Base port: ${config.basePort}`);\n\t\tlogInfo(`Max instances: ${config.maxInstances}`);\n\t\tlogInfo(`usbmuxd path: ${config.usbmuxdPath}`);\n\t\tlogInfo(`Monitoring Apple devices (VID: ${config.appleVendorId})`);\n\n\t\t// Set up device listener callbacks\n\t\tthis.usbListener.onDeviceAdd(async (device: DeviceInfo) => {\n\t\t\t// Filter for Apple devices only\n\t\t\tif (device.vid !== appleVid) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlogInfo(`Apple device connected: ${device.deviceId} (${device.deviceName || \"Unknown\"})`);\n\n\t\t\ttry {\n\t\t\t\tawait this.manager.onDeviceConnected(device);\n\t\t\t} catch (error) {\n\t\t\t\tlogError(\"Error handling device connection:\", error);\n\t\t\t}\n\t\t});\n\n\t\tthis.usbListener.onDeviceRemove(async (device: DeviceInfo) => {\n\t\t\t// Filter for Apple devices only\n\t\t\tif (device.vid !== appleVid) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlogInfo(`Apple device disconnected: ${device.deviceId}`);\n\n\t\t\ttry {\n\t\t\t\tawait this.manager.onDeviceDisconnected(device);\n\t\t\t} catch (error) {\n\t\t\t\tlogError(\"Error handling device disconnection:\", error);\n\t\t\t}\n\t\t});\n\n\t\t// Start listening for USB events\n\t\ttry {\n\t\t\tthis.usbListener.startListening({\n\t\t\t\ttargetDevices: [], // Monitor all devices, we'll filter by VID\n\t\t\t});\n\n\t\t\tthis.isListening = true;\n\t\t\tthis.manager.start();\n\n\t\t\tlogInfo(\"Service started successfully\");\n\t\t\tlogInfo(\"Waiting for iOS devices...\");\n\t\t} catch (error) {\n\t\t\tlogError(\"Failed to start USB listener:\", error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Stop the service\n\t * Stops monitoring and terminates all instances\n\t */\n\tpublic async stop(): Promise<void> {\n\t\tif (!this.isListening) {\n\t\t\treturn;\n\t\t}\n\n\t\tlogInfo(\"Stopping service...\");\n\n\t\t// Stop USB listener\n\t\tthis.usbListener.stopListening();\n\t\tthis.isListening = false;\n\n\t\t// Stop all instances\n\t\tawait this.manager.stop();\n\n\t\tlogInfo(\"Service stopped\");\n\t}\n\n\t/**\n\t * Get device port mapping\n\t */\n\tpublic getDevicePort(udid: string): number | null {\n\t\treturn this.manager.getDevicePort(udid);\n\t}\n\n\t/**\n\t * Get all device mappings\n\t */\n\tpublic getDeviceMappings() {\n\t\treturn this.manager.getDeviceMappings();\n\t}\n\n\t/**\n\t * Get all running instances\n\t */\n\tpublic getInstances() {\n\t\treturn this.manager.getInstances();\n\t}\n\n\t/**\n\t * Get service statistics\n\t */\n\tpublic getStats() {\n\t\treturn this.manager.getStats();\n\t}\n\n\t/**\n\t * Get current configuration\n\t */\n\tpublic getConfig() {\n\t\treturn this.manager.getConfig();\n\t}\n\n\t/**\n\t * Pair a device with the usbmuxd host.\n\t * This is required once per device before most commands will work.\n\t * The pairing record is stored in WSL and persists across restarts.\n\t *\n\t * @param udid Device UDID to pair\n\t * @param goIosPath Optional path to go-ios binary\n\t * @returns true if pairing succeeded, false otherwise\n\t */\n\tpublic async pairDevice(udid: string, goIosPath?: string): Promise<boolean> {\n\t\treturn this.manager.pairDevice(udid, goIosPath);\n\t}\n}\n", "import { type ChildProcess, exec, spawn } from \"node:child_process\";\nimport { EventEmitter } from \"node:events\";\nimport { promisify } from \"node:util\";\nimport { createLoggers } from \"@mcesystems/tool-debug-g4\";\nimport type {\n\tDeviceInfo,\n\tDeviceMapping,\n\tInstanceManagerConfig,\n\tManagerStats,\n\tUsbmuxdInstance,\n} from \"./types/index.js\";\n\nconst { logInfo, logWarning } = createLoggers(\"usbmuxd-instance-manager\");\n\nconst execAsync = promisify(exec);\n\n/**\n * Path to usbipd executable (Program Files location on Windows)\n */\nconst USBIPD_PATH = '\"C:\\\\Program Files\\\\usbipd-win\\\\usbipd.exe\"';\n\n/**\n * Represents a USB device from usbipd list output\n */\ninterface UsbipdDevice {\n\tbusId: string;\n\tvid: string;\n\tpid: string;\n\tdescription: string;\n\tstate: string;\n}\n\n/**\n * Parse usbipd list output to extract device information\n */\nfunction parseUsbipdList(output: string): UsbipdDevice[] {\n\tconst devices: UsbipdDevice[] = [];\n\t// Handle both \\r\\n and \\n line endings\n\tconst lines = output.split(/\\r?\\n/);\n\n\tfor (const line of lines) {\n\t\t// Format: \"4-5 05ac:12a8 Apple Mobile Device USB Composite Device Shared (forced)\"\n\t\t// More flexible regex: busid, vid:pid, then anything else\n\t\tconst match = line.match(/^(\\d+-\\d+)\\s+([0-9a-f]{4}):([0-9a-f]{4})\\s+(.+)$/i);\n\t\tif (match) {\n\t\t\t// Split the rest into description and state (state is the last word(s) after multiple spaces)\n\t\t\tconst rest = match[4].trim();\n\t\t\tconst stateMatch = rest.match(/^(.+?)\\s{2,}(\\S.*)$/);\n\t\t\tconst description = stateMatch ? stateMatch[1].trim() : rest;\n\t\t\tconst state = stateMatch ? stateMatch[2].trim() : \"Unknown\";\n\n\t\t\tdevices.push({\n\t\t\t\tbusId: match[1],\n\t\t\t\tvid: match[2].toUpperCase(),\n\t\t\t\tpid: match[3].toUpperCase(),\n\t\t\t\tdescription,\n\t\t\t\tstate,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn devices;\n}\n\n/**\n * Default configuration for the instance manager\n */\nconst DEFAULT_CONFIG: InstanceManagerConfig = {\n\tbatchSize: 4,\n\tbasePort: 27015,\n\tmaxInstances: 20,\n\tusbmuxdPath: \"usbmuxd\", // Path inside WSL2\n\twslDistribution: \"alpine-usbmuxd-build\", // Alpine WSL2 distribution name\n\tverboseLogging: true,\n\tappleVendorId: \"05AC\",\n};\n\n/**\n * Manages multiple usbmuxd instances with batch device allocation\n *\n * @example\n * const manager = new InstanceManager({\n * batchSize: 4,\n * basePort: 27015,\n * });\n *\n * manager.on('instance-started', (instance) => {\n * logInfo(`Instance ${instance.id} started on port ${instance.port}`);\n * });\n *\n * manager.start();\n */\nexport class InstanceManager extends EventEmitter {\n\tprivate config: InstanceManagerConfig;\n\tprivate instances: Map<number, UsbmuxdInstance> = new Map();\n\tprivate deviceMappings: Map<string, DeviceMapping> = new Map();\n\tprivate processes: Map<number, ChildProcess> = new Map();\n\tprivate nextInstanceId = 1;\n\tprivate startedAt: Date | null = null;\n\tprivate isRunning = false;\n\n\t/** Tracks which devices have been attached to WSL */\n\tprivate attachedDevices: Set<string> = new Set();\n\n\t/** Cached WSL IP address for connecting from Windows */\n\tprivate wslIpAddress: string | null = null;\n\n\tconstructor(config: Partial<InstanceManagerConfig> = {}) {\n\t\tsuper();\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t}\n\n\t/**\n\t * Detect the WSL2 IP address for the configured distribution\n\t * This IP is needed to connect from Windows to services inside WSL\n\t */\n\tprivate async detectWslIpAddress(): Promise<string> {\n\t\tif (this.wslIpAddress) {\n\t\t\treturn this.wslIpAddress;\n\t\t}\n\n\t\tconst distro = this.config.wslDistribution || \"alpine-usbmuxd-build\";\n\n\t\ttry {\n\t\t\t// Try to get IP from eth0 interface\n\t\t\tconst { stdout } = await execAsync(`wsl -d ${distro} -- ip -4 addr show eth0`);\n\t\t\tconst match = stdout.match(/inet\\s+(\\d+\\.\\d+\\.\\d+\\.\\d+)/);\n\t\t\tif (match) {\n\t\t\t\tthis.wslIpAddress = match[1];\n\t\t\t\tlogInfo(`Detected WSL IP address: ${this.wslIpAddress}`);\n\t\t\t\treturn this.wslIpAddress;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to detect WSL IP via ip addr: ${error}`);\n\t\t}\n\n\t\t// Fallback: try hostname -I\n\t\ttry {\n\t\t\tconst { stdout } = await execAsync(`wsl -d ${distro} -- hostname -I`);\n\t\t\tconst ip = stdout.trim().split(/\\s+/)[0];\n\t\t\tif (ip && /^\\d+\\.\\d+\\.\\d+\\.\\d+$/.test(ip)) {\n\t\t\t\tthis.wslIpAddress = ip;\n\t\t\t\tlogInfo(`Detected WSL IP address (hostname): ${this.wslIpAddress}`);\n\t\t\t\treturn this.wslIpAddress;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to detect WSL IP via hostname: ${error}`);\n\t\t}\n\n\t\t// Last resort fallback - localhost (may work with WSL2 mirrored networking)\n\t\tlogWarning(\"Could not detect WSL IP, falling back to localhost\");\n\t\tthis.wslIpAddress = \"127.0.0.1\";\n\t\treturn this.wslIpAddress;\n\t}\n\n\t/**\n\t * Start the instance manager\n\t */\n\tpublic start(): void {\n\t\tif (this.isRunning) {\n\t\t\tthrow new Error(\"Instance manager is already running\");\n\t\t}\n\n\t\tthis.isRunning = true;\n\t\tthis.startedAt = new Date();\n\t\tthis.emit(\"started\");\n\t}\n\n\t/**\n\t * Stop the instance manager and all instances\n\t */\n\tpublic async stop(): Promise<void> {\n\t\tif (!this.isRunning) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.isRunning = false;\n\n\t\t// Detach all devices from WSL\n\t\tconst detachPromises = Array.from(this.attachedDevices).map((busId) =>\n\t\t\tthis.detachDeviceFromWsl(busId)\n\t\t);\n\t\tawait Promise.all(detachPromises);\n\t\tthis.attachedDevices.clear();\n\n\t\t// Stop all instances\n\t\tconst stopPromises = Array.from(this.instances.keys()).map((id) => this.stopInstance(id));\n\n\t\tawait Promise.all(stopPromises);\n\n\t\tthis.instances.clear();\n\t\tthis.deviceMappings.clear();\n\t\tthis.processes.clear();\n\n\t\tthis.emit(\"stopped\");\n\t}\n\n\t/**\n\t * Find the usbipd bus ID for a device by matching VID/PID\n\t */\n\tprivate async findBusIdForDevice(device: DeviceInfo): Promise<string | null> {\n\t\ttry {\n\t\t\tconst { stdout } = await execAsync(`${USBIPD_PATH} list`);\n\t\t\tconst usbipdDevices = parseUsbipdList(stdout);\n\n\t\t\t// Convert device VID/PID to hex string for comparison\n\t\t\tconst deviceVid = device.vid.toString(16).toUpperCase().padStart(4, \"0\");\n\t\t\tconst devicePid = device.pid.toString(16).toUpperCase().padStart(4, \"0\");\n\n\t\t\tlogInfo(`Looking for device with VID:PID ${deviceVid}:${devicePid}`);\n\t\t\tlogInfo(`Found ${usbipdDevices.length} devices from usbipd list`);\n\n\t\t\t// Find matching device by VID/PID\n\t\t\tconst match = usbipdDevices.find((d) => d.vid === deviceVid && d.pid === devicePid);\n\n\t\t\tif (match) {\n\t\t\t\tlogInfo(\n\t\t\t\t\t`Found usbipd bus ID ${match.busId} for device ${device.deviceId} (${deviceVid}:${devicePid})`\n\t\t\t\t);\n\t\t\t\treturn match.busId;\n\t\t\t}\n\n\t\t\t// Debug: log all parsed devices to help diagnose\n\t\t\tfor (const d of usbipdDevices) {\n\t\t\t\tlogInfo(` usbipd device: ${d.busId} ${d.vid}:${d.pid} \"${d.description}\"`);\n\t\t\t}\n\n\t\t\tlogWarning(\n\t\t\t\t`Could not find usbipd bus ID for device ${device.deviceId} (${deviceVid}:${devicePid})`\n\t\t\t);\n\t\t\treturn null;\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to run usbipd list: ${error}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Ensure the WSL distribution is running\n\t */\n\tprivate async ensureWslRunning(): Promise<boolean> {\n\t\tconst distro = this.config.wslDistribution;\n\n\t\ttry {\n\t\t\tif (distro) {\n\t\t\t\t// Start specific distribution\n\t\t\t\tlogInfo(`Starting WSL distribution: ${distro}...`);\n\t\t\t\tawait execAsync(`wsl -d ${distro} -- echo \"WSL started\"`);\n\t\t\t} else {\n\t\t\t\t// Start default WSL\n\t\t\t\tlogInfo(\"Starting default WSL distribution...\");\n\t\t\t\tawait execAsync(`wsl -- echo \"WSL started\"`);\n\t\t\t}\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to start WSL: ${error}`);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Attach a device to WSL via usbipd\n\t * Note: This requires administrator privileges\n\t */\n\tprivate async attachDeviceToWsl(busId: string): Promise<boolean> {\n\t\tconst distro = this.config.wslDistribution;\n\n\t\ttry {\n\t\t\t// Ensure WSL is running first\n\t\t\tawait this.ensureWslRunning();\n\n\t\t\t// Bind the device (make it shareable)\n\t\t\tlogInfo(`Binding device ${busId}...`);\n\t\t\tawait execAsync(`${USBIPD_PATH} bind --busid ${busId} --force`);\n\n\t\t\t// Attach to WSL (use specific distro if configured, otherwise let usbipd pick)\n\t\t\tif (distro) {\n\t\t\t\tlogInfo(`Attaching device ${busId} to WSL distribution ${distro}...`);\n\t\t\t\tawait execAsync(`${USBIPD_PATH} attach --wsl=${distro} --busid=${busId}`);\n\t\t\t} else {\n\t\t\t\tlogInfo(`Attaching device ${busId} to default WSL...`);\n\t\t\t\tawait execAsync(`${USBIPD_PATH} attach --wsl --busid=${busId}`);\n\t\t\t}\n\n\t\t\tlogInfo(`Device ${busId} attached to WSL successfully`);\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to attach device ${busId} to WSL: ${error}`);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Detach a device from WSL via usbipd\n\t */\n\tprivate async detachDeviceFromWsl(busId: string): Promise<void> {\n\t\ttry {\n\t\t\tawait execAsync(`${USBIPD_PATH} detach --busid=${busId}`);\n\t\t\tlogInfo(`Device ${busId} detached from WSL`);\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to detach device ${busId}: ${error}`);\n\t\t}\n\t}\n\n\t/**\n\t * Handle device connection\n\t * Attaches device to WSL, then assigns to an existing instance or creates a new one\n\t */\n\tpublic async onDeviceConnected(device: DeviceInfo): Promise<void> {\n\t\t// Check if device is already mapped\n\t\tif (this.deviceMappings.has(device.deviceId)) {\n\t\t\tlogWarning(`Device ${device.deviceId} is already connected`);\n\t\t\treturn;\n\t\t}\n\n\t\t// Step 1: Find the usbipd bus ID for this device\n\t\tconst busId = await this.findBusIdForDevice(device);\n\t\tif (!busId) {\n\t\t\tlogWarning(`Cannot attach device ${device.deviceId} - bus ID not found`);\n\t\t\t// Continue anyway - maybe it's already attached or not needed\n\t\t}\n\n\t\t// Step 2: Attach device to WSL (if not already attached)\n\t\tif (busId && !this.attachedDevices.has(busId)) {\n\t\t\tconst attached = await this.attachDeviceToWsl(busId);\n\t\t\tif (attached) {\n\t\t\t\tthis.attachedDevices.add(busId);\n\t\t\t\t// Give WSL a moment to recognize the device\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, 1000));\n\t\t\t}\n\t\t}\n\n\t\t// Step 3: Find an instance with available capacity\n\t\tlet targetInstance = this.findInstanceWithCapacity();\n\n\t\t// If no instance has capacity, create a new one\n\t\tif (!targetInstance) {\n\t\t\tif (this.instances.size >= this.config.maxInstances) {\n\t\t\t\tthrow new Error(`Maximum number of instances (${this.config.maxInstances}) reached`);\n\t\t\t}\n\n\t\t\ttargetInstance = await this.createInstance();\n\t\t}\n\n\t\t// Add device to instance\n\t\ttargetInstance.deviceUdids.push(device.deviceId);\n\n\t\t// Create mapping (include host and busId for cleanup on disconnect)\n\t\tconst mapping: DeviceMapping = {\n\t\t\tudid: device.deviceId,\n\t\t\tinstanceId: targetInstance.id,\n\t\t\thost: targetInstance.host,\n\t\t\tport: targetInstance.port,\n\t\t\taddedAt: new Date(),\n\t\t\tbusId: busId ?? undefined,\n\t\t};\n\n\t\tthis.deviceMappings.set(device.deviceId, mapping);\n\n\t\tthis.emit(\"device-assigned\", {\n\t\t\tdevice,\n\t\t\tinstance: targetInstance,\n\t\t\tmapping,\n\t\t});\n\t}\n\n\t/**\n\t * Pair a device with the usbmuxd host.\n\t * This is required once per device before most commands will work.\n\t * The pairing record is stored in WSL and persists across restarts.\n\t *\n\t * @param udid Device UDID to pair\n\t * @param goIosPath Optional path to go-ios binary (defaults to \"ios\")\n\t * @returns true if pairing succeeded, false otherwise\n\t */\n\tpublic async pairDevice(udid: string, goIosPath = \"ios\"): Promise<boolean> {\n\t\tconst mapping = this.deviceMappings.get(udid);\n\t\tif (!mapping) {\n\t\t\tlogWarning(`Cannot pair device ${udid} - not found in mappings`);\n\t\t\treturn false;\n\t\t}\n\n\t\ttry {\n\t\t\tconst socketAddress = `${mapping.host}:${mapping.port}`;\n\t\t\tlogInfo(`Pairing device ${udid} via ${socketAddress}...`);\n\n\t\t\t// Run go-ios pair command with USBMUXD_SOCKET_ADDRESS set\n\t\t\tconst { stderr } = await execAsync(`\"${goIosPath}\" pair --udid=${udid}`, {\n\t\t\t\tenv: { ...process.env, USBMUXD_SOCKET_ADDRESS: socketAddress },\n\t\t\t});\n\n\t\t\tif (stderr?.includes(\"error\")) {\n\t\t\t\tlogWarning(`Pairing warning for ${udid}: ${stderr}`);\n\t\t\t}\n\n\t\t\tlogInfo(`Device ${udid} paired successfully`);\n\t\t\tthis.emit(\"device-paired\", { udid, mapping });\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tlogWarning(`Failed to pair device ${udid}: ${error}`);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Handle device disconnection\n\t * Detaches from WSL, removes device from instance, and stops instance if empty\n\t */\n\tpublic async onDeviceDisconnected(device: DeviceInfo): Promise<void> {\n\t\tconst mapping = this.deviceMappings.get(device.deviceId);\n\t\tif (!mapping) {\n\t\t\tlogWarning(`Device ${device.deviceId} was not tracked`);\n\t\t\treturn;\n\t\t}\n\n\t\t// Detach device from WSL if it was attached\n\t\tif (mapping.busId) {\n\t\t\tawait this.detachDeviceFromWsl(mapping.busId);\n\t\t\tthis.attachedDevices.delete(mapping.busId);\n\t\t}\n\n\t\tconst instance = this.instances.get(mapping.instanceId);\n\t\tif (!instance) {\n\t\t\tlogWarning(`Instance ${mapping.instanceId} not found`);\n\t\t\tthis.deviceMappings.delete(device.deviceId);\n\t\t\treturn;\n\t\t}\n\n\t\t// Remove device from instance\n\t\tconst deviceIndex = instance.deviceUdids.indexOf(device.deviceId);\n\t\tif (deviceIndex > -1) {\n\t\t\tinstance.deviceUdids.splice(deviceIndex, 1);\n\t\t}\n\n\t\t// Remove mapping\n\t\tthis.deviceMappings.delete(device.deviceId);\n\n\t\tthis.emit(\"device-removed\", {\n\t\t\tdevice,\n\t\t\tinstance,\n\t\t});\n\n\t\t// If instance is now empty, stop it\n\t\tif (instance.deviceUdids.length === 0) {\n\t\t\tawait this.stopInstance(instance.id);\n\t\t}\n\t}\n\n\t/**\n\t * Find an instance with available capacity\n\t */\n\tprivate findInstanceWithCapacity(): UsbmuxdInstance | null {\n\t\tfor (const instance of this.instances.values()) {\n\t\t\tif (instance.deviceUdids.length < this.config.batchSize) {\n\t\t\t\treturn instance;\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**\n\t * Create a new usbmuxd instance\n\t */\n\tprivate async createInstance(): Promise<UsbmuxdInstance> {\n\t\tconst instanceId = this.nextInstanceId++;\n\t\tconst port = this.config.basePort + instanceId - 1;\n\n\t\t// Detect WSL IP for connecting from Windows\n\t\tconst host = await this.detectWslIpAddress();\n\n\t\t// Build usbmuxd arguments\n\t\tconst usbmuxdArgs = [\n\t\t\t\"-f\", // Foreground\n\t\t\t\"-v\", // Verbose (if enabled)\n\t\t\t\"-S\",\n\t\t\t`0.0.0.0:${port}`, // Listen on all interfaces (for Windows \u2192 WSL2)\n\t\t\t\"--pidfile\",\n\t\t\t\"NONE\",\n\t\t];\n\n\t\tif (!this.config.verboseLogging) {\n\t\t\t// Remove -v if not verbose\n\t\t\tusbmuxdArgs.splice(1, 1);\n\t\t}\n\n\t\t// Build WSL command: wsl -d <distro> usbmuxd <args>\n\t\tconst wslArgs = [\n\t\t\t\"-d\",\n\t\t\tthis.config.wslDistribution || \"alpine-usbmuxd-build\",\n\t\t\tthis.config.usbmuxdPath,\n\t\t\t...usbmuxdArgs,\n\t\t];\n\n\t\t// Spawn via WSL\n\t\tconst process = spawn(\"wsl\", wslArgs, {\n\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\twindowsHide: false, // Show console for debugging\n\t\t});\n\n\t\t// Handle process output\n\t\tprocess.stdout?.on(\"data\", (data) => {\n\t\t\tthis.emit(\"instance-log\", {\n\t\t\t\tinstanceId,\n\t\t\t\tlevel: \"info\",\n\t\t\t\tmessage: data.toString().trim(),\n\t\t\t});\n\t\t});\n\n\t\tprocess.stderr?.on(\"data\", (data) => {\n\t\t\tthis.emit(\"instance-log\", {\n\t\t\t\tinstanceId,\n\t\t\t\tlevel: \"error\",\n\t\t\t\tmessage: data.toString().trim(),\n\t\t\t});\n\t\t});\n\n\t\t// Handle process exit\n\t\tprocess.on(\"exit\", (code, signal) => {\n\t\t\tthis.emit(\"instance-exited\", {\n\t\t\t\tinstanceId,\n\t\t\t\tcode,\n\t\t\t\tsignal,\n\t\t\t});\n\n\t\t\t// Clean up instance and process references, but keep device mappings intact.\n\t\t\t// Device mappings represent the logical port assignment and should only be\n\t\t\t// removed when the device is physically disconnected (via onDeviceDisconnected).\n\t\t\t// Consumers can listen to 'instance-exited' to react to unexpected exits.\n\t\t\tif (this.instances.has(instanceId)) {\n\t\t\t\tthis.instances.delete(instanceId);\n\t\t\t\tthis.processes.delete(instanceId);\n\t\t\t}\n\t\t});\n\n\t\t// Create instance record (pid is set synchronously by Node after spawn)\n\t\tconst pid = process.pid;\n\t\tif (pid === undefined) {\n\t\t\tprocess.kill(\"SIGKILL\");\n\t\t\tthrow new Error(\"Failed to get PID for usbmuxd instance\");\n\t\t}\n\t\tconst instance: UsbmuxdInstance = {\n\t\t\tid: instanceId,\n\t\t\thost,\n\t\t\tport,\n\t\t\tpid,\n\t\t\tdeviceUdids: [],\n\t\t\tstartedAt: new Date(),\n\t\t};\n\n\t\tthis.instances.set(instanceId, instance);\n\t\tthis.processes.set(instanceId, process);\n\n\t\tthis.emit(\"instance-started\", instance);\n\n\t\t// Wait a bit for the instance to start listening\n\t\tawait new Promise((resolve) => setTimeout(resolve, 500));\n\n\t\treturn instance;\n\t}\n\n\t/**\n\t * Stop a specific instance\n\t */\n\tprivate async stopInstance(instanceId: number): Promise<void> {\n\t\tconst instance = this.instances.get(instanceId);\n\t\tconst process = this.processes.get(instanceId);\n\n\t\tif (!instance || !process) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Kill the process\n\t\tprocess.kill(\"SIGTERM\");\n\n\t\t// Wait for process to exit\n\t\tawait new Promise<void>((resolve) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\t// Force kill if not exited\n\t\t\t\tif (!process.killed) {\n\t\t\t\t\tprocess.kill(\"SIGKILL\");\n\t\t\t\t}\n\t\t\t\tresolve();\n\t\t\t}, 5000);\n\n\t\t\tprocess.once(\"exit\", () => {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\n\t\t// Clean up\n\t\tthis.instances.delete(instanceId);\n\t\tthis.processes.delete(instanceId);\n\n\t\t// Remove device mappings\n\t\tfor (const [udid, mapping] of this.deviceMappings.entries()) {\n\t\t\tif (mapping.instanceId === instanceId) {\n\t\t\t\tthis.deviceMappings.delete(udid);\n\t\t\t}\n\t\t}\n\n\t\tthis.emit(\"instance-stopped\", instance);\n\t}\n\n\t/**\n\t * Get device-to-port mapping for a specific UDID\n\t */\n\tpublic getDevicePort(udid: string): number | null {\n\t\tconst mapping = this.deviceMappings.get(udid);\n\t\treturn mapping ? mapping.port : null;\n\t}\n\n\t/**\n\t * Get all device mappings\n\t */\n\tpublic getDeviceMappings(): DeviceMapping[] {\n\t\treturn Array.from(this.deviceMappings.values());\n\t}\n\n\t/**\n\t * Get all running instances\n\t */\n\tpublic getInstances(): UsbmuxdInstance[] {\n\t\treturn Array.from(this.instances.values());\n\t}\n\n\t/**\n\t * Get manager statistics\n\t */\n\tpublic getStats(): ManagerStats {\n\t\tconst now = Date.now();\n\t\tconst startTime = this.startedAt?.getTime() || now;\n\t\tconst uptimeSeconds = Math.floor((now - startTime) / 1000);\n\n\t\treturn {\n\t\t\tinstanceCount: this.instances.size,\n\t\t\tdeviceCount: this.deviceMappings.size,\n\t\t\tuptimeSeconds,\n\t\t\tstartedAt: this.startedAt || new Date(),\n\t\t};\n\t}\n\n\t/**\n\t * Get current configuration\n\t */\n\tpublic getConfig(): InstanceManagerConfig {\n\t\treturn { ...this.config };\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAAA,qBAAoB;AAC7B,SAAS,iBAAAC,sBAAqB;AAC9B,OAAO,uBAAuB;;;ACF9B,SAA4B,MAAM,aAAa;AAC/C,SAAS,oBAAoB;AAC7B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAS9B,IAAM,EAAE,SAAS,WAAW,IAAI,cAAc,0BAA0B;AAExE,IAAM,YAAY,UAAU,IAAI;AAKhC,IAAM,cAAc;AAgBpB,SAAS,gBAAgB,QAAgC;AACxD,QAAM,UAA0B,CAAC;AAEjC,QAAM,QAAQ,OAAO,MAAM,OAAO;AAElC,aAAW,QAAQ,OAAO;AAGzB,UAAM,QAAQ,KAAK,MAAM,mDAAmD;AAC5E,QAAI,OAAO;AAEV,YAAM,OAAO,MAAM,CAAC,EAAE,KAAK;AAC3B,YAAM,aAAa,KAAK,MAAM,qBAAqB;AACnD,YAAM,cAAc,aAAa,WAAW,CAAC,EAAE,KAAK,IAAI;AACxD,YAAM,QAAQ,aAAa,WAAW,CAAC,EAAE,KAAK,IAAI;AAElD,cAAQ,KAAK;AAAA,QACZ,OAAO,MAAM,CAAC;AAAA,QACd,KAAK,MAAM,CAAC,EAAE,YAAY;AAAA,QAC1B,KAAK,MAAM,CAAC,EAAE,YAAY;AAAA,QAC1B;AAAA,QACA;AAAA,MACD,CAAC;AAAA,IACF;AAAA,EACD;AAEA,SAAO;AACR;AAKA,IAAM,iBAAwC;AAAA,EAC7C,WAAW;AAAA,EACX,UAAU;AAAA,E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
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import type { DeviceInfo, DeviceMapping, InstanceManagerConfig, ManagerStats, UsbmuxdInstance } from "./types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Manages multiple usbmuxd instances with batch device allocation
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const manager = new InstanceManager({
|
|
8
|
+
* batchSize: 4,
|
|
9
|
+
* basePort: 27015,
|
|
10
|
+
* });
|
|
11
|
+
*
|
|
12
|
+
* manager.on('instance-started', (instance) => {
|
|
13
|
+
* logInfo(`Instance ${instance.id} started on port ${instance.port}`);
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* manager.start();
|
|
17
|
+
*/
|
|
18
|
+
export declare class InstanceManager extends EventEmitter {
|
|
19
|
+
private config;
|
|
20
|
+
private instances;
|
|
21
|
+
private deviceMappings;
|
|
22
|
+
private processes;
|
|
23
|
+
private nextInstanceId;
|
|
24
|
+
private startedAt;
|
|
25
|
+
private isRunning;
|
|
26
|
+
/** Tracks which devices have been attached to WSL */
|
|
27
|
+
private attachedDevices;
|
|
28
|
+
/** Cached WSL IP address for connecting from Windows */
|
|
29
|
+
private wslIpAddress;
|
|
30
|
+
constructor(config?: Partial<InstanceManagerConfig>);
|
|
31
|
+
/**
|
|
32
|
+
* Detect the WSL2 IP address for the configured distribution
|
|
33
|
+
* This IP is needed to connect from Windows to services inside WSL
|
|
34
|
+
*/
|
|
35
|
+
private detectWslIpAddress;
|
|
36
|
+
/**
|
|
37
|
+
* Start the instance manager
|
|
38
|
+
*/
|
|
39
|
+
start(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Stop the instance manager and all instances
|
|
42
|
+
*/
|
|
43
|
+
stop(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Find the usbipd bus ID for a device by matching VID/PID
|
|
46
|
+
*/
|
|
47
|
+
private findBusIdForDevice;
|
|
48
|
+
/**
|
|
49
|
+
* Ensure the WSL distribution is running
|
|
50
|
+
*/
|
|
51
|
+
private ensureWslRunning;
|
|
52
|
+
/**
|
|
53
|
+
* Attach a device to WSL via usbipd
|
|
54
|
+
* Note: This requires administrator privileges
|
|
55
|
+
*/
|
|
56
|
+
private attachDeviceToWsl;
|
|
57
|
+
/**
|
|
58
|
+
* Detach a device from WSL via usbipd
|
|
59
|
+
*/
|
|
60
|
+
private detachDeviceFromWsl;
|
|
61
|
+
/**
|
|
62
|
+
* Handle device connection
|
|
63
|
+
* Attaches device to WSL, then assigns to an existing instance or creates a new one
|
|
64
|
+
*/
|
|
65
|
+
onDeviceConnected(device: DeviceInfo): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Pair a device with the usbmuxd host.
|
|
68
|
+
* This is required once per device before most commands will work.
|
|
69
|
+
* The pairing record is stored in WSL and persists across restarts.
|
|
70
|
+
*
|
|
71
|
+
* @param udid Device UDID to pair
|
|
72
|
+
* @param goIosPath Optional path to go-ios binary (defaults to "ios")
|
|
73
|
+
* @returns true if pairing succeeded, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
pairDevice(udid: string, goIosPath?: string): Promise<boolean>;
|
|
76
|
+
/**
|
|
77
|
+
* Handle device disconnection
|
|
78
|
+
* Detaches from WSL, removes device from instance, and stops instance if empty
|
|
79
|
+
*/
|
|
80
|
+
onDeviceDisconnected(device: DeviceInfo): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Find an instance with available capacity
|
|
83
|
+
*/
|
|
84
|
+
private findInstanceWithCapacity;
|
|
85
|
+
/**
|
|
86
|
+
* Create a new usbmuxd instance
|
|
87
|
+
*/
|
|
88
|
+
private createInstance;
|
|
89
|
+
/**
|
|
90
|
+
* Stop a specific instance
|
|
91
|
+
*/
|
|
92
|
+
private stopInstance;
|
|
93
|
+
/**
|
|
94
|
+
* Get device-to-port mapping for a specific UDID
|
|
95
|
+
*/
|
|
96
|
+
getDevicePort(udid: string): number | null;
|
|
97
|
+
/**
|
|
98
|
+
* Get all device mappings
|
|
99
|
+
*/
|
|
100
|
+
getDeviceMappings(): DeviceMapping[];
|
|
101
|
+
/**
|
|
102
|
+
* Get all running instances
|
|
103
|
+
*/
|
|
104
|
+
getInstances(): UsbmuxdInstance[];
|
|
105
|
+
/**
|
|
106
|
+
* Get manager statistics
|
|
107
|
+
*/
|
|
108
|
+
getStats(): ManagerStats;
|
|
109
|
+
/**
|
|
110
|
+
* Get current configuration
|
|
111
|
+
*/
|
|
112
|
+
getConfig(): InstanceManagerConfig;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=InstanceManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InstanceManager.d.ts","sourceRoot":"","sources":["../../src/InstanceManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,KAAK,EACX,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,MAAM,kBAAkB,CAAC;AAmE1B;;;;;;;;;;;;;;GAcG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IAChD,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,SAAS,CAA2C;IAC5D,OAAO,CAAC,cAAc,CAAyC;IAC/D,OAAO,CAAC,SAAS,CAAwC;IACzD,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,SAAS,CAAS;IAE1B,qDAAqD;IACrD,OAAO,CAAC,eAAe,CAA0B;IAEjD,wDAAwD;IACxD,OAAO,CAAC,YAAY,CAAuB;gBAE/B,MAAM,GAAE,OAAO,CAAC,qBAAqB,CAAM;IAKvD;;;OAGG;YACW,kBAAkB;IAuChC;;OAEG;IACI,KAAK,IAAI,IAAI;IAUpB;;OAEG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IA0BlC;;OAEG;YACW,kBAAkB;IAqChC;;OAEG;YACW,gBAAgB;IAoB9B;;;OAGG;YACW,iBAAiB;IA4B/B;;OAEG;YACW,mBAAmB;IASjC;;;OAGG;IACU,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA0DjE;;;;;;;;OAQG;IACU,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,SAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IA6B1E;;;OAGG;IACU,oBAAoB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAwCpE;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAShC;;OAEG;YACW,cAAc;IAiG5B;;OAEG;YACW,YAAY;IAyC1B;;OAEG;IACI,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAKjD;;OAEG;IACI,iBAAiB,IAAI,aAAa,EAAE;IAI3C;;OAEG;IACI,YAAY,IAAI,eAAe,EAAE;IAIxC;;OAEG;IACI,QAAQ,IAAI,YAAY;IAa/B;;OAEG;IACI,SAAS,IAAI,qBAAqB;CAGzC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import type { DeviceMapping, InstanceManagerConfig, UsbmuxdInstance } from "./types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Main service that integrates usb-device-listener with InstanceManager
|
|
5
|
+
* Monitors iOS devices and manages usbmuxd instances automatically.
|
|
6
|
+
* Extends EventEmitter: forwards instance-started, instance-stopped, device-assigned,
|
|
7
|
+
* device-removed, instance-log, instance-exited from the underlying manager.
|
|
8
|
+
*/
|
|
9
|
+
export declare class UsbmuxdService extends EventEmitter {
|
|
10
|
+
private manager;
|
|
11
|
+
private usbListener;
|
|
12
|
+
private isListening;
|
|
13
|
+
constructor(config?: Partial<InstanceManagerConfig>);
|
|
14
|
+
/**
|
|
15
|
+
* Forward manager events to service subscribers (no logging; CLI/examples handle logging).
|
|
16
|
+
*/
|
|
17
|
+
private setupEventHandlers;
|
|
18
|
+
/**
|
|
19
|
+
* Start the service
|
|
20
|
+
* Begins monitoring for iOS devices
|
|
21
|
+
*/
|
|
22
|
+
start(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Stop the service
|
|
25
|
+
* Stops monitoring and terminates all instances
|
|
26
|
+
*/
|
|
27
|
+
stop(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Get device port mapping
|
|
30
|
+
*/
|
|
31
|
+
getDevicePort(udid: string): number | null;
|
|
32
|
+
/**
|
|
33
|
+
* Get all device mappings
|
|
34
|
+
*/
|
|
35
|
+
getDeviceMappings(): DeviceMapping[];
|
|
36
|
+
/**
|
|
37
|
+
* Get all running instances
|
|
38
|
+
*/
|
|
39
|
+
getInstances(): UsbmuxdInstance[];
|
|
40
|
+
/**
|
|
41
|
+
* Get service statistics
|
|
42
|
+
*/
|
|
43
|
+
getStats(): import("./index.js").ManagerStats;
|
|
44
|
+
/**
|
|
45
|
+
* Get current configuration
|
|
46
|
+
*/
|
|
47
|
+
getConfig(): InstanceManagerConfig;
|
|
48
|
+
/**
|
|
49
|
+
* Pair a device with the usbmuxd host.
|
|
50
|
+
* This is required once per device before most commands will work.
|
|
51
|
+
* The pairing record is stored in WSL and persists across restarts.
|
|
52
|
+
*
|
|
53
|
+
* @param udid Device UDID to pair
|
|
54
|
+
* @param goIosPath Optional path to go-ios binary
|
|
55
|
+
* @returns true if pairing succeeded, false otherwise
|
|
56
|
+
*/
|
|
57
|
+
pairDevice(udid: string, goIosPath?: string): Promise<boolean>;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=UsbmuxdService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsbmuxdService.d.ts","sourceRoot":"","sources":["../../src/UsbmuxdService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAK3C,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAI9F;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC/C,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,GAAE,OAAO,CAAC,qBAAqB,CAAM;IAOvD;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA0C1B;;;OAGG;IACI,KAAK,IAAI,IAAI;IAiEpB;;;OAGG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBlC;;OAEG;IACI,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIjD;;OAEG;IACI,iBAAiB;IAIxB;;OAEG;IACI,YAAY;IAInB;;OAEG;IACI,QAAQ;IAIf;;OAEG;IACI,SAAS;IAIhB;;;;;;;;OAQG;IACU,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAG3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EACX,qBAAqB,EACrB,eAAe,EACf,UAAU,EACV,aAAa,EACb,YAAY,GACZ,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the usbmuxd instance manager
|
|
3
|
+
*/
|
|
4
|
+
export interface InstanceManagerConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Number of devices per usbmuxd instance
|
|
7
|
+
* @default 4
|
|
8
|
+
*/
|
|
9
|
+
batchSize: number;
|
|
10
|
+
/**
|
|
11
|
+
* Base TCP port for first instance
|
|
12
|
+
* @default 27015
|
|
13
|
+
*/
|
|
14
|
+
basePort: number;
|
|
15
|
+
/**
|
|
16
|
+
* Maximum number of instances to spawn
|
|
17
|
+
* @default 20
|
|
18
|
+
*/
|
|
19
|
+
maxInstances: number;
|
|
20
|
+
/**
|
|
21
|
+
* Path to usbmuxd binary inside WSL2
|
|
22
|
+
* @default "usbmuxd"
|
|
23
|
+
*/
|
|
24
|
+
usbmuxdPath: string;
|
|
25
|
+
/**
|
|
26
|
+
* WSL2 distribution name containing usbmuxd
|
|
27
|
+
* @default "usbmuxd-alpine"
|
|
28
|
+
*/
|
|
29
|
+
wslDistribution?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Enable verbose logging from usbmuxd instances
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
verboseLogging: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Apple vendor ID for iOS devices
|
|
37
|
+
* @default "05AC"
|
|
38
|
+
*/
|
|
39
|
+
appleVendorId: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Information about a running usbmuxd instance
|
|
43
|
+
*/
|
|
44
|
+
export interface UsbmuxdInstance {
|
|
45
|
+
/**
|
|
46
|
+
* Instance ID (incremental)
|
|
47
|
+
*/
|
|
48
|
+
id: number;
|
|
49
|
+
/**
|
|
50
|
+
* Host address where this instance is listening (WSL IP or localhost)
|
|
51
|
+
*/
|
|
52
|
+
host: string;
|
|
53
|
+
/**
|
|
54
|
+
* TCP port this instance is listening on
|
|
55
|
+
*/
|
|
56
|
+
port: number;
|
|
57
|
+
/**
|
|
58
|
+
* Process ID
|
|
59
|
+
*/
|
|
60
|
+
pid: number;
|
|
61
|
+
/**
|
|
62
|
+
* Device UDIDs managed by this instance
|
|
63
|
+
*/
|
|
64
|
+
deviceUdids: string[];
|
|
65
|
+
/**
|
|
66
|
+
* Timestamp when instance was started
|
|
67
|
+
*/
|
|
68
|
+
startedAt: Date;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Device information (re-exported from @mcesystems/usb-device-listener for API convenience).
|
|
72
|
+
*/
|
|
73
|
+
export type { DeviceInfo } from "@mcesystems/usb-device-listener";
|
|
74
|
+
/**
|
|
75
|
+
* Device-to-instance mapping
|
|
76
|
+
*/
|
|
77
|
+
export interface DeviceMapping {
|
|
78
|
+
/**
|
|
79
|
+
* Device UDID
|
|
80
|
+
*/
|
|
81
|
+
udid: string;
|
|
82
|
+
/**
|
|
83
|
+
* Instance ID managing this device
|
|
84
|
+
*/
|
|
85
|
+
instanceId: number;
|
|
86
|
+
/**
|
|
87
|
+
* Host address where the usbmuxd instance is listening (WSL IP)
|
|
88
|
+
*/
|
|
89
|
+
host: string;
|
|
90
|
+
/**
|
|
91
|
+
* Port number for this instance
|
|
92
|
+
*/
|
|
93
|
+
port: number;
|
|
94
|
+
/**
|
|
95
|
+
* Timestamp when device was added
|
|
96
|
+
*/
|
|
97
|
+
addedAt: Date;
|
|
98
|
+
/**
|
|
99
|
+
* usbipd bus ID for WSL attachment (e.g., "1-2")
|
|
100
|
+
* Only present when device was attached via usbipd
|
|
101
|
+
*/
|
|
102
|
+
busId?: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Manager statistics
|
|
106
|
+
*/
|
|
107
|
+
export interface ManagerStats {
|
|
108
|
+
/**
|
|
109
|
+
* Total number of running instances
|
|
110
|
+
*/
|
|
111
|
+
instanceCount: number;
|
|
112
|
+
/**
|
|
113
|
+
* Total number of connected devices
|
|
114
|
+
*/
|
|
115
|
+
deviceCount: number;
|
|
116
|
+
/**
|
|
117
|
+
* Manager uptime in seconds
|
|
118
|
+
*/
|
|
119
|
+
uptimeSeconds: number;
|
|
120
|
+
/**
|
|
121
|
+
* Timestamp when manager started
|
|
122
|
+
*/
|
|
123
|
+
startedAt: Date;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,cAAc,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,WAAW,EAAE,MAAM,EAAE,CAAC;IAEtB;;OAEG;IACH,SAAS,EAAE,IAAI,CAAC;CAChB;AAED;;GAEG;AACH,YAAY,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,IAAI,CAAC;IAEd;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,SAAS,EAAE,IAAI,CAAC;CAChB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mcesystems/usbmuxd-instance-manager",
|
|
3
|
+
"version": "1.0.72",
|
|
4
|
+
"description": "Multi-instance manager for usbmuxd-win-mce - manages multiple usbmuxd processes with batch device allocation",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"usbmuxd",
|
|
17
|
+
"ios",
|
|
18
|
+
"iphone",
|
|
19
|
+
"ipad",
|
|
20
|
+
"multi-instance",
|
|
21
|
+
"device-manager",
|
|
22
|
+
"usb",
|
|
23
|
+
"windows",
|
|
24
|
+
"instance-manager",
|
|
25
|
+
"batch-processing"
|
|
26
|
+
],
|
|
27
|
+
"author": "MCE Systems",
|
|
28
|
+
"license": "ISC",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"node-windows": "^1.0.0-beta.8",
|
|
31
|
+
"@mcesystems/usb-device-listener": "1.0.72",
|
|
32
|
+
"@mcesystems/tool-debug-g4": "1.0.72"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^24.10.1",
|
|
36
|
+
"cross-env": "^10.1.0",
|
|
37
|
+
"esbuild": "^0.27.0",
|
|
38
|
+
"rimraf": "^6.1.2",
|
|
39
|
+
"tsx": "^4.21.0",
|
|
40
|
+
"typescript": "^5.9.3",
|
|
41
|
+
"vitest": "^2.1.8"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist",
|
|
45
|
+
"prebuilt",
|
|
46
|
+
"scripts",
|
|
47
|
+
"README.md"
|
|
48
|
+
],
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsx esbuild.config.mts && tsc --emitDeclarationOnly",
|
|
51
|
+
"build:all": "pnpm --filter @mcesystems/usbmuxd-instance-manager... build",
|
|
52
|
+
"clean": "rimraf dist",
|
|
53
|
+
"check:types": "tsc --noEmit",
|
|
54
|
+
"dev": "tsx src/cli.ts",
|
|
55
|
+
"example": "tsx src/examples/example.ts",
|
|
56
|
+
"start": "node dist/cli.js",
|
|
57
|
+
"pack": "npm pack",
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"test:watch": "vitest"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
Binary file
|