This repository has been archived by the owner on Nov 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
81 lines (67 loc) · 1.93 KB
/
app.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
var passwd = "WeLoveNTUOSC!"
var speakerpage;
var port = 5000;
var express = require("express");
var app = express();
var server = require("http").createServer(app);
var io = require("socket.io")(server);
var cheerio = require('cheerio');
var fs = require('fs');
server.listen(port);
app.set("view engine", "ejs");
app.get('/:slide_title/:slide_name',function(req, res){
console.log(__dirname);
var slide_title = req.params.slide_title;
var slide_name = req.params.slide_name;
console.log("Slide Folder Name: " + slide_title);
console.log("Slide File Name: " + slide_name);
var path = __dirname + "/slides/" + slide_title + "/" + slide_name;
fs.readFile(path, function(err, data){
var $ = cheerio.load(data);
var slide_head = $('head').html();
var slide_body = $('body').html();
do_render(res, slide_head, slide_body);
});
});
app.use(express.static(__dirname + "/slides"));
function do_render(res, slide_head, slide_body) {
res.render(__dirname + "/template/st-view", {
slide_head : slide_head,
slide_body : slide_body,
});
}
io.on('connection', function(socket){
/* Speaker Events */
socket.on('passwd',function(data){
if (passwd != data) {
socket.emit('is_speaker', false);
} else {
socket.emit('is_speaker', true);
socket.emit('is_audience', false);
socket.broadcast.emit('is_audience', true);
}
});
socket.on('pagechange', function(data) {
if (passwd != data.passwd) {
return;
} else {
speakerpage = data.state;
socket.broadcast.emit('pagechange', data.state);
}
});
socket.on('getspeakerpage', function(data){
if (passwd == data) {
return;
} else {
socket.emit('getspeakerpage', speakerpage);
}
});
socket.on('mousemove', function(data) {
if (passwd != data.passwd) {
return;
} else {
socket.broadcast.emit('mousemove', data.mousePos);
}
});
socket.on('disconnect', function(){});
});