async def adb_forward_to_any(self, remote: str) -> int: """ FIXME(ssx): not finished yet """ # if already forwarded, just return async for f in adb.forward_list(): if f.serial == self._serial: if f.remote == remote and f.local.startswith("tcp:"): return int(f.local[4:]) local_port = freeport.get() await adb.forward(self._serial, 'tcp:{}'.format(local_port), remote) return local_port
async def proxy_device_port(self, device_port: int) -> int: """ reverse-proxy device:port to *:port """ local_port = await self.adb_forward_to_any("tcp:" + str(device_port)) listen_port = freeport.get() logger.debug("%s tcpproxy.js start *:%d -> %d", self, listen_port, local_port) self.run_background([ 'node', 'tcpproxy.js', str(listen_port), 'localhost', str(local_port) ], silent=True) return listen_port
async def _init_forwards(self): logger.debug("%s forward atx-agent", self) self._atx_proxy_port = await self.proxy_device_port(7912) self._whatsinput_port = await self.proxy_device_port(6677) port = self._adb_remote_port = freeport.get() logger.debug("%s adbkit start, port %d", self, port) self.run_background([ 'node', 'node_modules/adbkit/bin/adbkit', 'usb-device-to-tcp', '-p', str(self._adb_remote_port), self._serial ], silent=True)