-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
38 lines (33 loc) · 1.16 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
var ansiedit = require("./src/ansiedit");
var HttpsServer = require('https').createServer;
var fs = require("fs");
server = HttpsServer({
cert: fs.readFileSync("/etc/ssl/private/letsencrypt-domain.pem"),
key: fs.readFileSync("/etc/ssl/private/letsencrypt-domain.key")
})
server.listen(process.argv[2] || 1337);
var express = require("express");
var app = express();
var session = require("express-session");
var express_ws = require("express-ws")(app, server);
var wss = express_ws.getWss("/");
app.use(express.static("public"));
app.use(session({"resave": false, "saveUninitialized": true, "secret": "sauce"}));
app.ws("/", (ws, req) => {
ws.send(ansiedit.getStart(req.sessionID));
ws.send(ansiedit.getImageData().data, {"binary": true});
ws.on("message", (msg) => {
ansiedit.message(JSON.parse(msg), req.sessionID, wss.clients);
});
ws.on("close", () => {
ansiedit.closeSession(req.sessionID, wss.clients);
});
});
setInterval(() => {
ansiedit.saveSessionWithTimestamp(() => {});
ansiedit.saveSession(() => {});
}, 14400000);
process.on("SIGINT", () => {
console.log("\n");
ansiedit.saveSession(process.exit);
});