FREAK
This commit is contained in:
parent
1a59316e51
commit
d8a13f511a
|
|
@ -1,54 +1,54 @@
|
||||||
const EventEmitter = require("events");
|
const EventEmitter = require("events")
|
||||||
const child_process = require("child_process");
|
const child_process = require("child_process")
|
||||||
const waitPort = require("wait-port");
|
const waitPort = require("wait-port")
|
||||||
|
|
||||||
const logger = require("../../lib/logger.js");
|
const logger = require("../../lib/logger.js")
|
||||||
const randport = require("../../lib/randport.js");
|
const randport = require("../../lib/randport.js")
|
||||||
|
|
||||||
const chalk = require("chalk");
|
const chalk = require("chalk")
|
||||||
|
|
||||||
class RCCService extends EventEmitter {
|
class RCCService extends EventEmitter {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super()
|
||||||
}
|
}
|
||||||
|
|
||||||
Start() {
|
Start() {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
this.port = await randport.tcp();
|
this.port = await randport.tcp()
|
||||||
|
|
||||||
if (process.platform == "win32") {
|
if (process.platform == "win32") {
|
||||||
this.proc = child_process.spawn("RCCService.exe", ["-Console", "-PlaceId:-1", `-Port`, this.port], { cwd: process.env.RCCSERVICE });
|
this.proc = child_process.spawn("RCCService.exe", ["-Console", "-PlaceId:-1", `-Port`, this.port], { cwd: process.env.RCCSERVICE, stdio: "inherit" })
|
||||||
} else {
|
} else {
|
||||||
this.proc = child_process.spawn("wine", ["RCCService.exe", "-Console", "-PlaceId:-1", `-Port`, this.port], { cwd: process.env.RCCSERVICE });
|
this.proc = child_process.spawn("wine", ["RCCService.exe", "-Console", "-PlaceId:-1", `-Port`, this.port], { cwd: process.env.RCCSERVICE, stdio: "inherit" })
|
||||||
}
|
}
|
||||||
|
|
||||||
this.proc.once("spawn", async () => {
|
this.proc.once("spawn", async () => {
|
||||||
logger.info(`${chalk.gray(`[${this.port}]`)} RCCService instance spawned`);
|
logger.info(`${chalk.gray(`[${this.port}]`)} RCCService instance spawned`)
|
||||||
const { open } = await waitPort({ host: "127.0.0.1", port: this.port, timeout: 5000, output: "silent" }).catch((e) => console.log(e));
|
const { open } = await waitPort({ host: "127.0.0.1", port: this.port, timeout: 5000, output: "silent" }).catch((e) => console.log(e))
|
||||||
if (!open || this.proc.exitCode !== null) {
|
if (!open || this.proc.exitCode !== null) {
|
||||||
this.proc.kill();
|
this.proc.kill()
|
||||||
logger.error(`${chalk.gray(`[${this.port}]`)} RCCService could not listen`);
|
logger.error(`${chalk.gray(`[${this.port}]`)} RCCService could not listen`)
|
||||||
return resolve(false);
|
return resolve(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolve(true);
|
return resolve(true)
|
||||||
});
|
})
|
||||||
|
|
||||||
this.proc.once("exit", () => {
|
this.proc.once("exit", () => {
|
||||||
this.proc.kill();
|
this.proc.kill()
|
||||||
logger.info(`${chalk.gray(`[${this.port}]`)} RCCService instance exited`);
|
logger.info(`${chalk.gray(`[${this.port}]`)} RCCService instance exited`)
|
||||||
});
|
})
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
resolve(false);
|
resolve(false)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
Stop(signal = "SIGTERM") {
|
Stop(signal = "SIGTERM") {
|
||||||
if (!this.proc) return;
|
if (!this.proc) return
|
||||||
return this.proc.kill(signal);
|
return this.proc.kill(signal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = RCCService;
|
module.exports = RCCService
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue