Skip to content

Commit

Permalink
more progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Windal committed Mar 15, 2013
1 parent 9306a98 commit 7ecd210
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 33 deletions.
10 changes: 10 additions & 0 deletions public/js/DrawCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ app.directive('drawingBoard', function() {
scope.stage.canvas.height = element.height();
}

scope.$on('remoteDraw', function(evt, msg) {
//scope.canvas.graphics.clear().setStrokeStyle(stroke, 'round', 'round')
// .beginStroke(scope.penColor)
// .moveTo(scope.end.x, scope.end.y)
//.curveTo(scope.end.x, scope.end.y, oldMidPts[user].x, oldMidPts[user].y)
;
//scope.stage.update();
});


var canvas = angular.element(element)[0];

$(window).resize(function() {
Expand Down
80 changes: 47 additions & 33 deletions public/js/JScribbleService.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ app.factory('JScribbleService', function($rootScope) {
this.socket = io.connect('http://' + host);
this.socket.userData = this;
this.socket.on('chat', this.chatCallback);
this.socket.on('draw', this.drawCallback);
this.socket.emit('join', $.toJSON({ userName: this.userName, userId: this.userId, avatar: this.avatar }));
}
this.userName = userName;
Expand Down Expand Up @@ -99,43 +100,56 @@ app.factory('JScribbleService', function($rootScope) {
this.avatar = av;
},

chatCallback: function (msg, d) {
var message = $.evalJSON(msg);
chatCallback: function (msg) {
var message = $.evalJSON(msg);

var action = message.action;
switch (action) {
case 'message':
this.userData.messages.push(message);
$rootScope.$apply();
break;
case 'control':
if(message.messages && message.messages.length > 0) {
this.userData.messages = message.messages;
$rootScope.$apply();
}
break;
}
},
var action = message.action;
switch (action) {
case 'message':
this.userData.messages.push(message);
$rootScope.$apply();
break;

case 'control':
if(message.messages && message.messages.length > 0) {
this.userData.messages = message.messages;
$rootScope.$apply();
}
break;
}
},

addDrawSegment: function(start, end, color, stroke) {
this.socket.emit('draw', $.toJSON({ action: 'draw',
userId: this.userId,
start: start,
end: end,
color: color,
stroke: stroke }));
},
drawCallback: function(msg) {
var message = $.evalJSON(msg);

sendStartDraw: function(start, color, stroke) {
this.socket.emit("");
this.socket.emit('draw', $.toJSON({ action: 'start',
userId: this.userId,
start: start,
end: start,
color: color,
storke: stroke }));
if (message.userId == this.userId) {
// ignore our own messages being retransmitted back to us...
return;
}

// send a notification message...
$rootScope.$broadcast('remoteDraw', message);

},

addDrawSegment: function(start, end, color, stroke) {
this.socket.emit('draw', $.toJSON({ action: 'draw',
userId: this.userId,
start: start,
end: end,
color: color,
stroke: stroke }));
},

sendStartDraw: function(start, color, stroke) {
this.socket.emit("");
this.socket.emit('draw', $.toJSON({ action: 'start',
userId: this.userId,
start: start,
end: start,
color: color,
storke: stroke }));
}

}
});

0 comments on commit 7ecd210

Please sign in to comment.