-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (56 loc) · 1.34 KB
/
index.js
File metadata and controls
65 lines (56 loc) · 1.34 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
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
const fs = require("fs");
const httpServer = require("https").createServer({
key: fs.readFileSync("./server.key"),
cert: fs.readFileSync("./server.crt"),
ca: fs.readFileSync("./root.crt"),
requestCert: true,
});
const io = require("socket.io")(httpServer, {
connectTimeout: 20000,
pingTimeout: 20000,
pingInterval: 10000,
});
const state = {
lock: 0,
shutdown: 0,
};
const shutdownTimer = 1800;
const lockTimer = 300;
io.on("connection", (socket) => {
socket.emit("config", {
shutdownAfter: shutdownTimer,
lockAfter: lockTimer,
state,
});
socket.on("getWallpaper", () => {
socket.emit("wallpaper", {
wallpaper: fs.readFileSync("./wallpaper.png"),
});
});
socket.on("getWallpaperOffline", () => {
socket.emit("wallpaper_offline", {
wallpaper: fs.readFileSync("./wallpaper-offline.png"),
});
});
socket.on("adminLock", (fn) => {
state.lock = Date.now();
console.log("Locking all machines");
io.emit("config", {
shutdownAfter: shutdownTimer,
lockAfter: lockTimer,
state,
});
fn();
});
socket.on("adminShutdown", (fn) => {
state.shutdown = Date.now();
console.log("Shutting all machines down");
io.emit("config", {
shutdownAfter: shutdownTimer,
lockAfter: lockTimer,
state,
});
fn();
});
});
httpServer.listen(4000);