Skip to content

Commit 6d6bce7

Browse files
committed
refactor: remove sockets knowledge from the ios-debug-service
1 parent e111b79 commit 6d6bce7

File tree

3 files changed

+20
-42
lines changed

3 files changed

+20
-42
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"args": [
1818
"debug",
1919
"ios",
20-
"--hmr"
20+
"--debug-brk"
2121
]
2222
// "args": [ "test", "android", "--justlaunch"]
2323
// "args": [ "platform", "add", "[email protected]", "--path", "cliapp"]

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ export class SocketProxyFactory extends EventEmitter implements ISocketProxyFact
171171
}
172172

173173
public removeAllProxies() {
174+
for (var deviceId in this.deviceWebServers) {
175+
this.deviceWebServers[deviceId].close();
176+
}
177+
178+
for (var deviceId in this.deviceTcpServers) {
179+
this.deviceTcpServers[deviceId].close();
180+
}
181+
174182
this.deviceWebServers = {};
175183
this.deviceTcpServers = {};
176184
}

lib/services/ios-debug-service.ts

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as iOSDevice from "../common/mobile/ios/device/ios-device";
2-
import * as net from "net";
32
import * as path from "path";
43
import * as log4js from "log4js";
54
import { ChildProcess } from "child_process";
@@ -13,8 +12,6 @@ const inspectorUiDir = "WebInspectorUI/";
1312

1413
export 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

Comments
 (0)