-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
39 lines (32 loc) · 858 Bytes
/
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
/*
* Canvas Socket.io - collaborative canvas board
*
* @author Raheel Khan <[email protected]>
* @licence The MIT License (MIT)
*/
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var path = require('path');
app.use('/public', express.static(path.join(__dirname, '/public')));
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html')
});
io.on('connection', function(socket){
console.log('a user connected');
socket.on('disconnect', function(){
console.log('user disconnected');
});
socket.on('drawClick', function(data) {
socket.broadcast.emit('draw', {
x: data.x,
y: data.y,
type: data.type,
user: data.user
});
});
});
http.listen(process.env.PORT || 3000, function(){
console.log('listening...');
});