@@ -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,11 +24,11 @@ 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 ,
35
31
private $socketProxyFactory : ISocketProxyFactory ,
36
- private $net : INet ,
37
32
private $projectDataService : IProjectDataService ) {
38
33
super ( device , $devicesService ) ;
39
34
this . $processService . attachToProcessExitSignals ( this , this . debugStop ) ;
@@ -90,11 +85,6 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
90
85
await this . killProcess ( this . _lldbProcess ) ;
91
86
this . _lldbProcess = undefined ;
92
87
}
93
-
94
- if ( this . _childProcess ) {
95
- await this . killProcess ( this . _childProcess ) ;
96
- this . _childProcess = undefined ;
97
- }
98
88
}
99
89
100
90
protected getChromeDebugUrl ( debugOptions : IDebugOptions , port : number ) : string {
@@ -116,38 +106,21 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
116
106
117
107
private async emulatorDebugBrk ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < string > {
118
108
const args = debugOptions . debugBrk ? "--nativescript-debug-brk" : "--nativescript-debug-start" ;
119
- const child_process = await this . $iOSEmulatorServices . runApplicationOnEmulator ( debugData . pathToAppPackage , {
109
+ const launchResult = await this . $iOSEmulatorServices . runApplicationOnEmulator ( debugData . pathToAppPackage , {
120
110
waitForDebugger : true ,
121
111
captureStdin : true ,
122
112
args : args ,
123
113
appId : debugData . applicationIdentifier ,
124
114
skipInstall : true
125
115
} ) ;
126
116
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
- } ) ;
149
-
150
- await this . waitForBackendPortToBeOpened ( debugData . deviceIdentifier ) ;
117
+ const pid = getPidFromiOSSimulatorLogs ( debugData . applicationIdentifier , launchResult ) ;
118
+ this . _lldbProcess = this . $childProcess . spawn ( "lldb" , [ "-p" , pid ] ) ;
119
+ if ( log4js . levels . TRACE . isGreaterThanOrEqualTo ( this . $logger . getLevel ( ) ) ) {
120
+ this . _lldbProcess . stdout . pipe ( process . stdout ) ;
121
+ }
122
+ this . _lldbProcess . stderr . pipe ( process . stderr ) ;
123
+ this . _lldbProcess . stdin . write ( "process continue\n" ) ;
151
124
152
125
return this . wireDebuggerClient ( debugData , debugOptions ) ;
153
126
}
@@ -158,20 +131,10 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
158
131
const attachRequestMessage = this . $iOSNotification . getAttachRequest ( debugData . applicationIdentifier ) ;
159
132
160
133
const iOSEmulatorService = < Mobile . IiOSSimulatorService > this . $iOSEmulatorServices ;
161
- await iOSEmulatorService . postDarwinNotification ( attachRequestMessage ) ;
162
- await this . waitForBackendPortToBeOpened ( debugData . deviceIdentifier ) ;
134
+ await iOSEmulatorService . postDarwinNotification ( attachRequestMessage , debugData . deviceIdentifier ) ;
163
135
return result ;
164
136
}
165
137
166
- private async waitForBackendPortToBeOpened ( deviceIdentifier : string ) : Promise < void > {
167
- const portListens = await this . $net . waitForPortToListen ( { port : inspectorBackendPort , timeout : 10000 , interval : 200 } ) ;
168
- if ( ! portListens ) {
169
- const error = < Mobile . IDeviceError > new Error ( "Unable to connect to application. Ensure application is running on simulator." ) ;
170
- error . deviceIdentifier = deviceIdentifier ;
171
- throw error ;
172
- }
173
- }
174
-
175
138
private async deviceDebugBrk ( debugData : IDebugData , debugOptions : IDebugOptions ) : Promise < string > {
176
139
await this . $devicesService . initialize ( { platform : this . platform , deviceId : debugData . deviceIdentifier } ) ;
177
140
const projectData = this . $projectDataService . getProjectData ( debugData . projectDir ) ;
@@ -219,7 +182,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
219
182
// the VSCode Ext starts `tns debug ios --no-client` to start/attach to debug sessions
220
183
// check if --no-client is passed - default to opening a tcp socket (versus Chrome DevTools (websocket))
221
184
if ( ( debugOptions . inspector || ! debugOptions . client ) && this . $hostInfo . isDarwin ) {
222
- this . _socketProxy = await this . $socketProxyFactory . createTCPSocketProxy ( this . getSocketFactory ( device ) ) ;
185
+ this . _socketProxy = await this . $socketProxyFactory . createTCPSocketProxy ( this . getSocketFactory ( debugData , device ) ) ;
223
186
await this . openAppInspector ( this . _socketProxy . address ( ) , debugData , debugOptions ) ;
224
187
return null ;
225
188
} else {
@@ -228,7 +191,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
228
191
}
229
192
230
193
const deviceIdentifier = device ? device . deviceInfo . identifier : debugData . deviceIdentifier ;
231
- this . _socketProxy = await this . $socketProxyFactory . createWebSocketProxy ( this . getSocketFactory ( device ) , deviceIdentifier ) ;
194
+ this . _socketProxy = await this . $socketProxyFactory . createWebSocketProxy ( this . getSocketFactory ( debugData , device ) , deviceIdentifier ) ;
232
195
return this . getChromeDebugUrl ( debugOptions , this . _socketProxy . options . port ) ;
233
196
}
234
197
}
@@ -247,9 +210,10 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
247
210
}
248
211
}
249
212
250
- private getSocketFactory ( device ?: Mobile . IiOSDevice ) : ( ) => Promise < net . Socket > {
213
+ private getSocketFactory ( debugData : IDebugData , device ?: Mobile . IiOSDevice ) : ( ) => Promise < net . Socket > {
251
214
const factory = async ( ) => {
252
- const socket = device ? await device . connectToPort ( inspectorBackendPort ) : net . connect ( inspectorBackendPort ) ;
215
+ const port = await this . $iOSDebuggerPortService . getPort ( { deviceId : debugData . deviceIdentifier , appId : debugData . applicationIdentifier } ) ;
216
+ const socket = device ? await device . connectToPort ( port ) : net . connect ( port ) ;
253
217
this . _sockets . push ( socket ) ;
254
218
return socket ;
255
219
} ;
0 commit comments