-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMergeManager.js
More file actions
153 lines (150 loc) · 5.79 KB
/
Copy pathMergeManager.js
File metadata and controls
153 lines (150 loc) · 5.79 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const fetch = require("node-fetch");
class MergeManager {
constructor(io) {
this.io = io;
this._state = {
vmix: {
address: "127.0.0.1",
port: "8088"
},
callers: [],
callersHidden: false,
activeCallers: 0,
previousMixInput: 0,
dualCallerIndex: 0,
numberOfCallers: 4,
maximumCallers: 2,
mixInputs: [0,0],
mixHiddenInputs: [0,0],
callerStart: 1,
callerMVStart: 2,
singleCallerMV: 10,
dualCallerMV: [8,9],
splitInput: 12,
activePair: 0,
pairs: [
{
name: "Inputs visible",
input1: 8,
input2: 9
},
{
name: "Inputs hidden",
input1: 10,
input2: 11
}
]
}
console.log("Run????")
for (let i = 0; i < this._state.numberOfCallers; i++){
var callerObject = {
active: false
}
this._state.callers.push(callerObject);
}
}
get state() {
return this._state;
}
sendState() {
this.io.sockets.emit("state", this.state)
}
setState(state) {
this._state = state;
this.sendvMix();
}
async triggerPair(pair) {
if(pair != this._state.activePair){
this._state.activePair = pair;
await this.vMixCommand("Function=Merge&Input=" + this.selectInput());
await this.sendvMix();
}
this.sendState();
}
addInput(id) {
console.log(id);
if(this._state.activeCallers < this._state.maximumCallers){
this._state.callers[(id-1)].active = true;
}
this.sendvMix();
this.sendState();
}
removeInput(id) {
console.log(id);
this._state.callers[(id-1)].active = false;
this.sendvMix();
this.sendState();
}
async sendvMix(){
this._state.dualCallerIndex = 0;
this._state.activeCallers = 0;
for(var i = 0; i < this._state.callers.length; i++){
if(this._state.callers[i].active == true){
this._state.activeCallers++
}
}
for(var i = 0; i < this._state.callers.length; i++){
if(this._state.callers[i].active == false){
await this.setMultiView(this._state.callerMVStart + i,this._state.callerStart + i);
console.log("Added input " + this._state.callerStart + i + " as Multiview layer " + this._state.callerMVStart + i + " on vMix input " + this._state.mixInputs[1 - this._state.previousMixInput])
}
else if(this._state.callers[i].active == true){
await this.setMultiView(this._state.callerMVStart + i,-2);
if(this._state.activeCallers == 1){
await this.setMultiView(this._state.singleCallerMV,this._state.callerStart + i);
}
else if(this._state.activeCallers == 2){
await this.setMultiView(this._state.dualCallerMV[this._state.dualCallerIndex],this._state.callerStart + i);
this._state.dualCallerIndex++;
}
console.log("Removed input " + this._state.callerStart + i + " as Multiview layer " + this._state.callerMVStart + i + " on vMix input " + this._state.mixInputs[1 - this._state.previousMixInput])
}
}
if(this._state.activeCallers == 0){
await this.setMultiView(this._state.singleCallerMV,-2);
await this.setMultiView(this._state.dualCallerMV[0],-2);
await this.setMultiView(this._state.dualCallerMV[1],-2);
console.log("Empty preset")
}
if(this._state.activeCallers == 1){
await this.setMultiView(this._state.dualCallerMV[0],-2);
await this.setMultiView(this._state.dualCallerMV[1],-2);
}
if(this._state.activeCallers == 2){
await this.setMultiView(this._state.singleCallerMV,-2);
this._state.dualCallerIndex = 1 - this._state.dualCallerIndex;
}
console.log("Active Callers: " + this._state.activeCallers);
let self = this;
await this.vMixCommand("Function=Merge&Input=" + self.selectInput());
console.log("Merge to input " + self.selectInput())
this._state.previousMixInput = 1 - this._state.previousMixInput;
}
selectInput(){
return this._state.pairs[this._state.activePair]["input" + (2 - this._state.previousMixInput)]
}
async setMultiView(layer, layerInput){
for(var i = 0; i < this._state.pairs.length; i++){
if(i == this._state.activePair){
await this.vMixCommand(`Function=SetMultiViewOverlay&Input=${this._state.pairs[i]["input" + (2 - this._state.previousMixInput)]}&Value=${layer},${layerInput}`);
}
else{
await this.vMixCommand(`Function=SetMultiViewOverlay&Input=${this._state.pairs[i]["input1"]}&Value=${layer},${layerInput}`);
await this.vMixCommand(`Function=SetMultiViewOverlay&Input=${this._state.pairs[i]["input2"]}&Value=${layer},${layerInput}`);
}
}
}
async vMixCommand(command){
await this.httpRequest(this._state.vmix.address, this._state.vmix.port, "/api/?" + command).then(function(str){
console.log(str)
})
}
async httpRequest(host, port, path){
return new Promise(function(resolve, reject) {
fetch(`http://${host}:${port}${path}`).then(function(res){
resolve(res.status);
})
})
}
}
module.exports = MergeManager;