mirror-protocol-chrome-and-firefox.patch
authorAndy Green <andy@warmcat.com>
Fri, 12 Nov 2010 14:12:13 +0000 (14:12 +0000)
committerAndy Green <andy@warmcat.com>
Fri, 12 Nov 2010 14:12:13 +0000 (14:12 +0000)
Signed-off-by: Andy Green <andy@warmcat.com>
test-server/test-server.c
test-server/test.html

index d35e826..5806d81 100644 (file)
@@ -37,7 +37,9 @@
  *                             ascii string is sent down it every 50ms.
  *                             If you send "reset\n" on the websocket, then
  *                             the incrementing number is reset to 0.
- * 
+ *
+ *  lws-mirror-protocol: copies any received packet to every connection also
+ *                             using this protocol, including the sender
  */
 
 
@@ -127,7 +129,6 @@ callback_dumb_increment(struct libwebsocket * wsi,
 /* lws-mirror_protocol */
 
 #define MAX_MESSAGE_QUEUE 64
-const int MAX_COMMUNE_MEMBERS = 20;
 
 struct per_session_data__lws_mirror {
        struct libwebsocket * wsi;
@@ -135,7 +136,6 @@ struct per_session_data__lws_mirror {
 };
 
 struct a_message {
-       struct per_session_data * sender;
        void * payload;
        size_t len;
 };
@@ -144,9 +144,6 @@ static struct a_message ringbuffer[MAX_MESSAGE_QUEUE];
 static int ringbuffer_head;
 
 
-struct per_session_data * all_members;
-
-
 static int
 callback_lws_mirror(struct libwebsocket * wsi,
                        enum libwebsocket_callback_reasons reason,
@@ -187,12 +184,13 @@ callback_lws_mirror(struct libwebsocket * wsi,
                break;
 
        case LWS_CALLBACK_RECEIVE:
-//             fprintf(stderr, "Received %d bytes payload\n", (int)len);
+               if (ringbuffer[ringbuffer_head].payload)
+                       free(ringbuffer[ringbuffer_head].payload );
+
                ringbuffer[ringbuffer_head].payload =
                                malloc(LWS_SEND_BUFFER_PRE_PADDING + len +
                                                  LWS_SEND_BUFFER_POST_PADDING);
                ringbuffer[ringbuffer_head].len = len;
-               ringbuffer[ringbuffer_head].sender = pss;
                memcpy(ringbuffer[ringbuffer_head].payload +
                                          LWS_SEND_BUFFER_PRE_PADDING, in, len);
                if (ringbuffer_head == (MAX_MESSAGE_QUEUE - 1))
index e2c9934..58e1941 100644 (file)
@@ -69,17 +69,17 @@ function get_appropriate_ws_url(ads)
 
        try {
                socket_di.onopen = function() {
-                       wsdi_statustd.style.backgroundColor = "#40ff40";
-                       wsdi_status.textContent = " websocket connection opened ";
+                       document.getElementById("wsdi_statustd").style.backgroundColor = "#40ff40";
+                       document.getElementById("wsdi_status").textContent = " websocket connection opened ";
                } 
 
                socket_di.onmessage =function got_packet(msg) {
-                       number.textContent = msg.data + "\n";
+                       document.getElementById("number").textContent = msg.data + "\n";
                } 
 
                socket_di.onclose = function(){
-                       wsdi_statustd.style.backgroundColor = "#ff4040";
-                       wsdi_status.textContent = " websocket connection closed ";
+                       document.getElementById("wsdi_statustd").style.backgroundColor = "#ff4040";
+                       document.getElementById("wsdi_status").textContent = " websocket connection CLOSED ";
                }
        } catch(exception) {
                alert('<p>Error' + exception);  
@@ -94,7 +94,7 @@ function reset() {
 
        var down = 0;
        var no_last = 1;
-       var last_x, last_y;
+       var last_x = 0, last_y = 0;
        var ctx;
        var socket_lm = new WebSocket(get_appropriate_ws_url("127.0.0.1:7681"),
                                   "lws-mirror-protocol");
@@ -102,8 +102,8 @@ function reset() {
 
        try {
                socket_lm.onopen = function() {
-                       wslm_statustd.style.backgroundColor = "#40ff40";
-                       wslm_status.textContent = " websocket connection opened ";
+                       document.getElementById("wslm_statustd").style.backgroundColor = "#40ff40";
+                       document.getElementById("wslm_status").textContent = " websocket connection opened ";
                } 
 
                socket_lm.onmessage =function got_packet(msg) {
@@ -111,15 +111,15 @@ function reset() {
                        if (i[0] == 'd') {
                                ctx.strokeStyle = i[1];
                                ctx.beginPath();
-                               ctx.moveTo(i[2], i[3]);
-                               ctx.lineTo(i[4], i[5]);
+                               ctx.moveTo(+(i[2]), +(i[3]));
+                               ctx.lineTo(+(i[4]), +(i[5]));
                                ctx.stroke();
                        }
                }
 
                socket_lm.onclose = function(){
-                       wslm_statustd.style.backgroundColor = "#ff4040";
-                       wslm_status.textContent = " websocket connection closed ";
+                       document.getElementById("wslm_statustd").style.backgroundColor = "#ff4040";
+                       document.getElementById("wslm_status").textContent = " websocket connection CLOSED ";
                }
        } catch(exception) {
                alert('<p>Error' + exception);  
@@ -136,6 +136,15 @@ function reset() {
        canvas.addEventListener('mousedown', ev_mousedown, false);
        canvas.addEventListener('mouseup', ev_mouseup, false);
 
+       offsetX = offsetY = 0;
+       element = canvas;
+      if (element.offsetParent) {
+        do {
+          offsetX += element.offsetLeft;
+          offsetY += element.offsetTop;
+        } while ((element = element.offsetParent));
+      }
 function update_color() {
        color = document.getElementById("color").value;
 }
@@ -152,8 +161,14 @@ function ev_mouseup(ev) {
 function ev_mousemove (ev) {
        var x, y;
 
-       x = ev.offsetX;
-       y = ev.offsetY;
+       if (ev.offsetX) {
+               x = ev.offsetX;
+               y = ev.offsetY;
+       } else {
+               x = ev.layerX - offsetX;
+               y = ev.layerY - offsetY;
+
+       }
 
        if (!down)
                return;