Skip to content
Browse files

Added tracker

  • Loading branch information...
1 parent 0eda54d commit ebc464976630f611c92d194b61e6b4667110a0b3 @gsiddardha gsiddardha committed Sep 18, 2011
Showing with 18 additions and 6 deletions.
  1. +4 −1 app.js
  2. +14 −5 public/javascripts/collab.js
View
5 app.js
@@ -97,7 +97,10 @@ io.sockets.on('connection', function(socket){
}
docVersion += 1;
history.push(tmp);
- io.sockets.emit('edit', data);
+
+ socket.get('nickname', function(err, nickname) {
+ io.sockets.emit('edit', {d:data, n:nickname});
+ });
});
});
View
19 public/javascripts/collab.js
@@ -62,17 +62,25 @@ key_handler = function (event) {
}
}
+
socket.on('edit', function (data){
var text = acee.getSession().getValue();
- if(data.edit == '\b') {
- text = text.substr(0,data.cursor-1) + text.substr(data.cursor);
+ var currentCursor = getCursor();
+ if(data.d.edit == '\b') {
+ text = text.substr(0,data.d.cursor-1) + text.substr(data.d.cursor);
} else {
- text = text.substr(0,data.cursor) + data.edit + text.substr(data.cursor);
+ text = text.substr(0,data.d.cursor) + data.d.edit + text.substr(data.d.cursor);
}
+
docVersion += 1;
acee.getSession().setValue(text);
- setCursor(data.cursor);
-});
+
+ if(data.n == socket.nickname){
+ setCursor(data.d.cursor);
+ } else {
+ setCursor(currentCursor);
+ }
+ });
socket.on('version', function(data){
version = data.version;
@@ -82,6 +90,7 @@ socket.on('version', function(data){
socket.on('nickname?', function(data){
var nickname = prompt('Your nickname?');
socket.emit('nickname', nickname);
+ socket.set('nickname', nickname);
socket.on('members', function(data){
members = data;
updateMembers();

0 comments on commit ebc4649

Please sign in to comment.
Something went wrong with that request. Please try again.