-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
26 lines (22 loc) · 688 Bytes
/
server.js
File metadata and controls
26 lines (22 loc) · 688 Bytes
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
var express = require('express'),
app = express(),
http = require('http'),
socketIo = require('socket.io');
var server = http.createServer(app);
var io = socketIo.listen(server);
server.listen(8080);
console.log("Server running on 127.0.0.1:8080");
var line_history = [];
app.use(express.static(__dirname + '/public'));
io.on('connection', function (socket) {
for (var i in line_history) {
socket.emit('draw_line', { line: line_history[i] } );
}
socket.on('draw_line', function (data) {
line_history.push(data.line);
io.emit('draw_line', { line: data.line });
});
socket.on('disconnect', function(){
line_history = [];
});
});