Skip to content

Commit

Permalink
more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andregoncalves committed Dec 4, 2009
1 parent f74fb80 commit 34eae59
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 50 deletions.
107 changes: 60 additions & 47 deletions assets/javascripts/cymain.js
@@ -1,55 +1,68 @@
var Cyclops = {
var Cyclops = function(type) {
this.eventStorage = [];

init_as: function(type) {
this.eventStorage = {};

if (type == "master")
{
pubsub.subscribe('/record/start', this, "startRecording");
pubsub.subscribe('/record/stop', this, "stopRecording");
}
else
{
pubsub.subscribe('/listen/start', this, 'startListening');
}
},
if (type == "master")
{
pubsub.subscribe('/record/start', this, "startRecording");
pubsub.subscribe('/record/stop', this, "stopRecording");
}
else
{
//pubsub.subscribe('/listen/start', this, 'startListening');
pubsub.subscribe('/listen/new', this, 'startListeningFromStorage');
//pubsub.subscribe('/listen/stop', this, 'stopListening');
}
}

startListening: function() {
$.get("/activity?id=final", {}, function(ev) {
ev = JSON.parse(ev);
this['playEvent_'+ev.type](ev.data);
this.startListening();
});
},
Cyclops.prototype.startListening = function() {
$.get("/activity?id=final", {}, function(ev) {
ev = JSON.parse(ev);
this['playEvent_'+ev.type](ev.data);
this.startListening();
});
}

startRecording: function(e) {
$(document).bind('mousemove', this.storeEvent);
},

Cyclops.prototype.startListeningFromStorage = function() {
events = master.eventStorage.reverse();
el = events.pop();

stopRecording: function(e) {
$(document).unbind('mousemove', this.storeEvent);
},
if (el)
{
console.info(el.type);
slave["playEvent_"+el.type](el);
}
}

storeEvent: function(e) {
this.eventStorage.push(e);
this.sendEvent(e);
},

sendEvent: function(e) {
ev = this['getEvent_'+e.type](e);

$.post('/publish?id=final', ev.serialize(), function(data, textStatus) {
if (textStatus != "success")
console.info("failed posting! " + stextStatus);
});
},
Cyclops.prototype.startRecording = function() {
$(document).bind('mousemove', this.storeEvent);
// TODO: add more events
}

getEvent_mousemove: function(e) {
event = new CyEvent("mousemove", { x:e.pageX, y:e.pageY });
return event;
},
Cyclops.prototype.stopRecording = function() {
$(document).unbind('mousemove', this.storeEvent);
}

Cyclops.prototype.storeEvent = function(e) {
master.eventStorage.push(e);
pubsub.publish('/listen/new', e, 'new event');
}

Cyclops.prototype.sendEvent = function(e) {
ev = this['getEvent_'+e.type](e);

playEvent_mousemove: function(e) {
$("#mouse").css('top', e.x).css('left', e.y);
}
$.post('/publish?id=final', ev.serialize(), function(data, textStatus) {
if (textStatus != "success")
console.info("failed posting! " + stextStatus);
});
}

Cyclops.prototype.getEvent_mousemove = function(e) {
event = new CyEvent("mousemove", { x:e.pageX, y:e.pageY });
return event;
}

Cyclops.prototype.playEvent_mousemove = function(e) {
// TODO: move to dispatch event
$("#mouse").css('top', e.pageY).css('left', e.pageX);
}
12 changes: 9 additions & 3 deletions assets/javascripts/demo2.js
@@ -1,10 +1,11 @@


$(document).ready(function() {
window.pubsub = new PubSub('/record/start', '/record/stop', '/listen/start', '/listen/stop');
window.pubsub = new PubSub('/record/start', '/record/stop', '/listen/start', '/listen/stop', '/listen/new', '/listen/stop');
CyNotify.subscribe('/record/start');
CyNotify.subscribe('/record/stop');
CyNotify.subscribe('/listen/start');
CyNotify.subscribe('/listen/start');
//CyNotify.subscribe('/listen/stop');


/*e = new CyEvent("mousemove", { x:10, y:20});
Expand All @@ -16,7 +17,8 @@ $(document).ready(function() {
});

$(window).load(function() {
Cyclops.init_as('slave');
master = new Cyclops('master');
slave = new Cyclops('save');

$(document).bind('keydown', 'Ctrl+r', function(e) {
pubsub.publish('/record/start', e, 'recording started');
Expand All @@ -30,6 +32,10 @@ $(window).load(function() {
pubsub.publish('/listen/start', e, 'listen started');
});

$(document).bind('keydown', 'Ctrl+k', function(e) {
pubsub.publish('/listen/stop', e, 'listen stopped');
});

/* $('img').click(function(e) {
console.info(e);
console.info("click on image");
Expand Down

0 comments on commit 34eae59

Please sign in to comment.