-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrouting.js
More file actions
executable file
·83 lines (74 loc) · 2.53 KB
/
Copy pathrouting.js
File metadata and controls
executable file
·83 lines (74 loc) · 2.53 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
const express = require('express');
const path = require('path');
const {getSessionStatus} = require('./api');
const WHITELISTED_DOMAINS = require('./config').whitelistedDomains;
const bodyParser = require('body-parser');
const cors = require('cors');
const {obsStopStreaming} = require('./obs');
module.exports = (app, io, memStore, youtubeClient, obs) => {
const corsOptions = {
credentials: true,
origin: (origin, cb) => {
if (WHITELISTED_DOMAINS.indexOf(origin) !== -1 || !origin) {
cb(null, true);
} else {
cb(new Error('Not allowed by CORS'));
}
}
}
app.use(cors(corsOptions));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use('/webcam_ui', express.static(__dirname + '/webcam_ui_build'));
app.get('/', async (req, res) => {
console.log(memStore);
if (memStore.sessionId || memStore.socketId) {
res.end('Webcam is busy');
} else {
if (req.query) {
const json = await getSessionStatus(req.query.sessionId, 'open');
if (json.data.status) {
memStore.sessionId = req.query.sessionId;
res.sendFile(path.join(__dirname, 'webcam_ui_build', 'index.html'));
} else {
res.end('Did not find webcam session. Please log in');
}
}
}
});
app.use('/authorize', express.static(__dirname + '/auth_app_build'));
app.post('/api/end_session', async (req, res) => {
const {sessionId} = req.body;
if(memStore.sessionId === sessionId) {
const json = await getSessionStatus(sessionId, 'close');
if (json.data.status) {
memStore.sessionId = null;
await youtubeClient.liveBroadcasts.delete({id: memStore.liveBroadcastId});
memStore.liveBroadcastId = null;
await obsStopStreaming(obs);
io.of('webcam').emit('endSession');
res.write(JSON.stringify({status: 'webcam session ended'}));
res.end();
} else {
res.write(JSON.stringify({status: 'webcam session does not match'}));
res.end();
}
} else {
res.write(JSON.stringify({status: 'webcam session does not match'}));
res.end();
}
});
app.get('/get_status', (req, res) => {
const {
authorized,
OBSWebSocketConnected,
OBSWebSocketAuthenticated
} = memStore;
res.write(JSON.stringify({
authorized,
obsReady: OBSWebSocketConnected,
obsAuthReady: OBSWebSocketAuthenticated
}));
res.end();
})
}