-
Notifications
You must be signed in to change notification settings - Fork 38
/
server.js
69 lines (60 loc) · 1.76 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
require('dotenv').config()
const express = require('express');
const path = require('path');
const GoogleMeet = require('./google-meet');
const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// Values
let email = process.env.EMAIL;
let password = process.env.PASSWORD;
let head = false;
let strict = false;
meetObj = new GoogleMeet(email, password, head, strict);
// cache store
// can be moved to db
let url = {};
let ind = 0;
app.get('/', (req, res) => {
res.render('index', { url, email, password })
});
app.post('/postlink', (req, res) => {
ind++;
url[ind] = {};
url[ind].id = ind;
url[ind].url = req.body.url;
url[ind].startTime = Date.parse(req.body.startDate);
url[ind].endTime = Date.parse(req.body.endDate);
res.redirect("/");
});
const listener = app.listen(3000 || process.env.PORT, () => {
setInterval(() => {
// when no scheduled links
if (Object.keys(url).length === 0) {
if (meetObj.getBrowserIsActive())
meetObj.closeBrowser();
else
return;
}
// check meet array every 10sec
for (x in url) {
// join period
if (url[x].startTime < Date.now() && url[x].endTime > Date.now()) {
console.log(`Request for joining meet ${url[x].url}`);
meetObj.schedule(url[x].url, url[x].id);
// hack: set above endTime so that it will not come for
// same meetId in this block
url[x].startTime = url[x].endTime + 2000;
}
// leave period
if (url[x].endTime < Date.now()) {
console.log(`Request for leaving meet ${url[x].url}`);
meetObj.closeTab(url[x].id);
delete url[x];
}
}
}, 10000)
console.log(`App listening on port ${listener.address().port}`)
})