@@ -20,10 +20,6 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
20
20
return this . deviceTcpServers [ `${ deviceIdentifier } -${ appId } ` ] ;
21
21
}
22
22
23
- public getWebSocketProxy ( deviceIdentifier : string , appId : string ) : ws . Server {
24
- return this . deviceWebServers [ `${ deviceIdentifier } -${ appId } ` ] ;
25
- }
26
-
27
23
public async addTCPSocketProxy ( device : Mobile . IiOSDevice , appId : string ) : Promise < net . Server > {
28
24
const cacheKey = `${ device . deviceInfo . identifier } -${ appId } ` ;
29
25
const existingServer = this . deviceTcpServers [ cacheKey ] ;
@@ -84,7 +80,17 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
84
80
return server ;
85
81
}
86
82
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 > {
88
94
const cacheKey = `${ device . deviceInfo . identifier } -${ appId } ` ;
89
95
const existingServer = this . deviceWebServers [ cacheKey ] ;
90
96
if ( existingServer ) {
@@ -152,12 +158,11 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
152
158
appDebugSocket . on ( "close" , ( ) => {
153
159
this . $logger . info ( "Backend socket closed!" ) ;
154
160
webSocket . close ( ) ;
155
- server . close ( ) ;
156
- delete this . deviceWebServers [ cacheKey ] ;
157
161
} ) ;
158
162
159
163
webSocket . on ( "close" , ( ) => {
160
164
this . $logger . info ( 'Frontend socket closed!' ) ;
165
+ appDebugSocket . unpipe ( packets ) ;
161
166
packets . destroy ( ) ;
162
167
device . destroyDebugSocket ( appId ) ;
163
168
if ( ! this . $options . watch ) {
@@ -167,7 +172,6 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
167
172
168
173
} ) ;
169
174
170
- this . $logger . info ( "Opened localhost " + localPort ) ;
171
175
return server ;
172
176
}
173
177
0 commit comments