forked from devansvd/whiteboard-socketio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (44 loc) · 1.36 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
57
58
const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const port = process.env.PORT || 3001;
app.use(express.static(__dirname + '/public'));
//heroku features:enable http-session-affinity
//to work with socket io
function onConnection(socket){
socket.on('drawing', function(data){
socket.broadcast.emit('drawing', data);
console.log(data);
});
socket.on('rectangle', function(data){
socket.broadcast.emit('rectangle', data);
console.log(data);
});
socket.on('linedraw', function(data){
socket.broadcast.emit('linedraw', data);
console.log(data);
});
socket.on('circledraw', function(data){
socket.broadcast.emit('circledraw', data);
console.log(data);
});
socket.on('ellipsedraw', function(data){
socket.broadcast.emit('ellipsedraw', data);
console.log(data);
});
socket.on('textdraw', function(data){
socket.broadcast.emit('textdraw', data);
console.log(data);
});
socket.on('copyCanvas', function(data){
socket.broadcast.emit('copyCanvas', data);
console.log(data);
});
socket.on('Clearboard', function(data){
socket.broadcast.emit('Clearboard', data);
console.log(data);
});
}
io.on('connection', onConnection);
http.listen(port, () => console.log('listening on port ' + port));