[Pkg-javascript-commits] [sockjs-client] 21/434: Flying 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 b751be2350a1acd1cd351985ead1ef8678e8093a
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Tue Jul 26 14:42:05 2011 +0100

    Flying cursors example.
---
 example-cursors.html | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/example-cursors.html b/example-cursors.html
new file mode 100644
index 0000000..f25d865
--- /dev/null
+++ b/example-cursors.html
@@ -0,0 +1,77 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+  <meta charset="UTF-8" />
+
+  <link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" rel="icon" type="image/x-icon" />
+
+  <script type="text/javascript" src="sockjs.js"></script>
+  <script type="text/javascript" src="static/jquery.min.js"></script>
+
+  <style type="text/css">
+      .cursor {
+        height: 30px;
+        width: 30px;
+        position: absolute;
+        border: 1px solid grey;
+      }
+
+  </style>
+
+</head>
+<body>
+
+  Latency: <code id="latency"></code><br>
+  <code id="logs" style="height:200px; overflow:auto; display: block; border: 1px grey solid;">
+  </code>
+
+<script>
+    // by default just change the port to 9999
+    var sockjs_url = document.location.protocol + '//' + document.location.hostname + ':9999';
+    if (document.location.hostname.indexOf('popcnt') !== -1) {
+        // but if hosted, it's run on port 80, but different domain
+        sockjs_url = "http://sockjs1.popcnt.org";
+    }
+    sockjs_url += '/broadcast';
+
+    function log(a) {
+            if ('console' in window && 'log' in window.console) {
+                console.log(a);
+            }
+            $('#logs').append($("<code>").text(a));
+            $('#logs').append($("<br>"));
+            $('#logs').scrollTop($('#logs').scrollTop()+10000);
+      }
+
+
+    var sjs = new SockJS(sockjs_url);
+    sjs.onopen = function() {
+        log('connected ' + sjs.protocol);
+    };
+    sjs.onclose = function(e) {
+        log('disconnected ' + e);
+    };
+    var myself = (''+Math.random()).substr(2);
+    sjs.onmessage = function(e) {
+        var msg = JSON.parse(e.data);
+        if (msg.id === myself) {
+            var td = (new Date()).getTime() - msg.t;
+            $('#latency').text('' + td + ' ms');
+        }
+        var id = 'cursor_'+msg.id;
+        if ($('#'+id).length === 0) {
+            $("body").append('<div id="' + id + '" class="cursor"></div>');
+        }
+        $('#'+id).offset({top:msg.y-15, left:msg.x-15});
+    };
+    $(document).mousemove(function(e) {
+         var msg = {x:e.pageX, y:e.pageY, t: (new Date()).getTime(), id:myself};
+         var raw_msg = JSON.stringify(msg);
+         if (sjs.readyState === SockJS.OPEN) {
+             sjs.send(raw_msg);
+         }
+    });
+</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