-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
54 lines (44 loc) · 1.34 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
const express = require("express");
const app = express();
const http = require("http").Server(app);
const io = require("socket.io")(http);
const auth = require("./auth");
const hostname = "0.0.0.0";
const port = 8080;
http.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
app.use(auth);
app.get("/", (req, res) => {
res.sendFile(__dirname + "/app.html");
});
app.get("/slides_left", (req, res) => {
res.sendFile(__dirname + "/slides/slides_left.html");
});
app.get("/slides_right", (req, res) => {
res.sendFile(__dirname + "/slides/slides_right.html");
});
app.get("/controller", (req, res) => {
res.sendFile(__dirname + "/controller.html");
});
app.use(express.static("slides"));
app.use((req, res) => {
res.sendStatus(404);
});
io.on("connection", (socket) => {
console.log(`Client ${socket.handshake.headers.host} joined`);
console.log(socket.handshake.headers);
io.emit("clientJoin", { for: "everyone" });
socket.on("disconnect", () => {
console.log(`Client ${socket.handshake.headers.host} left`);
io.emit("clientLeave", { for: "everyone" });
});
socket.on("slideCommand", (msg) => {
console.log("slideCommand", msg);
io.emit("slideCommand", msg);
});
socket.on("slideStatus", (msg) => {
console.log("slideStatus", msg);
io.emit("slideStatus", msg);
});
});