@@ -20,10 +20,6 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
2020 return this . deviceTcpServers [ `${ deviceIdentifier } -${ appId } ` ] ;
2121 }
2222
23- public getWebSocketProxy ( deviceIdentifier : string , appId : string ) : ws . Server {
24- return this . deviceWebServers [ `${ deviceIdentifier } -${ appId } ` ] ;
25- }
26-
2723 public async addTCPSocketProxy ( device : Mobile . IiOSDevice , appId : string ) : Promise < net . Server > {
2824 const cacheKey = `${ device . deviceInfo . identifier } -${ appId } ` ;
2925 const existingServer = this . deviceTcpServers [ cacheKey ] ;
@@ -84,7 +80,17 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
8480 return server ;
8581 }
8682
87- public async addWebSocketProxy ( device : Mobile . IiOSDevice , appId : string ) : Promise < ws . Server > {
83+ public async ensureWebSocketProxy ( device : Mobile . IiOSDevice , appId : string ) : Promise < ws . Server > {
84+ const existingWebProxy = this . deviceWebServers [ `${ device . deviceInfo . identifier } -${ appId } ` ] ;
85+ const result = existingWebProxy || await this . addWebSocketProxy ( device , appId ) ;
86+
87+ // TODO: do not remove till VSCode waits for this message in order to reattach
88+ this . $logger . info ( "Opened localhost " + result . options . port ) ;
89+
90+ return result ;
91+ }
92+
93+ private async addWebSocketProxy ( device : Mobile . IiOSDevice , appId : string ) : Promise < ws . Server > {
8894 const cacheKey = `${ device . deviceInfo . identifier } -${ appId } ` ;
8995 const existingServer = this . deviceWebServers [ cacheKey ] ;
9096 if ( existingServer ) {
@@ -152,12 +158,11 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
152158 appDebugSocket . on ( "close" , ( ) => {
153159 this . $logger . info ( "Backend socket closed!" ) ;
154160 webSocket . close ( ) ;
155- server . close ( ) ;
156- delete this . deviceWebServers [ cacheKey ] ;
157161 } ) ;
158162
159163 webSocket . on ( "close" , ( ) => {
160164 this . $logger . info ( 'Frontend socket closed!' ) ;
165+ appDebugSocket . unpipe ( packets ) ;
161166 packets . destroy ( ) ;
162167 device . destroyDebugSocket ( appId ) ;
163168 if ( ! this . $options . watch ) {
@@ -167,7 +172,6 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
167172
168173 } ) ;
169174
170- this . $logger . info ( "Opened localhost " + localPort ) ;
171175 return server ;
172176 }
173177
0 commit comments