1
1
import * as iOSDevice from "../common/mobile/ios/device/ios-device" ;
2
- import * as net from "net" ;
3
2
import * as path from "path" ;
4
3
import * as log4js from "log4js" ;
5
4
import { ChildProcess } from "child_process" ;
@@ -13,8 +12,6 @@ const inspectorUiDir = "WebInspectorUI/";
13
12
14
13
export class IOSDebugService extends DebugServiceBase implements IPlatformDebugService {
15
14
private _lldbProcess : ChildProcess ;
16
- private _sockets : net . Socket [ ] = [ ] ;
17
- private _socketProxy : any ;
18
15
19
16
constructor ( protected device : Mobile . IiOSDevice ,
20
17
protected $devicesService : Mobile . IDevicesService ,
@@ -74,19 +71,10 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
74
71
}
75
72
76
73
public async debugStop ( ) : Promise < void > {
77
- if ( this . _socketProxy ) {
78
- this . _socketProxy . close ( ) ;
79
- this . _socketProxy = null ;
80
- }
81
-
82
- _ . forEach ( this . _sockets , socket => socket . destroy ( ) ) ;
83
-
84
- this . _sockets = [ ] ;
85
74
this . $socketProxyFactory . removeAllProxies ( ) ;
86
75
87
76
if ( this . _lldbProcess ) {
88
77
this . _lldbProcess . stdin . write ( "process detach\n" ) ;
89
-
90
78
await this . killProcess ( this . _lldbProcess ) ;
91
79
this . _lldbProcess = undefined ;
92
80
}
@@ -210,11 +198,11 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
210
198
// check if --no-client is passed - default to opening a tcp socket (versus Chrome DevTools (websocket))
211
199
const deviceIdentifier = this . device ? this . device . deviceInfo . identifier : debugData . deviceIdentifier ;
212
200
if ( ( debugOptions . inspector || ! debugOptions . client ) && this . $hostInfo . isDarwin ) {
213
- const existingProxy = this . $socketProxyFactory . getTCPSocketProxy ( deviceIdentifier ) ;
214
- this . _socketProxy = existingProxy || await this . $socketProxyFactory . addTCPSocketProxy ( this . getSocketFactory ( debugData , debugOptions ) , deviceIdentifier ) ;
215
-
216
- if ( ! existingProxy ) {
217
- await this . openAppInspector ( this . _socketProxy . address ( ) , debugData , debugOptions ) ;
201
+ const existingTcpProxy = this . $socketProxyFactory . getTCPSocketProxy ( deviceIdentifier ) ;
202
+ const getDeviceSocket = async ( ) => await this . device . getDebugSocket ( debugData . applicationIdentifier , debugData . projectDir ) ;
203
+ const tcpSocketProxy = existingTcpProxy || await this . $socketProxyFactory . addTCPSocketProxy ( getDeviceSocket , deviceIdentifier ) ;
204
+ if ( ! existingTcpProxy ) {
205
+ await this . openAppInspector ( tcpSocketProxy . address ( ) , debugData , debugOptions ) ;
218
206
}
219
207
220
208
return null ;
@@ -223,9 +211,11 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
223
211
this . $logger . info ( "'--chrome' is the default behavior. Use --inspector to debug iOS applications using the Safari Web Inspector." ) ;
224
212
}
225
213
226
- const existingProxy = this . $socketProxyFactory . getWebSocketProxy ( deviceIdentifier ) ;
227
- this . _socketProxy = existingProxy || await this . $socketProxyFactory . addWebSocketProxy ( this . getSocketFactory ( debugData , debugOptions ) , deviceIdentifier ) ;
228
- return this . getChromeDebugUrl ( debugOptions , this . _socketProxy . options . port ) ;
214
+ const existingWebProxy = this . $socketProxyFactory . getWebSocketProxy ( deviceIdentifier ) ;
215
+ const getDeviceSocket = async ( ) => await this . device . getDebugSocket ( debugData . applicationIdentifier , debugData . projectDir ) ;
216
+ const webSocketProxy = existingWebProxy || await this . $socketProxyFactory . addWebSocketProxy ( getDeviceSocket , deviceIdentifier ) ;
217
+
218
+ return this . getChromeDebugUrl ( debugOptions , webSocketProxy . options . port ) ;
229
219
}
230
220
}
231
221
@@ -242,26 +232,6 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
242
232
this . $logger . info ( "Suppressing debugging client." ) ;
243
233
}
244
234
}
245
-
246
- private getSocketFactory ( debugData : IDebugData , debugOptions : IDebugOptions ) : ( ) => Promise < net . Socket > {
247
- let pendingExecution : Promise < net . Socket > = null ;
248
- const factory = async ( ) => {
249
- if ( ! pendingExecution ) {
250
- const func = async ( ) => {
251
- const socket = await this . device . getDebugSocket ( debugData . applicationIdentifier , debugData . projectDir ) ;
252
- this . _sockets . push ( socket ) ;
253
- pendingExecution = null ;
254
- return socket ;
255
- } ;
256
- pendingExecution = func ( ) ;
257
- }
258
-
259
- return pendingExecution ;
260
- } ;
261
-
262
- factory . bind ( this ) ;
263
- return factory ;
264
- }
265
235
}
266
236
267
- $injector . register ( "iOSDebugService" , IOSDebugService , false ) ;
237
+ $injector . register ( "iOSDebugService" , IOSDebugService , false ) ;
0 commit comments