-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.ts
112 lines (100 loc) · 3.14 KB
/
index.ts
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import Lights from "./classes/Lights";
import Colors from "./classes/Colors";
import fs from "fs";
import { Atem } from "atem-connection";
import IConfig from "./classes/IConfig";
const config: IConfig = JSON.parse(
fs.readFileSync("./tally.config.json", "utf-8")
);
const switcher = new Atem();
function allDisconnected() {
for (const tally of config.tallies) {
const lights = tally.lights;
if (lights === undefined) {
console.warn(
"Light object on the configured tally is not yet defined."
);
continue;
}
lights.startFlashing(
tally.disconnectedFlashColor[0],
tally.disconnectedFlashColor[1],
tally.disconnectedFlashColor[2],
tally.disconnectedFlashFrequency
);
}
}
function allConnected() {
for (const tally of config.tallies) {
const lights = tally.lights;
if (lights === undefined) {
console.warn(
"Light object on the configured tally is not yet defined."
);
continue;
}
lights.stopFlashing();
}
}
switcher.on("connected", () => {
console.log("Connected.");
allConnected();
});
switcher.on("disconnected", () => {
console.warn("Lost connection!");
allDisconnected();
});
switcher.on("stateChanged", (state: any) => {
// State does not always contain ME video data; Return if necessary data is missing.
if (!state || !state.video || !state.video.ME || !state.video.ME[0]) {
return;
}
const mixer = state.video.ME[0];
const pvw = mixer.previewInput;
const pgm = mixer.programInput;
for (const tally of config.tallies) {
if (tally.lights === undefined) {
console.warn(
"Light object on the configured tally is not yet defined."
);
continue;
}
// If faded to black, lights are always off
if (mixer?.fadeToBlack?.isFullyBlack) {
tally.lights.off();
continue;
}
// This camera is either in program OR preview, and there is an ongoing transition.
if (
mixer.inTransition &&
(tally.inputID === pgm || tally.inputID === pvw)
) {
tally.lights.write(Colors.YELLOW);
} else if (tally.inputID === pgm) {
// This camera is in program.
tally.lights.write(Colors.RED);
} else if (tally.inputID === pvw) {
// This camera is in preview.
tally.lights.write(Colors.GREEN);
} else {
// Camera is not in any preview or program.
tally.lights.off();
}
}
});
if (!config.tallies || !config.switcherIP) {
console.error("No tally lights or switcher IP configured!");
process.exit();
}
for (const tally of config.tallies) {
// Create the Lights object based off the Tally's config values
tally.lights = new Lights(
tally.ledGpioPins[0],
tally.ledGpioPins[1],
tally.ledGpioPins[2],
tally.invertSignals
);
}
allDisconnected();
console.log("Connecting...");
switcher.connect(config.switcherIP);