-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
95 lines (90 loc) · 3.42 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env nodejs
const axios = require("axios");
const crypto = require("crypto");
const xml2js = require("xml2js");
const express = require("express");
const cors = require("cors");
const dotenv = require("dotenv");
const { request } = require("http");
const app = express();
app.use(express.json());
dotenv.config();
app.all("/recordings", (req, res) => {
var recordings = [];
const servers = process.env.RECORDING_SERVERS.split(" ");
const secrets = process.env.RECORDING_SECRETS.split(" ");
const requests = makeRequests(servers, secrets);
axios
.all(requests)
.then(
axios.spread((...responses) => {
for (var j = 0; j < responses.length; j++) {
const parser = xml2js.parseString;
parser(responses[j].data, (err, result) => {
const parsedXML = result.response.recordings[0].recording;
var jsonConverted = JSON.parse(JSON.stringify(parsedXML));
for (var i = 0; i < jsonConverted.length; i++) {
var toPush = {
startTime: jsonConverted[i].startTime.toString(),
recordID: jsonConverted[i].recordID.toString(),
meetingID: jsonConverted[i].meetingID.toString(),
playback: jsonConverted[i].playback[0].format[0].url.toString(),
};
recordings.push(toPush);
}
});
}
console.log(recordings.length);
res.send(recordings);
})
)
.catch((errors) => {
res.status(400).send(errors.message);
});
});
app.all("/recordings/delete", (req, res) => {
const servers = process.env.RECORDING_SERVERS.split(" ");
const secrets = process.env.RECORDING_SECRETS.split(" ");
const playback = req.body.playback;
const recordID = req.body.recordID;
var request = null;
servers.forEach((server, index) => {
if (playback.includes(server)) {
const call = "deleteRecordings";
const params = "recordID=" + recordID;
const mix = call + params + secrets[index];
var shasum = crypto.createHash("sha1");
shasum.update(mix);
const checksum = shasum.digest("hex");
const url =
server + "/bigbluebutton/api/" + call + "?" + params + "&checksum=" + checksum;
request = axios.get(url);
}
});
request
.then((response) => {
res.status(200).send("success");
})
.catch((errors) => {
res.status(400).send("error");
});
});
function makeRequests(servers, secrets) {
var requests = [];
servers.forEach((server, index) => {
const secret = secrets[index];
const call = "getRecordings";
const mix = call + secret;
var shasum = crypto.createHash("sha1");
shasum.update(mix);
const checksum = shasum.digest("hex");
const url = server + "/bigbluebutton/api/" + call + "?checksum=" + checksum;
const request = axios.get(url);
requests.push(request);
});
return requests;
}
app.use(cors());
app.listen(process.env.SERVER_PORT, () => {
console.log("Server Started On http://localhost:" + process.env.SERVER_PORT);
});