-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (35 loc) · 1.24 KB
/
app.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
var express = require('express');
var app = express();
var path = require('path');
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = 8080;
app.use(express.static(__dirname + '/view'));
app.use(express.static(__dirname + '/script'));
app.get('/', function(req, res){
res.sendFile(index.html);
});
io.on('connection', function(socket){
socket.on('newUser', function(room){
socket.room = room;
var roomUsed = false;
socket.join(room);
console.log("New Connection, room: " + room);
});
socket.on("draw",function(drawInfo,lineWidth,color,room){
socket.broadcast.to(room).emit("drawDrawing",drawInfo,lineWidth,color);
});
socket.on("erase",function(drawInfo,lineWidth,room){
socket.broadcast.to(room).emit("eraseDrawing",drawInfo,lineWidth);
});
socket.on("clearCanvas",function(room){
socket.broadcast.to(room).emit("clearCanvasDrawing");
});
socket.on('disconnect', function(){
socket.leave(socket.room);
console.log("Disconect from, room: " + socket.room);
});
});
http.listen(port, "0.0.0.0", function(){
console.log('listening on *:' + port);
});