Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f74fb80
commit 34eae59
Showing
2 changed files
with
69 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters