Skip to content

Commit

Permalink
Don't listen to own messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Caswell committed Jun 3, 2010
1 parent 5660df8 commit 30e86fd
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions examples/multitouch/public/client.js
@@ -1,16 +1,20 @@
var circles; var circles;
var localID = Math.floor(Math.random()*1024*1024);


function longPoll() { function longPoll() {
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.onreadystatechange = function(event) { req.onreadystatechange = function(event) {
if (req.readyState == 4) { if (req.readyState == 4) {
if(req.status == 200){ if(req.status == 200) {
JSON.parse(req.responseText).forEach(function (message) { JSON.parse(req.responseText).forEach(function (message) {
for (var id in message) { if (message.sender === localID) {
circles[id].attr(message[id]); return;
}
for (var id in message.locs) {
circles[id].attr(message.locs[id]);
}; };
}); });
setTimeout(longPoll, 50); longPoll();
} else { } else {
setTimeout(longPoll, 10000); setTimeout(longPoll, 10000);
} }
Expand Down Expand Up @@ -49,11 +53,11 @@ function start() {
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.onreadystatechange = function(event) { req.onreadystatechange = function(event) {
pending = false; pending = false;
setTimeout(send, 50); setTimeout(send, 10);
}; };
req.open('POST', '/stream', true); req.open('POST', '/stream', true);
req.setRequestHeader("Content-Type", "application/json"); req.setRequestHeader("Content-Type", "application/json");
req.send(JSON.stringify(locs)); req.send(JSON.stringify({sender: localID, locs: locs}));
pending = true; pending = true;
locs = {}; locs = {};
} }
Expand All @@ -63,16 +67,7 @@ function start() {
this.animate({r: 120, opacity: 0.9}, 500, ">"); this.animate({r: 120, opacity: 0.9}, 500, ">");
}; };
R.set(r, g, b, p).drag(move, start, up); R.set(r, g, b, p).drag(move, start, up);
setTimeout(longPoll, 500); setTimeout(longPoll, 1000);
}; };


window.onload = start; window.onload = start;
var cache = window.applicationCache;

cache.addEventListener('updateready', function() {
cache.swapCache();
}, false);

setInterval(function () {
cache.update();
}, 10000);

0 comments on commit 30e86fd

Please sign in to comment.