-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
39 lines (28 loc) · 909 Bytes
/
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
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var path = require('path');
var ejs = require('ejs');
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.engine('.html', ejs.__express);
app.set('view engine', 'html');
app.use(express.static(path.join(__dirname, 'public')));
server.listen(8080);
app.get('/', function (req, res, next) {
res.render('index');
});
io.on('connection', function (socket) {
console.log('Server conneced!');
socket.emit('init', {userid: Math.random() * 1000});
socket.on('draw', function (data) {
socket.broadcast.emit('draw', data);
});
socket.on('config', function (data) {
socket.broadcast.emit('config', data);
});
socket.on('clear', function () {
socket.broadcast.emit('clear');
});
});