-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (42 loc) · 1.13 KB
/
index.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
55
56
//Constants
const express = require("express");
const path = require("path");
const http = require("http");
const root = path.resolve(path.dirname(""));
const room = require(`${root}/lib/socketroom.js`);
const eventloader = require(`${root}/core/socket/eventloader.js`);
//Roots
const publicroot = root + "/public";
const htmlroot = publicroot + "/html";
//App Setup
const app = express();
const server = http.createServer(app);
var io = require('socket.io')(server);
app.use(express.static(publicroot));
app.all("/", function(req, res) {
res.sendFile(htmlroot + "/index.html");
});
//New Room
app.get('/new', function(req, res) {
res.sendFile(htmlroot + "/new.html");
})
//Routing calls
app.get("/call/:path", function(req, res) {
res.sendFile(htmlroot + "/call.html");
});
//404
app.get("/:path", function(req, res) {
res.sendFile(htmlroot + "/404.html");
});
//IO
io.sockets.on("connection", function(socket) {
const events = eventloader.events;
for (var k in events) {
const temp = k;
socket.on(temp, function(...args) {
events[temp].invoke(socket, ...args);
});
}
});
server.listen(3001);
console.log();