hdckit
Version:
A pure Node.js client for the OpenHarmony Device Connector
44 lines (43 loc) • 1.67 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RemoveForwardPortCommand = exports.ListForwardsCommand = exports.ForwardPortCommand = void 0;
const Command_1 = __importDefault(require("../Command"));
const contain_1 = __importDefault(require("licia/contain"));
const util_1 = require("../util");
class ForwardPortCommand extends Command_1.default {
async execute(local, remote) {
this.send(`fport ${local} ${remote}`);
return this.connection.readValue().then((data) => {
const result = data.toString();
if (!(0, contain_1.default)(result, 'OK')) {
throw new Error(result);
}
});
}
}
exports.ForwardPortCommand = ForwardPortCommand;
class ListForwardsCommand extends Command_1.default {
async execute() {
this.send('fport ls');
return this.connection.readValue().then((data) => {
const result = data.toString();
return (0, util_1.readPorts)(result);
});
}
}
exports.ListForwardsCommand = ListForwardsCommand;
class RemoveForwardPortCommand extends Command_1.default {
async execute(local, remote) {
this.send(`fport rm ${local} ${remote}`);
return this.connection.readValue().then((data) => {
const result = data.toString();
if (!(0, contain_1.default)(result, 'success')) {
throw new Error(result);
}
});
}
}
exports.RemoveForwardPortCommand = RemoveForwardPortCommand;