@hap-toolkit/debugger 1.9.7 → 1.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adb/module.js +1 -1
- package/package.json +3 -3
package/lib/adb/module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _adbDevicesEmitter=_interopRequireDefault(require("adb-devices-emitter")),_adbCommander=_interopRequireDefault(require("adb-commander")),_sharedUtils=require("@hap-toolkit/shared-utils"),_recordClient=require("@hap-toolkit/shared-utils/lib/record-client"),_config=_interopRequireDefault(require("@hap-toolkit/shared-utils/config")),_debuglog=_interopRequireDefault(require("./debuglog"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const REMOTE_REVERSE_PORT=12306,REMOTE_UP_FORWARD_PORT=39517;class ADBModule{constructor(e){this.option=e,this.currentDeviceMap=new Map,this.cachedDeviceMap=new Map,this.DEBUG=(process.env.NODE_DEBUG||"").split(",").includes("adb"),this._localUpForwardPort=39517,this.commander=_adbCommander.default,this.devicesEmitter=_adbDevicesEmitter.default,this._lastPromise=null,this.emulators=new Map,this.init()}init(){(0,_debuglog.default)("init(): start"),this.devicesEmitter.addEventListener("deviceAdded",e=>{this._listen(e,this.onDeviceAdded.bind(this))}),this.devicesEmitter.addEventListener("deviceRemoved",e=>{this._listen(e,this.onDeviceRemoved.bind(this))}),this.devicesEmitter.start()}_listen(e,r){this._lastPromise?this._lastPromise=this._lastPromise.then(()=>r(e),()=>r(e)):this._lastPromise=r(e)}_getNextLocalForwardPort(){return this._localUpForwardPort++}async onDeviceAdded(e){const{sn:r}=e;_sharedUtils.colorconsole.info(`### App Server ### 设备"${r}"被连入`);const{result:t}=await this.commander.getProp(r);t&&this.emulators.set(t.trim(),r);const i=this.option.localReversePort;if((await this.establishADBProxyLink("reverse",[r,i,12306])).err)return void _sharedUtils.colorconsole.error(`### App Server ### onDeviceAdded(): (${r})建立adb reverse失败(local port: ${i}, remote port: 12306)`);let o=this.cachedDeviceMap.get(r);if((0,_debuglog.default)(`onDeviceAdded():(${r})\ncachedDevice:\t${JSON.stringify(o)}\ncachedDeviceList:\t${JSON.stringify(Array.from(this.cachedDeviceMap.entries()))}`),o&&o.upForwardPortPair||(o={upForwardPortPair:[this._getNextLocalForwardPort(),39517]}),(await this.establishADBProxyLink("forward",[r].concat(o.upForwardPortPair))).err)_sharedUtils.colorconsole.error(`### App Server ### onDeviceAdded(): (${r})建立adb forward失败(local port: ${o.upForwardPortPair[0]}, remote port: ${o.upForwardPortPair[1]}) `);else{if(o.wsPortPair){(await this.establishADBProxyLink("forward",[r,o.wsPortPair[0],o.wsPortPair[1]])).err&&(_sharedUtils.colorconsole.warn(`### App Server ### onDeviceAdded():(${r}) 建立adb forward失败(local port: ${o.wsPortPair[0]}, remote port: ${o.wsPortPair[1]})`),o.wsPortPair=void 0)}this.currentDeviceMap.set(r,o),this.cachedDeviceMap.set(r,o),await this._writeClientLogFile({sn:r,ip:"127.0.0.1",port:o.upForwardPortPair[0]}),(0,_debuglog.default)(`onDeviceAdded():(${r}) end`)}}async onDeviceRemoved(e){const{sn:r}=e;_sharedUtils.colorconsole.info(`### App Server ### 手机设备(${r})被拔出`),this.currentDeviceMap.delete(r),this.DEBUG&&((0,_debuglog.default)(`deviceRemoved():(${r}) cachedDeviceList: ${JSON.stringify(Array.from(this.cachedDeviceMap.entries()))}`),await this.commander.print(`adb -s ${r} reverse --list`),await this.commander.print(`adb -s ${r} forward --list`)),await this._removeItemFromClientLogFile(r),(0,_debuglog.default)(`deviceRemoved():(${r}) end`)}async _writeClientLogFile(e){try{const{clientRecordPath:r}=_config.default;(0,_recordClient.recordClient)(r,e,e=>{(0,_debuglog.default)(e)})}catch(e){_sharedUtils.colorconsole.error("### App Server ### writeClientLogFile(): 写入hap-toolkit-client-records.json文件出错: "+e.message)}}async _removeItemFromClientLogFile(e){try{const{clientRecordPath:r}=_config.default;(0,_recordClient.removeClientBySn)(r,e,e=>{(0,_debuglog.default)(e)})}catch(e){_sharedUtils.colorconsole.error("### App Server ### _removeItemFromClientLogFile(): 移除hap-toolkit-client-records.json设备信息出错: "+e.message)}}async forwardForWsChannel(e,r){let t=this.currentDeviceMap.get(e);const i=r;if(!t){const r=this.emulators.get(e);_sharedUtils.colorconsole.warn(`### App Server ### 通过(${e})查找到设备${r}`),t=this.currentDeviceMap.get(r),t&&(e=r)}if(!t)return _sharedUtils.colorconsole.error(`### App Server ### 获取(${e})设备信息失败`),{localWsPort:i};const o=t.wsPortPair;if(o&&o[0]===i&&o[1]===r)return{localWsPort:i};const{err:s}=await this.establishADBProxyLink("forward",[e,i,r]);return s?(_sharedUtils.colorconsole.error("### AppApp Server ### forwardForWsChannel(): 创建WebSocket端口映射失败"),t.wsPortPair=void 0,{err:s}):(t.wsPortPair=[i,r],{localWsPort:i})}async establishADBProxyLink(e,r){const t=await this.commander[e](...r);return this.DEBUG&&((0,_debuglog.default)(`establishADBReverseLink(): (${r[0]}) adb ${e} setup result: ${JSON.stringify(t)}`),await this.commander.print(`adb -s ${r[0]} ${e} --list`)),t}}var _default=ADBModule;exports.default=_default;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _adbDevicesEmitter=_interopRequireDefault(require("adb-devices-emitter")),_adbCommander=_interopRequireDefault(require("adb-commander")),_sharedUtils=require("@hap-toolkit/shared-utils"),_recordClient=require("@hap-toolkit/shared-utils/lib/record-client"),_config=_interopRequireDefault(require("@hap-toolkit/shared-utils/config")),_debuglog=_interopRequireDefault(require("./debuglog"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const REMOTE_REVERSE_PORT=12306,REMOTE_UP_FORWARD_PORT=39517;class ADBModule{constructor(e){this.option=e,this.currentDeviceMap=new Map,this.cachedDeviceMap=new Map,this.DEBUG=(process.env.NODE_DEBUG||"").split(",").includes("adb"),this._localUpForwardPort=39517,this.commander=_adbCommander.default,this.devicesEmitter=_adbDevicesEmitter.default,this._lastPromise=null,this.emulators=new Map,this.init()}init(){(0,_debuglog.default)("init(): start"),this.devicesEmitter.addEventListener("deviceAdded",e=>{this._listen(e,this.onDeviceAdded.bind(this))}),this.devicesEmitter.addEventListener("deviceRemoved",e=>{this._listen(e,this.onDeviceRemoved.bind(this))}),this.devicesEmitter.start()}_listen(e,r){this._lastPromise?this._lastPromise=this._lastPromise.then(()=>r(e),()=>r(e)):this._lastPromise=r(e)}_getNextLocalForwardPort(){return this._localUpForwardPort++}async onDeviceAdded(e){const{sn:r}=e;_sharedUtils.colorconsole.info(`### App Server ### 设备"${r}"被连入`);const{result:t}=await this.commander.getProp(r);t&&this.emulators.set(t.trim(),r);const i=this.option.localReversePort;if((await this.establishADBProxyLink("reverse",[r,i,12306])).err)return void _sharedUtils.colorconsole.error(`### App Server ### onDeviceAdded(): (${r})建立adb reverse失败(local port: ${i}, remote port: 12306)`);let o=this.cachedDeviceMap.get(r);if((0,_debuglog.default)(`onDeviceAdded():(${r})\ncachedDevice:\t${JSON.stringify(o)}\ncachedDeviceList:\t${JSON.stringify(Array.from(this.cachedDeviceMap.entries()))}`),o&&o.upForwardPortPair||(o={upForwardPortPair:[this._getNextLocalForwardPort(),39517]}),(await this.establishADBProxyLink("forward",[r].concat(o.upForwardPortPair))).err)_sharedUtils.colorconsole.error(`### App Server ### onDeviceAdded(): (${r})建立adb forward失败(local port: ${o.upForwardPortPair[0]}, remote port: ${o.upForwardPortPair[1]}) `);else{if(o.wsPortPair){(await this.establishADBProxyLink("forward",[r,o.wsPortPair[0],o.wsPortPair[1]])).err&&(_sharedUtils.colorconsole.warn(`### App Server ### onDeviceAdded():(${r}) 建立adb forward失败(local port: ${o.wsPortPair[0]}, remote port: ${o.wsPortPair[1]})`),o.wsPortPair=void 0)}this.currentDeviceMap.set(r,o),this.cachedDeviceMap.set(r,o),await this._writeClientLogFile({sn:r,ip:"127.0.0.1",port:o.upForwardPortPair[0]}),(0,_debuglog.default)(`onDeviceAdded():(${r}) end`)}}async onDeviceRemoved(e){const{sn:r}=e;_sharedUtils.colorconsole.info(`### App Server ### 手机设备(${r})被拔出`),this.currentDeviceMap.delete(r),this.DEBUG&&((0,_debuglog.default)(`deviceRemoved():(${r}) cachedDeviceList: ${JSON.stringify(Array.from(this.cachedDeviceMap.entries()))}`),await this.commander.print(`adb -s ${r} reverse --list`),await this.commander.print(`adb -s ${r} forward --list`)),await this._removeItemFromClientLogFile(r),(0,_debuglog.default)(`deviceRemoved():(${r}) end`)}async _writeClientLogFile(e){try{const{clientRecordPath:r}=_config.default;(0,_recordClient.recordClient)(r,e,e=>{(0,_debuglog.default)(e)})}catch(e){_sharedUtils.colorconsole.error("### App Server ### writeClientLogFile(): 写入hap-toolkit-client-records.json文件出错: "+e.message)}}async _removeItemFromClientLogFile(e){try{const{clientRecordPath:r}=_config.default;(0,_recordClient.removeClientBySn)(r,e,e=>{(0,_debuglog.default)(e)})}catch(e){_sharedUtils.colorconsole.error("### App Server ### _removeItemFromClientLogFile(): 移除hap-toolkit-client-records.json设备信息出错: "+e.message)}}async forwardForWsChannel(e,r){let t=this.currentDeviceMap.get(e);const i=r;if(!t){const r=this.emulators.get(e);_sharedUtils.colorconsole.warn(`### App Server ### 通过(${e})查找到设备${r}`),t=this.currentDeviceMap.get(r),t&&(e=r)}if(!t)return _sharedUtils.colorconsole.error(`### App Server ### 获取(${e})设备信息失败`),{localWsPort:i};const o=t.wsPortPair;if(o&&o[0]===i&&o[1]===r)return{localWsPort:i};const{err:s}=await this.establishADBProxyLink("forward",[e,i,r]);return s?(_sharedUtils.colorconsole.error("### AppApp Server ### forwardForWsChannel(): 创建WebSocket端口映射失败"),t.wsPortPair=void 0,{err:s}):(t.wsPortPair=[i,r],{localWsPort:i})}async establishADBProxyLink(e,r){const t=await this.commander[e](...r);return this.DEBUG&&((0,_debuglog.default)(`establishADBReverseLink(): (${r[0]}) adb ${e} setup result: ${JSON.stringify(t)}`),await this.commander.print(`adb -s ${r[0]} ${e} --list`)),t}_stop(){_sharedUtils.colorconsole.log("### ADB stop"),this.devicesEmitter.stop()}}var _default=ADBModule;exports.default=_default;
|
|
2
2
|
//# sourceMappingURL=module.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hap-toolkit/debugger",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.8",
|
|
4
4
|
"description": "@hap-toolkit/debugger",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.0.0"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@hap-toolkit/chrome-devtools-frontend": "^1.1.2",
|
|
27
|
-
"@hap-toolkit/shared-utils": "1.9.
|
|
27
|
+
"@hap-toolkit/shared-utils": "1.9.8",
|
|
28
28
|
"@sentry/node": "^5.26.0",
|
|
29
29
|
"adb-commander": "^0.1.9",
|
|
30
30
|
"adb-devices-emitter": "^0.1.9",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"mini-css-extract-plugin": "^1.3.0",
|
|
45
45
|
"mkdirp": "^0.5.5"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "f0e6052f5577bf9b3c139e960855f428540c517c"
|
|
48
48
|
}
|