-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
41 lines (31 loc) · 1.27 KB
/
server.ts
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
import * as express from "express";
import * as path from "path";
import * as WebSocket from "ws";
import { Clip } from "./core/classes/Clip";
import { CompilationController } from "./core/classes/CompilationController";
import { IAutomaticCompilationConfig, ICompilationConfig, IManualCompilationConfig, NetworkMessage } from "./core/types";
const PORT = 8080;
const WSPORT = 8081;
const app = express();
const wss = new WebSocket.Server({ port: WSPORT });
app.use(express.static(path.join(__dirname, "/gui/dist")));
app.listen(PORT);
console.log("Website started at http://localhost:" + PORT);
/**
* TODO: Pas d'edit phase sans selected clips
*/
wss.on("connection", (ws: WebSocket) => {
ws.on("message", async (message: string) => {
const obj : NetworkMessage = JSON.parse(message) ;
console.log(obj.header);
if (obj.header === "clipSearch") {
const config = obj.data as IAutomaticCompilationConfig;
const clipsData = await Clip.queryClipsData(config);
ws.send(JSON.stringify({ header: "clipSearchResult", data: clipsData }));
} else if (obj.header === "render") {
const config = obj.data as IManualCompilationConfig;
const compilationController = new CompilationController(config);
compilationController.run();
}
});
});