-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
60 lines (48 loc) · 1.4 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
const express = require('express');
const path = require('path');
const BodyParser = require("body-parser")
const Config = require("getconfig");
const jwt = require("jsonwebtoken");
const app = express();
app.use(BodyParser.json());
app.get("/__healthcheck", async (_req, res) => {
res.status(200).end();
});
app.get('/recording-complete', (req, res) => {
console.log('Finished recording client');
res.statusCode = 200;
res.send('<html><body bgcolor=black></body></html>');
});
// Serve the static files from the React app
app.use(express.static(path.join(__dirname, 'client/dist')));
const validateRecordingData = function (recordingToken, account_id) {
let decoded;
try {
decoded = jwt.verify(recordingToken, secret);
// Create user data for recording client
const userDataToken = jwt.sign(
{
id: "recording-bot-client",
isAHiddenBot: true
}, Config.apiSecret
);
return {
roomName: decoded.room,
roomId: decoded.sub,
userDataToken
};
}
catch (err) {
console.error(`Failed token validation ${err}`);
return {
error: err
};
}
}
app.post("/verify-recording", async (req, res) => {
const recordingData = validateRecordingData(req.body.recording_token, req.body.org_key)
return res.send(recordingData);
});
const port = process.env.PORT || 5000;
app.listen(port);
console.log('App is listening on port ' + port);