-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (35 loc) · 1.15 KB
/
index.js
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
const queueTypeId = process.argv[2];
if (queueTypeId === undefined) {
console.error("Queue channel argument missing!");
console.error("\t try running the process:");
console.error("\t\t" + process.argv[0] + " " + process.argv[1] + " <channelnumber>");
process.exit(-1);
}
const socket = require("./lib/socketConnection")(8080);
global.debug = (message, ...args) => {
socket.send("debug", message + ":\n" + JSON.stringify(args));
console.log(message + ":\n" + JSON.stringify(args));
};
const queue = require("./lib/messageQueue")(1337, parseInt(queueTypeId));
const StateStack = require("./lib/stateStack");
const stack = new StateStack({
sendEvent(...args) {
return queue.send(...args);
},
display(...args) {
return socket.display(...args);
},
sendCaptions(...args) {
return socket.sendCaptions(...args);
},
sendView(...args) {
return socket.send(...args);
}
});
const eventHandler = (arg) => stack.processEvent(arg);
queue.on("event", (...arg) => eventHandler(...arg));
socket.on("remote", (...arg) => {
debug("REMOTE Event", arg);
eventHandler(...arg);
});
queue.start();