Skip to content

Commit a163224

Browse files
committed
fix generating port for debug socket when debugging ios with chrome devtools
When generating a port to start a websocket on, use the same logic as is present in the android debug service - get the first available available port in a range, and reuse it for the next debug session of the same application if it is still available
1 parent 9a95e7c commit a163224

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/services/ios-debug-service.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
3232
private $iOSNotification: IiOSNotification,
3333
private $iOSSocketRequestExecutor: IiOSSocketRequestExecutor,
3434
private $processService: IProcessService,
35-
private $socketProxyFactory: ISocketProxyFactory) {
35+
private $socketProxyFactory: ISocketProxyFactory,
36+
private $net: INet) {
3637
super(device, $devicesService);
3738
this.$processService.attachToProcessExitSignals(this, this.debugStop);
3839
this.$socketProxyFactory.on(CONNECTION_ERROR_EVENT_NAME, (e: Error) => this.emit(CONNECTION_ERROR_EVENT_NAME, e));
@@ -212,7 +213,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
212213
this.$logger.info("'--chrome' is the default behavior. Use --inspector to debug iOS applications using the Safari Web Inspector.");
213214
}
214215

215-
this._socketProxy = await this.$socketProxyFactory.createWebSocketProxy(this.getSocketFactory(device));
216+
this._socketProxy = await this.$net.getAvailablePortInRange(41000);
216217
return this.getChromeDebugUrl(debugOptions, this._socketProxy.options.port);
217218
}
218219
}

test/services/ios-debug-service.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ class IOSDebugServiceInheritor extends IOSDebugService {
1717
$iOSNotification: IiOSNotification,
1818
$iOSSocketRequestExecutor: IiOSSocketRequestExecutor,
1919
$processService: IProcessService,
20-
$socketProxyFactory: ISocketProxyFactory) {
20+
$socketProxyFactory: ISocketProxyFactory,
21+
$net: INet) {
2122
super(<any>{}, $devicesService, $platformService, $iOSEmulatorServices, $childProcess, $hostInfo, $logger, $errors,
22-
$npmInstallationManager, $iOSNotification, $iOSSocketRequestExecutor, $processService, $socketProxyFactory);
23+
$npmInstallationManager, $iOSNotification, $iOSSocketRequestExecutor, $processService, $socketProxyFactory, $net);
2324
}
2425

2526
public getChromeDebugUrl(debugOptions: IDebugOptions, port: number): string {
@@ -48,6 +49,12 @@ const createTestInjector = (): IInjector => {
4849
on: (event: string | symbol, listener: Function): any => undefined
4950
});
5051

52+
testInjector.register("net", {
53+
getAvailablePortInRange: function (startPort: number, endPort?: number): any {
54+
return 41000;
55+
}
56+
});
57+
5158
return testInjector;
5259
};
5360

0 commit comments

Comments
 (0)