microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
readme-sync-master-command-behaviors

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/debugger/direct/IWDPHelper.ts

86lines · modeblame

259c018fYuri Skorokhodov5 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
09f6024fHeniker4 years ago4import * as cp from "child_process";
259c018fYuri Skorokhodov5 years ago5import { PromiseUtil } from "../../common/node/promise";
6import { Request } from "../../common/node/request";
7import { IAttachRequestArgs } from "../debugSessionBase";
8import { ErrorHelper } from "../../common/error/errorHelper";
9import { InternalErrorCode } from "../../common/error/internalErrorCode";
10
11/**
12* Helper class to control [ios-webkit-debug-proxy](https://github.com/google/ios-webkit-debug-proxy)
13*/
14export class IWDPHelper {
15private iOSWebkitDebugProxyProcess: cp.ChildProcess | null;
16public static readonly iOS_WEBKIT_DEBUG_PROXY_DEFAULT_PORT: number = 9221;
17
18constructor() {
19this.iOSWebkitDebugProxyProcess = null;
20}
21
0d77292aJiglioNero4 years ago22public async startiOSWebkitDebugProxy(
34472878RedMickey5 years ago23proxyPort: number,
24proxyRangeStart: number,
25proxyRangeEnd: number,
26): Promise<void> {
259c018fYuri Skorokhodov5 years ago27return new Promise((resolve, reject) => {
28this.cleanUp();
29
09f6024fHeniker4 years ago30const portRange = `null:${proxyPort},:${proxyRangeStart}-${proxyRangeEnd}`;
77e86943lexie0111 years ago31this.iOSWebkitDebugProxyProcess = cp.spawn(
32"ios_webkit_debug_proxy",
33["-c", portRange],
34{ shell: true },
35);
34472878RedMickey5 years ago36this.iOSWebkitDebugProxyProcess.on("error", err => {
09f6024fHeniker4 years ago37reject(new Error(`Unable to start ios_webkit_debug_proxy: ${String(err)}`));
259c018fYuri Skorokhodov5 years ago38});
39// Allow some time for the spawned process to error out
09f6024fHeniker4 years ago40void PromiseUtil.delay(250).then(() => resolve());
259c018fYuri Skorokhodov5 years ago41});
42}
43
0d77292aJiglioNero4 years ago44public async getSimulatorProxyPort(
34472878RedMickey5 years ago45attachArgs: IAttachRequestArgs,
46): Promise<{ targetPort: number; iOSVersion: string }> {
0d77292aJiglioNero4 years ago47const response = await Request.request(`http://localhost:${attachArgs.port}/json`, true);
48try {
49// An example of a json response from IWDP
50// [{
51// "deviceId": "00008020-XXXXXXXXXXXXXXXX",
52// "deviceName": "iPhone name",
53// "deviceOSVersion": "13.4.1",
54// "url": "localhost:9223"
55// }]
09f6024fHeniker4 years ago56const endpointsList = JSON.parse(response);
259c018fYuri Skorokhodov5 years ago57
0d77292aJiglioNero4 years ago58let devices = endpointsList;
59if (attachArgs.target) {
60devices = endpointsList.filter((entry: { deviceId: string }) =>
61attachArgs.target?.toLowerCase() === "device"
62? entry.deviceId !== "SIMULATOR"
63: entry.deviceId === "SIMULATOR",
64);
65}
259c018fYuri Skorokhodov5 years ago66
09f6024fHeniker4 years ago67const device = devices[0];
0d77292aJiglioNero4 years ago68// device.url is of the form 'localhost:port'
69return {
70targetPort: parseInt(device.url.split(":")[1], 10),
71iOSVersion: device.deviceOSVersion,
72};
73} catch (e) {
74throw ErrorHelper.getInternalError(
75InternalErrorCode.IOSCouldNotFoundDeviceForDirectDebugging,
76);
77}
d55f3c22Yuri Skorokhodov5 years ago78}
259c018fYuri Skorokhodov5 years ago79
80public cleanUp(): void {
81if (this.iOSWebkitDebugProxyProcess) {
82this.iOSWebkitDebugProxyProcess.kill();
83this.iOSWebkitDebugProxyProcess = null;
84}
85}
34472878RedMickey5 years ago86}