Skip to content

Commit 3dd15bc

Browse files
committed
fix: log the proxy port even when returning a cached proxy instead of recreating it each time
1 parent 95e9cbb commit 3dd15bc

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

lib/declarations.d.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,7 @@ interface IAppDebugSocketProxyFactory extends NodeJS.EventEmitter {
735735
getTCPSocketProxy(deviceIdentifier: string, appId: string): any;
736736
addTCPSocketProxy(device: Mobile.IiOSDevice, appId: string): Promise<any>;
737737

738-
getWebSocketProxy(deviceIdentifier: string, appId: string): any;
739-
addWebSocketProxy(device: Mobile.IiOSDevice, appId: string): Promise<any>;
738+
ensureWebSocketProxy(device: Mobile.IiOSDevice, appId: string): Promise<any>;
740739

741740
removeAllProxies(): void;
742741
}

lib/device-sockets/ios/app-debug-socket-proxy-factory.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -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

lib/services/ios-device-debug-service.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ export class IOSDeviceDebugService extends DebugServiceBase implements IDeviceDe
160160
if (debugOptions.chrome) {
161161
this.$logger.info("'--chrome' is the default behavior. Use --inspector to debug iOS applications using the Safari Web Inspector.");
162162
}
163-
const existingWebProxy = this.$appDebugSocketProxyFactory.getWebSocketProxy(this.deviceIdentifier, debugData.applicationIdentifier);
164-
const webSocketProxy = existingWebProxy || await this.$appDebugSocketProxyFactory.addWebSocketProxy(this.device, debugData.applicationIdentifier);
163+
const webSocketProxy = await this.$appDebugSocketProxyFactory.ensureWebSocketProxy(this.device, debugData.applicationIdentifier);
165164

166165
return this.getChromeDebugUrl(debugOptions, webSocketProxy.options.port);
167166
}

0 commit comments

Comments
 (0)