UNPKG

hdckit

Version:

A pure Node.js client for the OpenHarmony Device Connector

53 lines (52 loc) 1.89 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Connection_1 = __importDefault(require("./Connection")); const Target_1 = __importDefault(require("./Target")); const isStrBlank_1 = __importDefault(require("licia/isStrBlank")); const util_1 = require("./util"); const targets_1 = require("./command/targets"); const forward_1 = require("./command/forward"); const reverse_1 = require("./command/reverse"); class Client { constructor({ host = '127.0.0.1', port = 8710, bin = 'hdc' } = { port: 5037, }) { this.options = { host, port, bin }; } connection(connectKey) { const connection = new Connection_1.default(this.options); return connection.connect(connectKey); } listTargets() { return this.connection().then((conn) => new targets_1.ListTargetsCommand(conn).execute()); } trackTargets() { return this.connection().then((conn) => new targets_1.TrackTargetsCommand(conn).execute()); } getTarget(connectKey) { if ((0, isStrBlank_1.default)(connectKey)) { throw new Error('connectKey is required'); } return new Target_1.default(this, connectKey); } listForwards() { return this.connection().then((conn) => new forward_1.ListForwardsCommand(conn).execute()); } listReverses() { return this.connection().then((conn) => new reverse_1.ListReversesCommand(conn).execute()); } async kill() { const pid = await (0, util_1.getLastPid)(); if (pid) { try { process.kill(pid, 'SIGKILL'); // eslint-disable-next-line } catch (e) { } } } } exports.default = Client;