Permalink
Browse files

events mostly working

  • Loading branch information...
1 parent 88b402e commit a62c96089299cd6a1e3027d5af074dea51479a33 @pgte committed Dec 5, 2009
Showing with 171 additions and 37 deletions.
  1. +159 −27 assets/javascripts/cymain.js
  2. +3 −2 assets/javascripts/event.js
  3. +5 −4 assets/javascripts/final.js
  4. +1 −1 demo_final/application.html
  5. +3 −3 nginx/nginx.conf
@@ -16,8 +16,16 @@ var Cyclops = function(type) {
cyclops_get_lastModified = null;
Cyclops.prototype.startListening = function() {
-
- temp_cyclops_get_lastModified = $.ajax({
+
+ $.getJSON("/activity?id="+$.cookie('cyclops_queue_id'), function(ev) {
+ //console.info(ev.when+': Playing event '+ev.type);
+ slave['playEvent_'+ev.type](ev);
+ slave.startListening();
+ });
+
+ /*
+ var temp_cyclops_get_lastModified = null;
+ $.ajax({
beforeSend: function(XMLHttpRequest) {
if(cyclops_get_lastModified != null) {
XMLHttpRequest.setRequestHeader("If-Modified-Since", cyclops_get_lastModified);
@@ -26,21 +34,30 @@ Cyclops.prototype.startListening = function() {
type: "GET",
url: "/activity?id="+$.cookie('cyclops_queue_id'),
dataType: "json",
+ async: true,
success: function(ev){
//console.info('data = '+data);
//ev = JSON.parse(data);
//try {
+ console.info(ev.when+': Playing event '+ev.type);
slave['playEvent_'+ev.type](ev);
//} catch(exception) {
//if (self['console'])
//console.error(exception);
//}
+ },
+ complete: function(XMLHttpRequest) {
+ console.info('LAST MODIFIED IS:'+XMLHttpRequest.getResponseHeader('Last-Modified'));
+ if(temp_cyclops_get_lastModified = XMLHttpRequest.getResponseHeader('Last-Modified')) {
+ cyclops_get_lastModified = temp_cyclops_get_lastModified;
+ }
+ console.info('Last-Modified = '+temp_cyclops_get_lastModified);
slave.startListening();
+
}
- }).getResponseHeader('Last-Modified');
-
- if(temp_cyclops_get_lastModified)
- cyclops_get_lastModified = temp_cyclops_get_lastModified;
+ })
+ console.info('Last-Modified = '+temp_cyclops_get_lastModified);
+*/
}
@@ -59,6 +76,14 @@ Cyclops.prototype.startListeningFromStorage = function() {
Cyclops.prototype.startRecording = function() {
$(document).bind('mousemove', this.sendEvent);
$(document).bind('click', this.sendEvent);
+ $(document).bind('mouseover', this.sendEvent);
+ /*
+ $(document).bind('mouseout', this.sendEvent);
+ $(document).bind('mouseenter', this.sendEvent);
+ $(document).bind('mouseleave', this.sendEvent);
+ $(document).bind('mouseup', this.sendEvent);
+ $(document).bind('mousedown', this.sendEvent);
+*/
// TODO: add more events
}
@@ -72,49 +97,156 @@ Cyclops.prototype.storeEvent = function(e) {
}
Cyclops.prototype.sendEvent = function(e) {
+
- ev = master['getEvent_'+e.type](e);
+ ev = master['getEvent_'+e.type](e);
+ //console.info(ev.when+': sending '+e.type);
- $.post('/publish?id='+$.cookie('cyclops_queue_id'), ev.serialize(), function(data, textStatus) {
- });
+ $.post('/publish?id='+$.cookie('cyclops_queue_id'), ev.serialize(), function(data, textStatus) {
+ });
}
-
Cyclops.prototype.getEvent_mousemove = function(e) {
- event = new CyEvent("mousemove", { x:e.pageX, y:e.pageY });
+ event = new CyEvent("mousemove", { x:e.pageX, y:e.pageY });
+ return event;
+}
+
+Cyclops.prototype.getEvent_mouseover = function(e) {
+ //console.info('getting mouseover:'+e.type);
+ if(e.type == 'mouseover') {
+ event = new CyEvent("mouseover", { x:e.pageX, y:e.pageY });
+ return event;
+ }
+}
+
+Cyclops.prototype.getEvent_mouseout = function(e) {
+ //console.info('getting mouseout:'+e.type);
+ if(e.type == 'mouseout') {
+ event = new CyEvent("mouseout", { x:e.pageX, y:e.pageY });
+ return event;
+ }
+}
+
+Cyclops.prototype.getEvent_mouseenter = function(e) {
+ event = new CyEvent("mouseenter", { x:e.pageX, y:e.pageY });
return event;
}
-Cyclops.prototype.getEvent_click = function(e) {
- event = new CyEvent("click", { x:e.pageX, y:e.pageY });
+Cyclops.prototype.getEvent_mouseleave = function(e) {
+ event = new CyEvent("mouseleave", { x:e.pageX, y:e.pageY });
return event;
}
+Cyclops.prototype.getEvent_mouseup = function(e) {
+ event = new CyEvent("mouseup", { x:e.pageX, y:e.pageY, clicks:e.detail });
+ return event;
+}
+
+Cyclops.prototype.getEvent_mousedown = function(e) {
+ event = new CyEvent("mousedown", { x:e.pageX, y:e.pageY, clicks:e.detail });
+ return event;
+}
+
+
+Cyclops.prototype.getEvent_click = function(e) {
+ event = new CyEvent("click", { x:e.pageX, y:e.pageY });
+ return event;
+}
+
+
+Cyclops.prototype.__find_object_in_location = function(x, y) {
+ $('#mouse').hide();
+ var el = document.elementFromPoint(x, y);
+ $('#mouse').show();
+ //console.info('got el from location:'+el);
+ return el;
+}
+
+Cyclops.prototype.__create_event = function(type, pageX, pageY) {
+ ev = jQuery.Event(type);
+ ev.pageX=parseInt(pageX);
+ ev.clientX=ev.pageX - (document.body.scrollLeft
+ + document.documentElement.scrollLeft) ;
+ ev.pageY=parseInt(pageY);
+ ev.clientY=ev.pageY - (document.body.scrollTop
+ + document.documentElement.scrollTop);
+ return ev;
+}
+
Cyclops.prototype.playEvent_mousemove = function(e) {
+ // TODO: move to dispatch event
+ $("#mouse").css('top', e.data.y).css('left', e.data.x);
+ if(el = slave.__find_object_in_location(e.data.x, e.data.y)) {
+ //el.dispatchEvent(evt);
+ jsEvent = this.__create_event('mousemove', e.data.x, e.data.y);
+ $(el).trigger(jsEvent);
+ }
+}
+
+Cyclops.prototype.playEvent_mouseover = function(e) {
// TODO: move to dispatch event
$("#mouse").css('top', e.data.y).css('left', e.data.x);
var evt = document.createEvent("MouseEvents");
- evt.initMouseEvent("mousemove", true, true, window,
- 0, 0, 0, 0, 0, false, false, false, false, 0, null);
+ el = slave.__find_object_in_location(e.data.x, e.data.y)
+ if(el) {
+ jsEvent = this.__create_event('mouseover', e.data.x, e.data.y);
+ $(el).trigger(jsEvent);
+ }
+}
+
+Cyclops.prototype.playEvent_mouseout = function(e) {
+ // TODO: move to dispatch event
+ $("#mouse").css('top', e.data.y).css('left', e.data.x);
+
+ if(el = slave.__find_object_in_location(e.data.x, e.data.y)) {
+ jsEvent = this.__create_event('mouseout', e.data.x, e.data.y);
+ $(el).trigger(jsEvent);
+ }
+}
+
+
+Cyclops.prototype.playEvent_mouseenter = function(e) {
+ // TODO: move to dispatch event
+ $("#mouse").css('top', e.data.y).css('left', e.data.x);
+
+ if(el = slave.__find_object_in_location(e.data.x, e.data.y)) {
+ jsEvent = this.__create_event('mouseenter', e.data.x, e.data.y);
+ $(el).trigger(jsEvent);
+ }
+}
+
+Cyclops.prototype.playEvent_mouseleave = function(e) {
+ // TODO: move to dispatch event
+ $("#mouse").css('top', e.data.y).css('left', e.data.x);
+
+ if(el = slave.__find_object_in_location(e.data.x, e.data.y)) {
+ jsEvent = this.__create_event('mouseleave', e.data.x, e.data.y);
+ $(el).trigger(jsEvent);
+ }
+}
- if(el = document.elementFromPoint(e.data.x, e.data.y)) {
- el.dispatchEvent(evt);
+Cyclops.prototype.playEvent_mouseup = function(e) {
+ // TODO: move to dispatch event
+ if(el = slave.__find_object_in_location(e.data.x, e.data.y)) {
+ jsEvent = this.__create_event('mouseup', e.data.x, e.data.y);
+ $(el).trigger(jsEvent);
+ }
+}
+
+Cyclops.prototype.playEvent_mousedown = function(e) {
+ // TODO: move to dispatch event
+ if(el = slave.__find_object_in_location(e.data.x, e.data.y)) {
+ jsEvent = this.__create_event('mousedown', e.data.x, e.data.y);
+ $(el).trigger(jsEvent);
}
}
Cyclops.prototype.playEvent_click = function(e) {
// TODO: move to dispatch event
- var evt = document.createEvent("MouseEvents");
- evt.initMouseEvent("click", true, true, window,
- 1, 0, 0, 0, 0, false, false, false, false, 0, null);
- $('#mouse').hide();
- if(el = document.elementFromPoint(e.data.x, e.data.y)) {
- //console.info(el);
- el.dispatchEvent(evt);
- } else {
- //console.error('No element in '+e.data.x + ', '+e.data.y);
+ if(el = slave.__find_object_in_location(e.data.x, e.data.y)) {
+ jsEvent = this.__create_event('click', e.data.x, e.data.y);
+ $(el).trigger(jsEvent);
}
- $('#mouse').show();
}
@@ -1,6 +1,7 @@
function CyEvent(type, data) {
- this.type = type;
- this.data = data;
+ this.type = type;
+ this.data = data;
+ this.when = Math.round(new Date().getTime() / 1000);
}
CyEvent.prototype.serialize = function() {
@@ -12,6 +12,7 @@ $(document).ready(function() {
var x;
var y;
+ /*
canvas.onmousedown = function(e) {
x = e.clientX;
y = e.clientY;
@@ -22,11 +23,13 @@ $(document).ready(function() {
x = null;
y = null;
}
-
+*/
canvas.onmousemove = function(e) {
+ /*
if (x == null || y == null) {
return;
- }
+ }*/
+
x = e.clientX;
y = e.clientY;
x += -canvas.offsetLeft + document.body.scrollLeft
@@ -77,8 +80,6 @@ $(window).load(function() {
});
-
-
/* $('img').click(function(e) {
console.info(e);
@@ -31,6 +31,6 @@ <h2>Paint here:</h2>
<script src="../assets/javascripts/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
<script src="../assets/javascripts/cymain.js" type="text/javascript" charset="utf-8"></script>
<script src="../assets/javascripts/cynotify.js" type="text/javascript" charset="utf-8"></script>
-
+
</body>
</html>
View
@@ -45,10 +45,10 @@ http {
set $push_channel_id $arg_id; #/?id=239aff3 or somesuch
push_publisher;
- push_store_messages on; # enable message queueing
+ push_store_messages off; # enable message queueing
push_message_timeout 2h; # expire buffered messages after 2 hours
push_max_message_buffer_length 100; # store 10 messages
- push_min_message_recipients 0; # minimum recipients before purge
+ push_min_message_recipients 1; # minimum recipients before purge
}
# public long-polling endpoint
@@ -59,7 +59,7 @@ http {
# - last: only the most recent listener request is kept, 409 for others.
# - first: only the oldest listener request is kept, 409 for others.
# - broadcast: any number of listener requests may be long-polling.
- push_subscriber_concurrency broadcast;
+ push_subscriber_concurrency last;
set $push_channel_id $arg_id;
default_type text/plain;
}

0 comments on commit a62c960

Please sign in to comment.