Skip to content

Commit 36b1553

Browse files
committed
Sending history as one array
1 parent abc2155 commit 36b1553

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

public/draw.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ $(function(){
5555
socket.on('chatmessage', function (data) {
5656
alertify.log(data.user + ": " + data.message);
5757
});
58+
59+
socket.on('drawActionHistory', function(history){
60+
var i = 0, oc = {};
61+
console.log("History length is " + history.length);
62+
for(i = 0; i < history.length; i += 1){
63+
if(history[i].drawing && oc[history[i].id]){
64+
drawLine(oc[history[i].id].x, oc[history[i].id].y, history[i].x, history[i].y, history[i].color)
65+
}
66+
oc[history[i].id] = history[i]; //update state.
67+
}
68+
69+
});
5870

5971
var prev = {};
6072

@@ -150,8 +162,8 @@ $(function(){
150162

151163
var paper = document.getElementById('paper');
152164
var hammertime = Hammer(paper).on("tap", function(e){
153-
console.log("tap");
154-
console.log(e);
165+
//console.log("tap");
166+
//console.log(e);
155167
});
156168

157169
Hammer(document).on("drag", function(e) {
@@ -161,7 +173,7 @@ $(function(){
161173
});
162174
Hammer(document).on('dragstart', function(e){
163175
e.preventDefault();
164-
console.log("dragstart");
176+
//console.log("dragstart");
165177
});
166178

167179
function preventBehavior(e){

server.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ app.get('/', function(req, res){
2424
io.set("log level", 1);
2525

2626
io.sockets.on('connection', function(socket){
27-
var i;
28-
29-
for(i = 0; i < drawActionStack.length; i += 1){
30-
socket.emit('moving', drawActionStack[i]);
31-
}
27+
/* Send new connection the drawing history as one large array. */
28+
socket.emit('drawActionHistory', drawActionStack);
3229

3330
socket.on('mousemove', function(data){
3431
//if they drew something add it to the action stack.

0 commit comments

Comments
 (0)