-
Notifications
You must be signed in to change notification settings - Fork 6
/
atem.js
108 lines (101 loc) · 3.62 KB
/
atem.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
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
module.exports = function(RED)
{
//Main Function
function ATEM(config)
{
RED.nodes.createNode(this, config);
var network = RED.nodes.getNode(config.network);
var node = this;
var outputMode = config.outputMode;
var sendTime = config.sendTime;
var sendInitial = config.sendInitialData == "yes";
var sendStatus = config.sendStatusUpdates == "yes";
node.status({fill:"orange",shape:"dot",text:"Connecting..."});
network.addStatusCallback(function(color, message, extraInformation) {
node.status({fill:color,shape:"dot",text:message});
if(extraInformation != "") {
node.error(extraInformation);
}
});
network.addMessageCallback(function(message) {
//Format into the correct format
var messages = [];
if(message.length !== undefined && message.length != null) {
messages = message;
}
else {
messages.push(message);
}
//Loop though the messages
for(var msg in messages) {
message = messages[msg];
if(message.topic == "initial") {
if(sendInitial) {
node.send(message);
}
}
else if(message.topic == "status") {
if(sendStatus) {
node.send(message);
}
}
else if(message.topic == "command"){
//Messages
switch(outputMode) {
case "reply": { //This does not appear to be working and has been disabled
if(message.payload.type == "stateChanged" && msg.sender == this) {
if(!(sendTime === "no" && message.payload.cmd === "time")) {
node.send(message);
}
}
break;
}
case "status": {
if(message.payload.type == "stateChanged") {
if(!(sendTime === "no" && message.payload.cmd === "time")) {
node.send(message);
}
}
break;
}
case "supported": {
if(message.payload.cmd !== "raw") {
if(!(sendTime === "no" && message.payload.cmd === "time")) {
node.send(message);
}
}
break;
}
case "all": {
if(!(sendTime === "no" && message.payload.cmd === "time")) {
node.send(message);
}
break;
}
}
}
else {
node.status({fill:"red",shape:"dot",text:"Internal Error"});
node.error("Unknown command topic sent check console");
console.log("[ERROR] ATEM - Unknown command topic sent: ");
console.log(message);
}
}
});
//Status information
node.sendStatus = function(color, message, extraInformation) {
if(sendStatus) {
node.status({fill:color,shape:"dot",text:message});
if(extraInformation != "") {
node.error(extraInformation);
}
}
}
node.on("close", function() {
});
node.on("input", function(msg) {
network.send(msg, node);
});
}
RED.nodes.registerType("atem-atem", ATEM);
}