-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
143 lines (124 loc) · 5.13 KB
/
server.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
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
const { Voicemeeter, StripProperties, BusProperties} = require('voicemeeter-connector');
var voicemeeter = Voicemeeter.init();
var stripNumber = 0;
var busNumber = 0;
var ready = false;
var config = require('./app/config.json');
const IP = 'localhost';
const PORT = config.port;
const path = require('path');
const qrcode = require('qrcode-terminal');
const express = require("express")
const app = express();
app.use(express.static('./app/'));
const http = require('http').Server(app);
const io = require('socket.io')(http, {cors: {origin: "*"}});
http.listen(PORT, () => {
console.log(`Connect to the web interface at http://${IP}:${PORT} or scan the QR code below`);
qrcode.generate(`http://${IP}:${PORT}`, {
small: true
});
voicemeeter.then(async (voicemeeterinstance) => {
voicemeeterinstance.connect();
console.log('voicemeeter connected');
voicemeeter = voicemeeterinstance;
});
});
io.on('connection', (socket) => {
function updateData() {
let strips = [];
let buses = [];
for (let i = 0; i < stripNumber; i++) {
let strip = {};
for (const property in StripProperties) {
strip[property] = voicemeeter.getStripParameter(i, StripProperties[property]);
}
strip["Index"] = i;
strip["Type"] = voicemeeter.type == "voicemeeterPotato" ? 2 : (voicemeeter.type == "voicemeeterBanana" ? 1 : 0);
strips.push(strip);
}
for (let i = 0; i < busNumber; i++) {
let bus = {};
for (const property in BusProperties) {
bus[property] = voicemeeter.getBusParameter(i, BusProperties[property]);
}
bus["Index"] = i;
bus["Type"] = voicemeeter.type == "voicemeeterPotato" ? 2 : (voicemeeter.type == "voicemeeterBanana" ? 1 : 0);
buses.push(bus);
}
return {"strips": strips, "buses": buses };
}
socket.on('ready', () => {
console.log('Connected');
voicemeeter.updateDeviceList();
let data = {
type: voicemeeter.type,
version: voicemeeter.version,
inputDevices: voicemeeter.inputDevices,
outputDevices: voicemeeter.outputDevices
};
stripNumber = (voicemeeter.type == 'voicemeeter') ? 3 : ((voicemeeter.type == 'voicemeeterBanana') ? 5 : 7);
busNumber = (voicemeeter.type == 'voicemeeter') ? 3 : ((voicemeeter.type == 'voicemeeterBanana') ? 5 : 7);
socket.emit('info', JSON.stringify(data));
socket.emit('newdata', JSON.stringify(updateData()));
ready = true;
});
socket.on('setStrip', (data) => {
data = JSON.parse(data);
ready = false;
let promises = [];
const id = data["Index"];
promises.push(voicemeeter.setStripParameter(id, StripProperties.Gain, data["Gain"]));
promises.push(voicemeeter.setStripParameter(id, StripProperties.Mute, +data["Mute"]));
promises.push(voicemeeter.setStripParameter(id, StripProperties.A1, +data["A1"]));
promises.push(voicemeeter.setStripParameter(id, StripProperties.A2, +data["A2"]));
promises.push(voicemeeter.setStripParameter(id, StripProperties.A3, +data["A3"]));
promises.push(voicemeeter.setStripParameter(id, StripProperties.A4, +data["A4"]));
promises.push(voicemeeter.setStripParameter(id, StripProperties.A5, +data["A5"]));
promises.push(voicemeeter.setStripParameter(id, StripProperties.B1, +data["B1"]));
promises.push(voicemeeter.setStripParameter(id, StripProperties.B2, +data["B2"]));
promises.push(voicemeeter.setStripParameter(id, StripProperties.B3, +data["B3"]));
promises.push(voicemeeter.setStripParameter(id, StripProperties.Mono, +data["Mono"]));
promises.push(voicemeeter.setStripParameter(id, StripProperties.Solo, +data["Solo"]));
Promise.all(promises).then(() => {
ready = true;
});
});
socket.on('setBus', (data) => {
data = JSON.parse(data);
ready = false;
let promises = [];
const id = data["Index"];
promises.push(voicemeeter.setBusParameter(id, BusProperties.Gain, data["Gain"]));
promises.push(voicemeeter.setBusParameter(id, BusProperties.Mute, +data["Mute"]));
Promise.all(promises).then(() => {
ready = true;
});
});
voicemeeter.attachChangeEvent(() => {
if(!ready) {
return;
}
socket.emit('newdata', JSON.stringify(updateData()));
});
socket.on('disconnect', () => {
console.log("Disconnected");
});
});
app.get('/version', function (req, res) {
res.send({
type: voicemeeter.type,
version: voicemeeter.version,
ins: voicemeeter.inputDevices,
out: voicemeeter.outputDevices
});
});
app.get('/', function (req, res) {
res.sendFile(path + "index.html");
});
function exitHandler(options, exitCode) {
voicemeeter.disconnect();
}
[`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach((eventType) => {
process.on(eventType, exitHandler.bind(null, eventType));
})