-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
59 lines (50 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
55
56
57
58
59
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
app.use(bodyParser.json());
var games = new Map();
var links = [...games.keys()];
games.set('/a', []);
app.post('/add', (req, res) => {
let link = req.body.link;
games.set(`/${link}`, []);
res.send(link);
});
app.post('/remove', (req, res) => {
let link = `/${req.body.link}`;
games.delete(link);
res.send(link);
})
app.get(links, (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.post('/update', (req, res) => {
let link = `/${req.body.link}`;
if(games.get(link).length == 0){
res.send('Empty');
}else{
res.send(games.get(link));
}
});
io.sockets.on('connection', (socket) => {
socket.on('mouse', (data) => {
let link = data.link.split('https://')[1].split('/')[1];
if(games.has(`/${link}`)){
let game = games.get(`/${link}`);
game.push({
x: data.x,
y: data.y,
px: data.px,
py: data.py,
strokeweight: data.strokeweight,
color: data.color
});
}
});
});
setInterval(()=>{
links = [...games.keys()];
}, 10);
server.listen(3000);