| 10 | import { getDeviceVersion } from "../schema/device.type"; |
| 11 | |
| 12 | class IDF { |
| 13 | tunnelManager: TunnelManager; |
| 14 | wdaStreamClient: WdaStreamClient; |
| 15 | wdaControlClient?: WdaControlClient; |
| 16 | wdaGoIOS?: WdaGoIOS; |
| 17 | |
| 18 | udid: string; |
| 19 | version: number; |
| 20 | socketClient: Socket; |
| 21 | |
| 22 | controlPort?: number; |
| 23 | streamPort?: number; |
| 24 | |
| 25 | streamClient?: SubProcess; |
| 26 | |
| 27 | constructor(udid: string, version: string, socket: Socket) { |
| 28 | this.socketClient = socket; |
| 29 | this.udid = udid; |
| 30 | this.tunnelManager = new TunnelManager(udid); |
| 31 | this.wdaStreamClient = new WdaStreamClient(); |
| 32 | this.version = getDeviceVersion(version); |
| 33 | } |
| 34 | |
| 35 | getPorts() { |
| 36 | return [this.controlPort, this.streamPort]; |
| 37 | } |
| 38 | |
| 39 | async sendCommand(data: any) { |
| 40 | logger.info(`send command ${JSON.stringify(data)}`); |
| 41 | try { |
| 42 | if (this.wdaControlClient) { |
| 43 | const cmd = buildCommand(data); |
| 44 | await this.wdaControlClient.performCommand(cmd); |
| 45 | } |
| 46 | } catch (error) { |
| 47 | logger.error(`error in send command`, error); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | async start() { |
| 52 | const [controlPort, streamPort] = await findFreePorts(2); |
| 53 | this.controlPort = controlPort; |
| 54 | this.streamPort = streamPort; |
| 55 | /** |
| 56 | * start tunnel for control port |
| 57 | */ |
| 58 | try { |
| 59 | await this.tunnelManager.startControlTunnel(controlPort); |
| 60 | } catch (error) { |
| 61 | logger.error(`error start tunnel for control port`, error); |
| 62 | await this.stop(); |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * start tunnel for stream port |
| 68 | */ |
| 69 | try { |
nothing calls this directly
no outgoing calls
no test coverage detected