-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
48 lines (38 loc) · 1.06 KB
/
client.js
File metadata and controls
48 lines (38 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const ipc = require("@node-ipc/node-ipc").default;
if (process.argv.length === 2) {
console.error("Expected at least one argument!");
process.exit(1);
}
ipc.config.id = "hello";
ipc.config.retry = 1500;
ipc.config.rawBuffer = true;
ipc.config.encoding = "utf-8";
ipc.config.silent = true;
ipc.connectTo("world", function () {
ipc.of.world.on("connect", function () {
let text = process.argv[2];
text = text.split("\n").join(" ");
const apiKey = process.argv[3];
const prerun = process.argv[4];
ipc.of.world.emit(JSON.stringify([text, apiKey, prerun]));
});
ipc.of.world.on("data", function (data) {
try {
data = JSON.parse(data);
if (data.method == "status") {
// console.info(data.message);
}
if (data.method == "stdout") {
process.stdout.write(data.message);
}
if (data.method == "stderr") {
process.stderr.write(data.message);
}
if (data.method == "close") {
process.exit(0);
}
} catch (e) {
// console.error(e);
}
});
});