node-red-contrib-voice-assistant
Version:
一个小度-小爱-猫精音箱控制NODE-RED自定义设备的节点
67 lines (66 loc) • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
const fs_1 = require("fs");
const uuid_1 = require("uuid");
const ini_1 = require("ini");
class FrpClient {
constructor() {
this.config = {
common: {
server_addr: '47.110.232.79',
server_port: 7000,
},
};
}
createSection(local_addr = '127.0.0.1', local_port = 0, remote_port = 0) {
const section = (0, uuid_1.v4)().replace(/-/g, '');
this.config[section] = {
type: 'tcp',
local_addr: local_addr,
local_port: local_port,
remote_port: remote_port,
};
return section;
}
createConfig() {
(0, fs_1.writeFileSync)(__dirname + '/frpc.ini', (0, ini_1.stringify)(this.config));
}
start() {
try {
this.child = (0, child_process_1.spawn)(__dirname + '/frpc1');
this.child.on('error', function (err) {
console.log(err);
});
this.child.on('close', (code) => {
console.log(code);
this.emitClose && this.emitClose();
});
this.child.stdout.on('data', (msg) => {
console.log(msg.toString());
});
return true;
}
catch (_a) {
return false;
}
}
close(done) {
try {
(0, child_process_1.spawn)('kill', ['-9', this.child.pid.toString()]);
this.emitClose = done;
}
catch (_a) {
done();
}
}
}
const frpcClient = new FrpClient();
frpcClient.createSection(undefined, 1880, 10003);
frpcClient.createConfig();
frpcClient.start();
/* setTimeout(() => {
frpcClient.close(function () {
console.log('关闭完成');
});
}, 5000); */