@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 ADDED
@@ -0,0 +1,245 @@
1
+ # usbmuxd Instance Manager
2
+
3
+ **Multi-instance manager for usbmuxd-win-mce**
4
+
5
+ Automatically manages multiple usbmuxd instances with intelligent batch device allocation to prevent freezing when handling many iOS devices simultaneously.
6
+
7
+ ## Features
8
+
9
+ - **Automatic Device Detection**: Uses `usb-device-listener` to detect iOS device connections
10
+ - **Batch Allocation**: Groups devices (default: 4 per instance) for optimal resource usage
11
+ - **Dynamic Scaling**: Spawns new instances as needed, terminates when empty
12
+ - **Isolated Failures**: One instance crash doesn't affect others
13
+ - **Zero Configuration**: Works out-of-the-box with sensible defaults
14
+
15
+ ## Architecture
16
+
17
+ ```
18
+ ┌──────────────────────────────────────────────────────────────┐
19
+ │ Windows Host │
20
+ │ ┌────────────────────────────────────────────────────────┐ │
21
+ │ │ usbmuxd-instance-manager (Node.js) │ │
22
+ │ │ ┌──────────────────────────────────────────────────┐ │ │
23
+ │ │ │ usb-device-listener │ │ │
24
+ │ │ │ Detects iOS devices (VID: 0x05AC) │ │ │
25
+ │ │ └──────────────┬───────────────────────────────────┘ │ │
26
+ │ │ │ │ │
27
+ │ │ ┌──────────────▼───────────────────────────────────┐ │ │
28
+ │ │ │ InstanceManager │ │ │
29
+ │ │ │ - Batch allocation (4 devices per instance) │ │ │
30
+ │ │ │ - Port assignment (27015, 27016, 27017...) │ │ │
31
+ │ │ │ - Spawns via WSL2 │ │ │
32
+ │ │ └──────────────┬───────────────────────────────────┘ │ │
33
+ │ └─────────────────┼──────────────────────────────────────┘ │
34
+ │ │ wsl -d usbmuxd-alpine usbmuxd ... │
35
+ │ ┌─────────────────▼──────────────────────────────────────┐ │
36
+ │ │ WSL2 - Alpine Linux (26MB) │ │
37
+ │ │ ┌──────────────────┐ ┌──────────────────┐ │ │
38
+ │ │ │ usbmuxd instance │ │ usbmuxd instance │ │ │
39
+ │ │ │ Port: 27015 │ │ Port: 27016 │ ... │ │
40
+ │ │ │ Devices 1-4 │ │ Devices 5-8 │ │ │
41
+ │ │ └──────────────────┘ └──────────────────┘ │ │
42
+ │ └─────────────────────────────────────────────────────────┘ │
43
+ └──────────────────────────────────────────────────────────────┘
44
+ ```
45
+
46
+ ## Installation
47
+
48
+ ```bash
49
+ # From workspace root
50
+ pnpm install
51
+
52
+ # Build the package
53
+ pnpm --filter @mcesystems/usbmuxd-instance-manager build
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ ### CLI
59
+
60
+ ```bash
61
+ # Run with defaults
62
+ pnpm --filter @mcesystems/usbmuxd-instance-manager dev
63
+
64
+ # Or after building
65
+ node dist/cli.js
66
+
67
+ # With custom options
68
+ node dist/cli.js --batchSize 6 --basePort 27020
69
+ ```
70
+
71
+ ### Programmatic API
72
+
73
+ ```typescript
74
+ import { UsbmuxdService } from '@mcesystems/usbmuxd-instance-manager';
75
+
76
+ const service = new UsbmuxdService({
77
+ batchSize: 4,
78
+ basePort: 27015,
79
+ maxInstances: 20,
80
+ usbmuxdPath: 'usbmuxd', // Path inside WSL2
81
+ wslDistribution: 'usbmuxd-alpine', // Alpine WSL2 distro
82
+ verboseLogging: true,
83
+ });
84
+
85
+ // Start monitoring
86
+ service.start();
87
+
88
+ // Get device port mapping
89
+ const port = service.getDevicePort('00008030-001234567890402E');
90
+ console.log(`Device is on port ${port}`);
91
+
92
+ // Get statistics
93
+ const stats = service.getStats();
94
+ console.log(`Managing ${stats.deviceCount} devices across ${stats.instanceCount} instances`);
95
+
96
+ // Stop when done
97
+ await service.stop();
98
+ ```
99
+
100
+ ## Configuration
101
+
102
+ | Option | Type | Default | Description |
103
+ |--------|------|---------|-------------|
104
+ | `batchSize` | number | 4 | Devices per instance |
105
+ | `basePort` | number | 27015 | Starting TCP port |
106
+ | `maxInstances` | number | 20 | Maximum instances |
107
+ | `usbmuxdPath` | string | `usbmuxd` | Path to usbmuxd inside WSL2 |
108
+ | `wslDistribution` | string | `usbmuxd-alpine` | Alpine WSL2 distribution name |
109
+ | `verboseLogging` | boolean | true | Enable verbose output |
110
+ | `appleVendorId` | string | '05AC' | Apple vendor ID (hex) |
111
+
112
+ ## CLI Options
113
+
114
+ ```
115
+ Usage: usbmuxd-instance-manager [OPTIONS]
116
+
117
+ Options:
118
+ --batchSize <n> Number of devices per instance (default: 4)
119
+ --basePort <port> Base TCP port for first instance (default: 27015)
120
+ --maxInstances <n> Maximum number of instances (default: 20)
121
+ --usbmuxdPath <path> Path to usbmuxd executable
122
+ --verbose <true|false> Enable verbose logging (default: true)
123
+ --appleVid <vid> Apple Vendor ID in hex (default: 05AC)
124
+ -h, --help Show this help message
125
+ ```
126
+
127
+ ## Events
128
+
129
+ The `InstanceManager` and `UsbmuxdService` emit events for monitoring:
130
+
131
+ ```typescript
132
+ service.manager.on('instance-started', (instance) => {
133
+ console.log(`Instance ${instance.id} started on port ${instance.port}`);
134
+ });
135
+
136
+ service.manager.on('device-assigned', ({ device, instance, mapping }) => {
137
+ console.log(`Device ${device.deviceId} → Instance ${instance.id} (port ${mapping.port})`);
138
+ });
139
+
140
+ service.manager.on('instance-stopped', (instance) => {
141
+ console.log(`Instance ${instance.id} stopped`);
142
+ });
143
+ ```
144
+
145
+ ## Example Scenario
146
+
147
+ ### 12 Devices Connected
148
+
149
+ ```
150
+ Instance 1 (port 27015): iPhone-1, iPhone-2, iPhone-3, iPhone-4
151
+ Instance 2 (port 27016): iPhone-5, iPhone-6, iPhone-7, iPhone-8
152
+ Instance 3 (port 27017): iPhone-9, iPhone-10, iPhone-11, iPhone-12
153
+ ```
154
+
155
+ ### Device Disconnects
156
+
157
+ When iPhone-3 disconnects:
158
+ - Instance 1 now has 3 devices
159
+ - Next device connects → assigned to Instance 1 (has capacity)
160
+
161
+ When all devices disconnect from Instance 2:
162
+ - Instance 2 automatically terminates
163
+ - Frees resources
164
+
165
+ ## Requirements
166
+
167
+ ### Runtime
168
+
169
+ - **Node.js**: 18+
170
+ - **Windows**: 10/11 with WSL2
171
+ - **Alpine WSL2 image**: usbmuxd-alpine distribution imported
172
+ - **USB/IP**: usbipd-win for USB device forwarding to WSL2
173
+
174
+ ### Build
175
+
176
+ - **pnpm**: Workspace package manager
177
+ - **TypeScript**: 5.9+
178
+ - **esbuild**: For bundling
179
+
180
+ ## Development
181
+
182
+ ```bash
183
+ # Install dependencies
184
+ pnpm install
185
+
186
+ # Run in dev mode (with auto-reload)
187
+ pnpm --filter @mcesystems/usbmuxd-instance-manager dev
188
+
189
+ # Build
190
+ pnpm --filter @mcesystems/usbmuxd-instance-manager build
191
+
192
+ # Type check
193
+ pnpm --filter @mcesystems/usbmuxd-instance-manager check:types
194
+
195
+ # Clean
196
+ pnpm --filter @mcesystems/usbmuxd-instance-manager clean
197
+ ```
198
+
199
+ ## Troubleshooting
200
+
201
+ ### Service Won't Start
202
+
203
+ - **Check usbmuxd path**: Ensure `usbmuxdPath` points to valid executable
204
+ - **Check permissions**: Run as Administrator if needed
205
+ - **Check ports**: Ensure ports 27015+ are not in use
206
+
207
+ ### Devices Not Detected
208
+
209
+ - **Check USB drivers**: iOS devices need WinUSB driver (install via Zadig)
210
+ - **Check VID**: Ensure `appleVendorId` is correct ('05AC' for Apple)
211
+ - **Check logs**: Run with verbose logging enabled
212
+
213
+ ### Instance Crashes
214
+
215
+ - **Check usbmuxd logs**: Look at instance output in console
216
+ - **Check USB driver**: Device might need driver reinstall
217
+ - **Restart service**: Service will spawn new instance for remaining devices
218
+
219
+ ## Performance
220
+
221
+ ### Resource Usage (20 devices, 5 instances)
222
+
223
+ - **CPU**: 15-20%
224
+ - **Memory**: ~400MB total (~80MB per instance)
225
+ - **Startup Time**: ~500ms per instance
226
+
227
+ ### vs. Single Instance (iTunes-style)
228
+
229
+ | Metric | Single Instance | Multi-Instance (5x) |
230
+ |--------|----------------|---------------------|
231
+ | CPU | 25-40% | 15-20% |
232
+ | Memory | 800MB | 400MB |
233
+ | Freezing | Frequent | None |
234
+ | Crash Impact | All devices | 4 devices max |
235
+
236
+ ## License
237
+
238
+ UNLICENSED - Private/Proprietary
239
+
240
+ This package is separate from the GPL-licensed usbmuxd-win-mce fork and remains proprietary.
241
+
242
+ ## See Also
243
+
244
+ - [usbmuxd-win-mce](https://github.com/coheneli/usbmuxd-win-mce) - The usbmuxd fork for Windows
245
+ - [usb-device-listener](../usb-device-listener) - USB device detection library