-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (28 loc) · 929 Bytes
/
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
//Mini server to keep the slide show (and notes) in sync across browsers
//(Designed to be used on localhost only)
let http = require("http")
let ws = require("nodejs-websocket")
let express = require("express")
let path = require("path")
let process = require("process")
let app = express();
let server = http.Server(app);
const port = process.env.PORT || 8083;
app.use(express.static(path.resolve('content'))); //TODO: maybe it shouldn't serve .md files (then again, it won't matter locally)
let wserver = ws.createServer(function (connection) {
connection.on("text", function (str) {
console.log("Next slide: " + str);
broadcast(str);
})
})
process.on('uncaughtException', function(err) {
console.log("Oh, lookie, an error: ");
console.log(err);
})
function broadcast(str) {
wserver.connections.forEach(function (connection) {
connection.sendText(str);
})
}
wserver.listen(port);
server.listen(port + 1);