-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
40 lines (37 loc) · 1023 Bytes
/
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
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
server.listen(80);
app.get('/', function (req, res) {
res.sendFile(__dirname + '/public/login.html');
});
app.use(express.static(__dirname + '/public'));
app.get('/join',function(req, res){
var id = req.query.id;
res.redirect("/index.html?id="+id);
});
var line_history = [];
io.on('connection', function (socket) {
line_history.forEach(function(coord){
socket.emit('refresh',coord );
});
socket.on('update',function(data){
line_history.push(data);
socket.broadcast.emit('refresh',data);
});
socket.on('clear',function(data){
var aux = [];
line_history.forEach(function(a){
if(a.id != data) aux.push(a);
});
line_history = aux;
socket.broadcast.emit('clear',data);
});
});
function create_sala(req){
var id = Math.floor((Math.random() * 999) + 1);
if(salas.includes(id)) create_sala();
else{
}
}