@@ -6,18 +6,13 @@ import { ChildProcess } from "child_process";
6
6
import { DebugServiceBase } from "./debug-service-base" ;
7
7
import { CONNECTION_ERROR_EVENT_NAME , AWAIT_NOTIFICATION_TIMEOUT_SECONDS } from "../constants" ;
8
8
import { getPidFromiOSSimulatorLogs } from "../common/helpers" ;
9
-
10
- import byline = require( "byline" ) ;
11
-
12
- const inspectorBackendPort = 18181 ;
13
9
const inspectorAppName = "NativeScript Inspector.app" ;
14
10
const inspectorNpmPackageName = "tns-ios-inspector" ;
15
11
const inspectorUiDir = "WebInspectorUI/" ;
16
12
17
13
export class IOSDebugService extends DebugServiceBase implements IPlatformDebugService {
18
14
private _lldbProcess : ChildProcess ;
19
15
private _sockets : net . Socket [ ] = [ ] ;
20
- private _childProcess : ChildProcess ;
21
16
private _socketProxy : any ;
22
17
23
18
constructor ( protected device : Mobile . IDevice ,
@@ -29,6 +24,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
29
24
private $logger : ILogger ,
30
25
private $errors : IErrors ,
31
26
private $npmInstallationManager : INpmInstallationManager ,
27
+ private $iOSDebuggerPortService : IIOSDebuggerPortService ,
32
28
private $iOSNotification : IiOSNotification ,
33
29
private $iOSSocketRequestExecutor : IiOSSocketRequestExecutor ,
34
30
private $processService : IProcessService ,
@@ -90,11 +86,6 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
90
86
await this . killProcess ( this . _lldbProcess ) ;
91
87
this . _lldbProcess = undefined ;
92
88
}
93
-
94
- if ( this . _childProcess ) {
95
- await this . killProcess ( this . _childProcess ) ;
96
- this . _childProcess = undefined ;
97
- }
98
89
}
99
90
100
91
protected getChromeDebugUrl ( debugOptions : IDebugOptions , port : number ) : string {
@@ -116,38 +107,23 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
116
107
117
108
private async emulatorDebugBrk ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < string > {
118
109
const args = debugOptions . debugBrk ? "--nativescript-debug-brk" : "--nativescript-debug-start" ;
119
- const child_process = await this . $iOSEmulatorServices . runApplicationOnEmulator ( debugData . pathToAppPackage , {
110
+ const launchResult = await this . $iOSEmulatorServices . runApplicationOnEmulator ( debugData . pathToAppPackage , {
120
111
waitForDebugger : true ,
121
112
captureStdin : true ,
122
113
args : args ,
123
114
appId : debugData . applicationIdentifier ,
124
115
skipInstall : true
125
116
} ) ;
126
117
127
- const lineStream = byline ( child_process . stdout ) ;
128
- this . _childProcess = child_process ;
129
-
130
- lineStream . on ( 'data' , ( line : NodeBuffer ) => {
131
- const lineText = line . toString ( ) ;
132
- if ( lineText && _ . startsWith ( lineText , debugData . applicationIdentifier ) ) {
133
- const pid = getPidFromiOSSimulatorLogs ( debugData . applicationIdentifier , lineText ) ;
134
- if ( ! pid ) {
135
- this . $logger . trace ( `Line ${ lineText } does not contain PID of the application ${ debugData . applicationIdentifier } .` ) ;
136
- return ;
137
- }
138
-
139
- this . _lldbProcess = this . $childProcess . spawn ( "lldb" , [ "-p" , pid ] ) ;
140
- if ( log4js . levels . TRACE . isGreaterThanOrEqualTo ( this . $logger . getLevel ( ) ) ) {
141
- this . _lldbProcess . stdout . pipe ( process . stdout ) ;
142
- }
143
- this . _lldbProcess . stderr . pipe ( process . stderr ) ;
144
- this . _lldbProcess . stdin . write ( "process continue\n" ) ;
145
- } else {
146
- process . stdout . write ( line + "\n" ) ;
147
- }
148
- } ) ;
118
+ const pid = getPidFromiOSSimulatorLogs ( debugData . applicationIdentifier , launchResult ) ;
119
+ this . _lldbProcess = this . $childProcess . spawn ( "lldb" , [ "-p" , pid ] ) ;
120
+ if ( log4js . levels . TRACE . isGreaterThanOrEqualTo ( this . $logger . getLevel ( ) ) ) {
121
+ this . _lldbProcess . stdout . pipe ( process . stdout ) ;
122
+ }
123
+ this . _lldbProcess . stderr . pipe ( process . stderr ) ;
124
+ this . _lldbProcess . stdin . write ( "process continue\n" ) ;
149
125
150
- await this . waitForBackendPortToBeOpened ( debugData . deviceIdentifier ) ;
126
+ await this . waitForBackendPortToBeOpened ( debugData ) ;
151
127
152
128
return this . wireDebuggerClient ( debugData , debugOptions ) ;
153
129
}
@@ -158,16 +134,17 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
158
134
const attachRequestMessage = this . $iOSNotification . getAttachRequest ( debugData . applicationIdentifier ) ;
159
135
160
136
const iOSEmulatorService = < Mobile . IiOSSimulatorService > this . $iOSEmulatorServices ;
161
- await iOSEmulatorService . postDarwinNotification ( attachRequestMessage ) ;
162
- await this . waitForBackendPortToBeOpened ( debugData . deviceIdentifier ) ;
137
+ await iOSEmulatorService . postDarwinNotification ( attachRequestMessage , debugData . deviceIdentifier ) ;
138
+ await this . waitForBackendPortToBeOpened ( debugData ) ;
163
139
return result ;
164
140
}
165
141
166
- private async waitForBackendPortToBeOpened ( deviceIdentifier : string ) : Promise < void > {
167
- const portListens = await this . $net . waitForPortToListen ( { port : inspectorBackendPort , timeout : 10000 , interval : 200 } ) ;
142
+ private async waitForBackendPortToBeOpened ( debugData : IDebugData ) : Promise < void > {
143
+ const port = await this . $iOSDebuggerPortService . getPort ( { deviceId : debugData . deviceIdentifier , appId : debugData . applicationIdentifier } ) ;
144
+ const portListens = await this . $net . waitForPortToListen ( { port, timeout : 10000 , interval : 200 } ) ;
168
145
if ( ! portListens ) {
169
146
const error = < Mobile . IDeviceError > new Error ( "Unable to connect to application. Ensure application is running on simulator." ) ;
170
- error . deviceIdentifier = deviceIdentifier ;
147
+ error . deviceIdentifier = debugData . deviceIdentifier ;
171
148
throw error ;
172
149
}
173
150
}
@@ -219,7 +196,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
219
196
// the VSCode Ext starts `tns debug ios --no-client` to start/attach to debug sessions
220
197
// check if --no-client is passed - default to opening a tcp socket (versus Chrome DevTools (websocket))
221
198
if ( ( debugOptions . inspector || ! debugOptions . client ) && this . $hostInfo . isDarwin ) {
222
- this . _socketProxy = await this . $socketProxyFactory . createTCPSocketProxy ( this . getSocketFactory ( device ) ) ;
199
+ this . _socketProxy = await this . $socketProxyFactory . createTCPSocketProxy ( this . getSocketFactory ( debugData , device ) ) ;
223
200
await this . openAppInspector ( this . _socketProxy . address ( ) , debugData , debugOptions ) ;
224
201
return null ;
225
202
} else {
@@ -228,7 +205,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
228
205
}
229
206
230
207
const deviceIdentifier = device ? device . deviceInfo . identifier : debugData . deviceIdentifier ;
231
- this . _socketProxy = await this . $socketProxyFactory . createWebSocketProxy ( this . getSocketFactory ( device ) , deviceIdentifier ) ;
208
+ this . _socketProxy = await this . $socketProxyFactory . createWebSocketProxy ( this . getSocketFactory ( debugData , device ) , deviceIdentifier ) ;
232
209
return this . getChromeDebugUrl ( debugOptions , this . _socketProxy . options . port ) ;
233
210
}
234
211
}
@@ -247,9 +224,10 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
247
224
}
248
225
}
249
226
250
- private getSocketFactory ( device ?: Mobile . IiOSDevice ) : ( ) => Promise < net . Socket > {
227
+ private getSocketFactory ( debugData : IDebugData , device ?: Mobile . IiOSDevice ) : ( ) => Promise < net . Socket > {
251
228
const factory = async ( ) => {
252
- const socket = device ? await device . connectToPort ( inspectorBackendPort ) : net . connect ( inspectorBackendPort ) ;
229
+ const port = await this . $iOSDebuggerPortService . getPort ( { deviceId : debugData . deviceIdentifier , appId : debugData . applicationIdentifier } ) ;
230
+ const socket = device ? await device . connectToPort ( port ) : net . connect ( port ) ;
253
231
this . _sockets . push ( socket ) ;
254
232
return socket ;
255
233
} ;
0 commit comments