-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
73 lines (63 loc) · 1.57 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
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
const express = require('express');
const bodyParser = require('body-parser');
const voicemeeter = require('voicemeeter-remote');
const app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
const port = process.env.PORT || 8080;
app.post('/strips/:id', function (req, res) {
try {
for (key in req.body) {
const capitalizedName = key.charAt(0).toUpperCase() + key.slice(1);
if (typeof (voicemeeter[`setStrip${capitalizedName}`]) === "function") {
voicemeeter[`setStrip${capitalizedName}`](req.params.id, req.body[key]);
} else {
throw 'Parameter name not found';
}
}
res.json({
error: false,
});
} catch (e) {
res.json({
error: true,
message: e
});
}
});
app.post('/buses/:id', function (req, res) {
try {
for (key in req.body) {
const capitalizedName = key.charAt(0).toUpperCase() + key.slice(1);
if (typeof (voicemeeter[`setBus${capitalizedName}`]) === "function") {
voicemeeter[`setBus${capitalizedName}`](req.params.id, req.body[key]);
} else {
throw 'Parameter name not found';
}
}
res.json({
error: false,
});
} catch (e) {
res.json({
error: true,
message: e
});
}
});
app.use(function (req, res, next) {
res.status(404).send("Sorry can't find that!")
})
app.use(function (err, req, res, next) {
res.status(500).send("Sorry can't do that!")
})
try {
voicemeeter.init().then(()=>{
voicemeeter.login();
app.listen(port);
})
} catch (e) {
console.error(e);
}