[Pkg-javascript-commits] [sockjs-client] 30/434: Send at most 5 events per second in the cursors example.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:46:59 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository sockjs-client.

commit 337e9ae5e2bfbecc075abc14ac021f09427b7a2a
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Mon Aug 1 11:42:37 2011 +0100

    Send at most 5 events per second in the cursors example.
---
 example-cursors.html | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/example-cursors.html b/example-cursors.html
index ebab80b..1b06a06 100644
--- a/example-cursors.html
+++ b/example-cursors.html
@@ -41,7 +41,7 @@
       }
 
 
-    var sjs = new SockJS(sockjs_url);
+    var sjs = new SockJS(sockjs_url, ['jsonp']);
     sjs.onopen = function() {
         log('connected ' + sjs.protocol);
     };
@@ -61,13 +61,22 @@
         }
         $('#'+id).offset({top:msg.y-15, left:msg.x-15});
     };
+    var x, y;
+    var last_x, last_y;
     $(document).mousemove(function(e) {
-         var msg = {x:e.pageX, y:e.pageY, t: (new Date()).getTime(), id:myself};
+         x = e.pageX; y = e.pageY;
+    });
+    function poll() {
+         if (last_x === x && last_y === y)
+             return;
+         var msg = {x:x, y:y, t: (new Date()).getTime(), id:myself};
+         last_x = x; last_y = y;
          var raw_msg = JSON.stringify(msg);
          if (sjs.readyState === SockJS.OPEN) {
              sjs.send(raw_msg);
          }
-    });
+    };
+    setInterval(poll, 200);
 </script>
 </body>
 </html>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list