From 34eae594710698e650ca22ad836618c6a9a02dcc Mon Sep 17 00:00:00 2001 From: Andre Goncalves Date: Fri, 4 Dec 2009 18:05:08 +0000 Subject: [PATCH] more changes --- assets/javascripts/cymain.js | 107 ++++++++++++++++++++--------------- assets/javascripts/demo2.js | 12 +++- 2 files changed, 69 insertions(+), 50 deletions(-) diff --git a/assets/javascripts/cymain.js b/assets/javascripts/cymain.js index 9cd3763..bc98b6d 100644 --- a/assets/javascripts/cymain.js +++ b/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); } \ No newline at end of file diff --git a/assets/javascripts/demo2.js b/assets/javascripts/demo2.js index dd58ab6..8140824 100644 --- a/assets/javascripts/demo2.js +++ b/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}); @@ -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'); @@ -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");