-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (33 loc) · 1.27 KB
/
index.js
File metadata and controls
37 lines (33 loc) · 1.27 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
const express = require('express');
const app = express();
const http = require("http").createServer(app);
const io = require('socket.io')(http);
const bodyParser = require('body-parser');
const port = 3000;
// kid's never see this, so just putting here for now
const incantation = 'verjaardag';
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', (req, res) => res.sendFile(__dirname + '/index.html'));
app.get('/game', (req, res) => res.sendFile(__dirname + '/game.html'));
app.get('/control', (req, res) => res.sendFile(__dirname + '/control.html'));
app.post('/check', (req, res) => {
if (req.body.incantation.toUpperCase() === incantation.toUpperCase()) {
res.status(200);
res.send('Congratulations!');
} else {
res.status(403);
res.send('Oh no!');
}
});
io.on('connection', (socket) => {
['start', 'loaded', 'playing', 'ended'].forEach(function(element) {
socket.on(`video-${element}`, function(data){
socket.broadcast.emit(`video-${element}`, data);
});
socket.on(`audio-${element}`, function(data){
socket.broadcast.emit(`audio-${element}`, data);
});
});
});
http.listen(port, () => console.log(`Escape room listening on ${port}!`));