UNPKG

debug-server-next

Version:

Dev server for hippy-core.

123 lines (122 loc) 4.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.patchDebugTarget = exports.createTargetByIWDPPage = exports.createTargetByWsUrlParams = exports.createTargetByDeviceInfo = void 0; const tslib_1 = require("tslib"); const enum_1 = require("@/@types/enum"); const url_1 = require("@/utils/url"); const config_1 = require("@/config"); const iwdp_1 = require("@/utils/iwdp"); /** * 通过 device 信息创建调试对象 */ const createTargetByDeviceInfo = (device) => { // 通过 tunnel 创建的 target,暂时使用 devicename 作为调试对象 id,后续终端重构后使用 targetCreated 事件抛出的 id const clientId = device.devicename; const wsUrl = url_1.makeUrl(`${config_1.config.domain}${config_1.config.wsPath}`, { clientId, role: enum_1.ClientRole.Devtools, }); const devtoolsFrontendUrl = url_1.makeUrl(`http://${config_1.config.domain}/front_end/inspector.html`, { remoteFrontend: true, experiments: true, ws: wsUrl, env: global.debugAppArgv.env, }); const title = device.platform === "1" /* IOS */ ? clientId : 'Hippy debug tools for V8'; return { clientId, devtoolsFrontendUrl, thumbnailUrl: '', title, url: '', description: '', webSocketDebuggerUrl: `ws://${wsUrl}`, platform: device.platform, type: enum_1.ChromePageType.Page, appClientTypeList: ["TunnelAppClient" /* Tunnel */], deviceId: device.deviceid, deviceName: device.devicename, deviceOSVersion: device.osVersion, }; }; exports.createTargetByDeviceInfo = createTargetByDeviceInfo; /** * 通过 ws 连接 url 创建调试对象 */ const createTargetByWsUrlParams = (wsUrlParams) => { const { clientId, clientRole, contextName, deviceName } = wsUrlParams; let platform; if (clientRole === enum_1.ClientRole.Android) platform = "2" /* Android */; if (clientRole === enum_1.ClientRole.IOS) platform = "1" /* IOS */; const wsUrl = url_1.makeUrl(`${config_1.config.domain}${config_1.config.wsPath}`, { clientId, role: enum_1.ClientRole.Devtools, }); const devtoolsFrontendUrl = url_1.makeUrl(`http://${config_1.config.domain}/front_end/inspector.html`, { remoteFrontend: true, experiments: true, ws: wsUrl, env: global.debugAppArgv.env, }); return { clientId, devtoolsFrontendUrl, thumbnailUrl: '', title: contextName, url: '', description: '', webSocketDebuggerUrl: `ws://${wsUrl}`, platform, type: enum_1.ChromePageType.Page, deviceName, appClientTypeList: ["WsAppClient" /* WS */], }; }; exports.createTargetByWsUrlParams = createTargetByWsUrlParams; /** * 通过 IWDP 获取到的页面创建调试对象 */ const createTargetByIWDPPage = (iWDPPage) => { const iWDPWsUrl = iWDPPage.webSocketDebuggerUrl; const wsUrl = url_1.makeUrl(`${config_1.config.domain}${config_1.config.wsPath}`, { clientId: iWDPWsUrl, role: enum_1.ClientRole.Devtools, }); const devtoolsFrontendUrl = url_1.makeUrl(`http://${config_1.config.domain}/front_end/inspector.html`, { remoteFrontend: true, experiments: true, ws: wsUrl, env: global.debugAppArgv.env, }); return { clientId: iWDPWsUrl, iWDPWsUrl, devtoolsFrontendUrl, title: iWDPPage.title, thumbnailUrl: '', url: '', description: '', webSocketDebuggerUrl: `ws://${wsUrl}`, platform: "1" /* IOS */, type: enum_1.ChromePageType.Page, deviceId: iWDPPage.device.deviceId, deviceName: iWDPPage.device.deviceName, deviceOSVersion: iWDPPage.device.deviceOSVersion, appClientTypeList: ["IWDPAppClient" /* IWDP */], }; }; exports.createTargetByIWDPPage = createTargetByIWDPPage; /** * 补充完整 debugTarget 信息。 * 当 iOS 根据 device 创建出调试对象时,用 IWDP 获取到的额外信息加以补充 */ const patchDebugTarget = (debugTarget) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { if (debugTarget.platform === "1" /* IOS */) { const iOSPages = yield iwdp_1.getIWDPPages(global.debugAppArgv.iWDPPort); return iwdp_1.patchIOSTarget(debugTarget, iOSPages); } return debugTarget; }); exports.patchDebugTarget = patchDebugTarget;