11import * as iOSDevice from "../common/mobile/ios/device/ios-device" ;
2- import * as net from "net" ;
32import * as path from "path" ;
43import * as log4js from "log4js" ;
54import { ChildProcess } from "child_process" ;
@@ -13,8 +12,6 @@ const inspectorUiDir = "WebInspectorUI/";
1312
1413export class IOSDebugService extends DebugServiceBase implements IPlatformDebugService {
1514 private _lldbProcess : ChildProcess ;
16- private _sockets : net . Socket [ ] = [ ] ;
17- private _socketProxy : any ;
1815
1916 constructor ( protected device : Mobile . IiOSDevice ,
2017 protected $devicesService : Mobile . IDevicesService ,
@@ -74,19 +71,10 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
7471 }
7572
7673 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 = [ ] ;
8574 this . $socketProxyFactory . removeAllProxies ( ) ;
8675
8776 if ( this . _lldbProcess ) {
8877 this . _lldbProcess . stdin . write ( "process detach\n" ) ;
89-
9078 await this . killProcess ( this . _lldbProcess ) ;
9179 this . _lldbProcess = undefined ;
9280 }
@@ -210,11 +198,11 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
210198 // check if --no-client is passed - default to opening a tcp socket (versus Chrome DevTools (websocket))
211199 const deviceIdentifier = this . device ? this . device . deviceInfo . identifier : debugData . deviceIdentifier ;
212200 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 ) ;
218206 }
219207
220208 return null ;
@@ -223,9 +211,11 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
223211 this . $logger . info ( "'--chrome' is the default behavior. Use --inspector to debug iOS applications using the Safari Web Inspector." ) ;
224212 }
225213
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 ) ;
229219 }
230220 }
231221
@@ -242,26 +232,6 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
242232 this . $logger . info ( "Suppressing debugging client." ) ;
243233 }
244234 }
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- }
265235}
266236
267- $injector . register ( "iOSDebugService" , IOSDebugService , false ) ;
237+ $injector . register ( "iOSDebugService" , IOSDebugService , false ) ;
0 commit comments