diff --git a/lib/definitions/ios-debugger-port-service.d.ts b/lib/definitions/ios-debugger-port-service.d.ts index 50f156afb0..1b6486a0f5 100644 --- a/lib/definitions/ios-debugger-port-service.d.ts +++ b/lib/definitions/ios-debugger-port-service.d.ts @@ -17,7 +17,7 @@ interface IIOSDebuggerPortService { * Gets iOS debugger port for specified deviceId and appId * @param {IIOSDebuggerPortInputData} data - Describes deviceId and appId */ - getPort(data: IIOSDebuggerPortInputData): Promise; + getPort(data: IIOSDebuggerPortInputData, debugOptions?: IDebugOptions): Promise; /** * Attaches on DEBUGGER_PORT_FOUND event and STARTING_IOS_APPLICATION events * In case when DEBUGGER_PORT_FOUND event is emitted, stores the port and clears the timeout if such. diff --git a/lib/services/ios-debug-service.ts b/lib/services/ios-debug-service.ts index c5f48b7f1a..9ee2412f87 100644 --- a/lib/services/ios-debug-service.ts +++ b/lib/services/ios-debug-service.ts @@ -202,7 +202,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS // the VSCode Ext starts `tns debug ios --no-client` to start/attach to debug sessions // check if --no-client is passed - default to opening a tcp socket (versus Chrome DevTools (websocket)) if ((debugOptions.inspector || !debugOptions.client) && this.$hostInfo.isDarwin) { - this._socketProxy = await this.$socketProxyFactory.createTCPSocketProxy(this.getSocketFactory(debugData, device)); + this._socketProxy = await this.$socketProxyFactory.createTCPSocketProxy(this.getSocketFactory(device, debugData, debugOptions)); await this.openAppInspector(this._socketProxy.address(), debugData, debugOptions); return null; } else { @@ -211,7 +211,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS } const deviceIdentifier = device ? device.deviceInfo.identifier : debugData.deviceIdentifier; - this._socketProxy = await this.$socketProxyFactory.createWebSocketProxy(this.getSocketFactory(debugData, device), deviceIdentifier); + this._socketProxy = await this.$socketProxyFactory.createWebSocketProxy(this.getSocketFactory(device, debugData, debugOptions), deviceIdentifier); return this.getChromeDebugUrl(debugOptions, this._socketProxy.options.port); } } @@ -230,9 +230,9 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS } } - private getSocketFactory(debugData: IDebugData, device?: Mobile.IiOSDevice): () => Promise { + private getSocketFactory(device: Mobile.IiOSDevice, debugData: IDebugData, debugOptions: IDebugOptions): () => Promise { const factory = async () => { - const port = await this.$iOSDebuggerPortService.getPort({ projectDir: debugData.projectDir, deviceId: debugData.deviceIdentifier, appId: debugData.applicationIdentifier }); + const port = await this.$iOSDebuggerPortService.getPort({ projectDir: debugData.projectDir, deviceId: debugData.deviceIdentifier, appId: debugData.applicationIdentifier }, debugOptions); if (!port) { this.$errors.fail("NativeScript debugger was not able to get inspector socket port."); } diff --git a/lib/services/ios-debugger-port-service.ts b/lib/services/ios-debugger-port-service.ts index 8dac0bb27e..e52f4b509d 100644 --- a/lib/services/ios-debugger-port-service.ts +++ b/lib/services/ios-debugger-port-service.ts @@ -14,7 +14,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService { private $projectDataService: IProjectDataService, private $logger: ILogger) { } - public getPort(data: IIOSDebuggerPortInputData): Promise { + public getPort(data: IIOSDebuggerPortInputData, debugOptions?: IDebugOptions): Promise { return new Promise((resolve, reject) => { if (!this.canStartLookingForDebuggerPort(data)) { resolve(IOSDebuggerPortService.DEFAULT_PORT); @@ -22,7 +22,8 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService { } const key = `${data.deviceId}${data.appId}`; - let retryCount: number = 10; + const timeout = this.getTimeout(debugOptions); + let retryCount = Math.max(timeout * 1000 / 500, 10); const interval = setInterval(() => { let port = this.getPortByKey(key); diff --git a/test/services/ios-debugger-port-service.ts b/test/services/ios-debugger-port-service.ts index 765d255d11..66d4db19a4 100644 --- a/test/services/ios-debugger-port-service.ts +++ b/test/services/ios-debugger-port-service.ts @@ -157,7 +157,7 @@ describe("iOSDebuggerPortService", () => { } const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId, projectDir: mockProjectDirObj.projectDir }); - clock.tick(10000); + clock.tick(20000); const port = await promise; assert.deepEqual(port, testCase.emittedPort); }); @@ -171,7 +171,7 @@ describe("iOSDebuggerPortService", () => { } const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId, projectDir: mockProjectDirObj.projectDir }); - clock.tick(10000); + clock.tick(20000); const port = await promise; assert.deepEqual(port, testCase.emittedPort); });